From d3e52958320ab362555fbfb50bcb93997e34ba0a Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 29 Jan 2023 20:56:59 +0100 Subject: [PATCH] refactor --- .env | 7 - .eslintrc.json | 3 - .gitignore | 40 - .markdown/test.md | 230 - .markdown/test2.md | 9 - .prettierrc | 5 - .vscode/settings.json | 4 - README.md | 34 - .../articles/editor/[articleId]/layout.tsx | 3 - .../articles/editor/[articleId]/page.tsx | 295 - app/admin/articles/page.tsx | 13 - .../categories/editor/[categoryId]/layout.tsx | 3 - .../categories/editor/[categoryId]/page.tsx | 180 - app/admin/categories/page.tsx | 11 - app/admin/images/Gallery.tsx | 26 - app/admin/images/page.tsx | 24 - app/admin/page.tsx | 10 - .../[categoryName]/[articleName]/head.tsx | 13 - .../[categoryName]/[articleName]/layout.tsx | 3 - .../[categoryName]/[articleName]/page.tsx | 63 - app/articles/[categoryName]/page.tsx | 97 - app/articles/page.tsx | 33 - app/head.tsx | 7 - app/layout.tsx | 26 - app/page.tsx | 3 - app/testing/typography/page.tsx | 21 - components/ContentTable.tsx | 22 - components/Footer.tsx | 40 - components/Markdown.tsx | 76 - components/Nav.tsx | 135 - components/Sidebar.tsx | 28 - docker-compose.yml | 34 - docker_data/pgpass | 1 - docker_data/servers.json | 14 - global.ts | 3 - lib/prisma.ts | 14 - manager/fetchManager.ts | 77 - next.config.js | 8 - package-lock.json | 16515 ---------------- package.json | 51 - pages/api/articles/[articleId].ts | 38 - pages/api/articles/index.ts | 141 - pages/api/articles/name/[articleName].ts | 37 - pages/api/categories/[categoryId].ts | 31 - pages/api/categories/index.ts | 129 - pages/api/categories/name/[categoryName].ts | 33 - pages/api/images/index.ts | 11 - pages/api/search.ts | 31 - .../20230107035654_init/migration.sql | 109 - .../20230122141410_contentable/migration.sql | 40 - .../20230122141436_contenttable/migration.sql | 2 - prisma/migrations/migration_lock.toml | 3 - prisma/schema.prisma | 53 - public/favicon.ico | Bin 25931 -> 0 bytes public/images/blur.png | Bin 549 -> 0 bytes public/images/docker.png | Bin 44975 -> 0 bytes public/images/logo.svg | 7 - public/images/test.jpg | Bin 2341241 -> 0 bytes public/next.svg | 1 - public/thirteen.svg | 1 - public/vercel.svg | 1 - styles/buttons.scss | 34 - styles/globals.scss | 28 - styles/inputs.scss | 73 - styles/modules/Article.module.scss | 60 - .../modules/ArticleContentTable.module.scss | 29 - styles/modules/ArticleEditor.module.scss | 94 - styles/modules/Category.module.scss | 55 - styles/modules/CategoryEditor.module.scss | 2 - styles/modules/CategoryList.module.scss | 106 - styles/modules/Footer.module.scss | 72 - styles/modules/Nav.module.scss | 227 - styles/modules/Sidebar.module.scss | 31 - styles/modules/markdown.module.scss | 141 - styles/prism_themes/prism-a11y-dark.css | 161 - styles/prism_themes/prism-atom-dark.css | 143 - .../prism-base16-ateliersulphurpool.light.css | 176 - styles/prism_themes/prism-cb.css | 146 - styles/prism_themes/prism-coldark-cold.css | 317 - styles/prism_themes/prism-coldark-dark.css | 317 - .../prism-coy-without-shadows.css | 140 - styles/prism_themes/prism-darcula.css | 159 - styles/prism_themes/prism-dracula.css | 122 - styles/prism_themes/prism-duotone-dark.css | 172 - styles/prism_themes/prism-duotone-earth.css | 172 - styles/prism_themes/prism-duotone-forest.css | 172 - styles/prism_themes/prism-duotone-light.css | 172 - styles/prism_themes/prism-duotone-sea.css | 172 - styles/prism_themes/prism-duotone-space.css | 172 - styles/prism_themes/prism-ghcolors.css | 122 - styles/prism_themes/prism-gruvbox-dark.css | 143 - styles/prism_themes/prism-gruvbox-light.css | 143 - styles/prism_themes/prism-holi-theme.css | 119 - styles/prism_themes/prism-hopscotch.css | 132 - styles/prism_themes/prism-laserwave.css | 133 - styles/prism_themes/prism-lucario.css | 122 - styles/prism_themes/prism-material-dark.css | 205 - styles/prism_themes/prism-material-light.css | 207 - .../prism_themes/prism-material-oceanic.css | 210 - styles/prism_themes/prism-night-owl.css | 158 - styles/prism_themes/prism-nord.css | 124 - styles/prism_themes/prism-one-dark.css | 440 - styles/prism_themes/prism-one-light.css | 428 - styles/prism_themes/prism-pojoaque.css | 151 - .../prism_themes/prism-shades-of-purple.css | 196 - .../prism-solarized-dark-atom.css | 143 - styles/prism_themes/prism-synthwave84.css | 140 - styles/prism_themes/prism-vs.css | 168 - styles/prism_themes/prism-vsc-dark-plus.css | 275 - styles/prism_themes/prism-xonokai.css | 162 - styles/prism_themes/prism-z-touch.css | 160 - styles/typography.scss | 81 - styles/variables.scss | 38 - styles/variables_colors.scss | 70 - tsconfig.json | 26 - types/api.ts | 40 - types/contentTable.ts | 5 - types/responseErrors.ts | 4 - utils.ts | 16 - validators.ts | 10 - 120 files changed, 26885 deletions(-) delete mode 100644 .env delete mode 100644 .eslintrc.json delete mode 100644 .gitignore delete mode 100644 .markdown/test.md delete mode 100644 .markdown/test2.md delete mode 100644 .prettierrc delete mode 100644 .vscode/settings.json delete mode 100644 README.md delete mode 100644 app/admin/articles/editor/[articleId]/layout.tsx delete mode 100644 app/admin/articles/editor/[articleId]/page.tsx delete mode 100644 app/admin/articles/page.tsx delete mode 100644 app/admin/categories/editor/[categoryId]/layout.tsx delete mode 100644 app/admin/categories/editor/[categoryId]/page.tsx delete mode 100644 app/admin/categories/page.tsx delete mode 100644 app/admin/images/Gallery.tsx delete mode 100644 app/admin/images/page.tsx delete mode 100644 app/admin/page.tsx delete mode 100644 app/articles/[categoryName]/[articleName]/head.tsx delete mode 100644 app/articles/[categoryName]/[articleName]/layout.tsx delete mode 100644 app/articles/[categoryName]/[articleName]/page.tsx delete mode 100644 app/articles/[categoryName]/page.tsx delete mode 100644 app/articles/page.tsx delete mode 100644 app/head.tsx delete mode 100644 app/layout.tsx delete mode 100644 app/page.tsx delete mode 100644 app/testing/typography/page.tsx delete mode 100644 components/ContentTable.tsx delete mode 100644 components/Footer.tsx delete mode 100644 components/Markdown.tsx delete mode 100644 components/Nav.tsx delete mode 100644 components/Sidebar.tsx delete mode 100644 docker-compose.yml delete mode 100644 docker_data/pgpass delete mode 100644 docker_data/servers.json delete mode 100644 global.ts delete mode 100644 lib/prisma.ts delete mode 100644 manager/fetchManager.ts delete mode 100644 next.config.js delete mode 100644 package-lock.json delete mode 100644 package.json delete mode 100644 pages/api/articles/[articleId].ts delete mode 100644 pages/api/articles/index.ts delete mode 100644 pages/api/articles/name/[articleName].ts delete mode 100644 pages/api/categories/[categoryId].ts delete mode 100644 pages/api/categories/index.ts delete mode 100644 pages/api/categories/name/[categoryName].ts delete mode 100644 pages/api/images/index.ts delete mode 100644 pages/api/search.ts delete mode 100644 prisma/migrations/20230107035654_init/migration.sql delete mode 100644 prisma/migrations/20230122141410_contentable/migration.sql delete mode 100644 prisma/migrations/20230122141436_contenttable/migration.sql delete mode 100644 prisma/migrations/migration_lock.toml delete mode 100644 prisma/schema.prisma delete mode 100644 public/favicon.ico delete mode 100644 public/images/blur.png delete mode 100644 public/images/docker.png delete mode 100644 public/images/logo.svg delete mode 100644 public/images/test.jpg delete mode 100644 public/next.svg delete mode 100644 public/thirteen.svg delete mode 100644 public/vercel.svg delete mode 100644 styles/buttons.scss delete mode 100644 styles/globals.scss delete mode 100644 styles/inputs.scss delete mode 100644 styles/modules/Article.module.scss delete mode 100644 styles/modules/ArticleContentTable.module.scss delete mode 100644 styles/modules/ArticleEditor.module.scss delete mode 100644 styles/modules/Category.module.scss delete mode 100644 styles/modules/CategoryEditor.module.scss delete mode 100644 styles/modules/CategoryList.module.scss delete mode 100644 styles/modules/Footer.module.scss delete mode 100644 styles/modules/Nav.module.scss delete mode 100644 styles/modules/Sidebar.module.scss delete mode 100644 styles/modules/markdown.module.scss delete mode 100644 styles/prism_themes/prism-a11y-dark.css delete mode 100644 styles/prism_themes/prism-atom-dark.css delete mode 100644 styles/prism_themes/prism-base16-ateliersulphurpool.light.css delete mode 100644 styles/prism_themes/prism-cb.css delete mode 100644 styles/prism_themes/prism-coldark-cold.css delete mode 100644 styles/prism_themes/prism-coldark-dark.css delete mode 100644 styles/prism_themes/prism-coy-without-shadows.css delete mode 100644 styles/prism_themes/prism-darcula.css delete mode 100644 styles/prism_themes/prism-dracula.css delete mode 100644 styles/prism_themes/prism-duotone-dark.css delete mode 100644 styles/prism_themes/prism-duotone-earth.css delete mode 100644 styles/prism_themes/prism-duotone-forest.css delete mode 100644 styles/prism_themes/prism-duotone-light.css delete mode 100644 styles/prism_themes/prism-duotone-sea.css delete mode 100644 styles/prism_themes/prism-duotone-space.css delete mode 100644 styles/prism_themes/prism-ghcolors.css delete mode 100644 styles/prism_themes/prism-gruvbox-dark.css delete mode 100644 styles/prism_themes/prism-gruvbox-light.css delete mode 100644 styles/prism_themes/prism-holi-theme.css delete mode 100644 styles/prism_themes/prism-hopscotch.css delete mode 100644 styles/prism_themes/prism-laserwave.css delete mode 100644 styles/prism_themes/prism-lucario.css delete mode 100644 styles/prism_themes/prism-material-dark.css delete mode 100644 styles/prism_themes/prism-material-light.css delete mode 100644 styles/prism_themes/prism-material-oceanic.css delete mode 100644 styles/prism_themes/prism-night-owl.css delete mode 100644 styles/prism_themes/prism-nord.css delete mode 100644 styles/prism_themes/prism-one-dark.css delete mode 100644 styles/prism_themes/prism-one-light.css delete mode 100644 styles/prism_themes/prism-pojoaque.css delete mode 100644 styles/prism_themes/prism-shades-of-purple.css delete mode 100644 styles/prism_themes/prism-solarized-dark-atom.css delete mode 100644 styles/prism_themes/prism-synthwave84.css delete mode 100644 styles/prism_themes/prism-vs.css delete mode 100644 styles/prism_themes/prism-vsc-dark-plus.css delete mode 100644 styles/prism_themes/prism-xonokai.css delete mode 100644 styles/prism_themes/prism-z-touch.css delete mode 100644 styles/typography.scss delete mode 100644 styles/variables.scss delete mode 100644 styles/variables_colors.scss delete mode 100644 tsconfig.json delete mode 100644 types/api.ts delete mode 100644 types/contentTable.ts delete mode 100644 types/responseErrors.ts delete mode 100644 utils.ts delete mode 100644 validators.ts diff --git a/.env b/.env deleted file mode 100644 index e83cbb8..0000000 --- a/.env +++ /dev/null @@ -1,7 +0,0 @@ -# Environment variables declared in this file are automatically made available to Prisma. -# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema - -# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. -# See the documentation for all the connection string options: https://pris.ly/d/connection-strings - -DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres?schema=explainegy" \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index bffb357..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "next/core-web-vitals" -} diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bf15673..0000000 --- a/.gitignore +++ /dev/null @@ -1,40 +0,0 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules -/.pnp -.pnp.js - -# testing -/coverage - -# next.js -/.next/ -/out/ - -# production -/build - -# misc -.DS_Store -*.pem - -/docker_data/postgres/ - -# debug -npm-debug.log* -yarn-debug.log* -yarn-error.log* -.pnpm-debug.log* - -# local env files -.env*.local - -# vercel -.vercel - -# typescript -*.tsbuildinfo -next-env.d.ts - -.vscode diff --git a/.markdown/test.md b/.markdown/test.md deleted file mode 100644 index 7bae116..0000000 --- a/.markdown/test.md +++ /dev/null @@ -1,230 +0,0 @@ ---- -__Advertisement :)__ - -- __[pica](https://nodeca.github.io/pica/demo/)__ - high quality and fast image -resize in browser. -- __[babelfish](https://github.com/nodeca/babelfish/)__ - developer friendly -i18n with plurals support and easy syntax. - -You will like those projects! ---- - -## h2 Heading - -### h3 Heading - -#### h4 Heading - -##### h5 Heading - -###### h6 Heading - -## Horizontal Rules - ---- - ---- - ---- - -## Typographic replacements - -Enable typographer option to see result. - -(c) (C) (r) (R) (tm) (TM) (p) (P) +- - -test.. test... test..... test?..... test!.... - -!!!!!! ???? ,, -- --- - -"Smartypants, double quotes" and 'single quotes' - -## Emphasis - -**This is bold text** - -**This is bold text** - -_This is italic text_ - -_This is italic text_ - -~~Strikethrough~~ - -## Blockquotes - -> Blockquotes can also be nested... -> -> > ...by using additional greater-than signs right next to each other... -> > -> > > ...or with spaces between arrows. - -## Lists - -Unordered - -- Create a list by starting a line with `+`, `-`, or `*` -- Sub-lists are made by indenting 2 spaces: - - Marker character change forces new list start: - - Ac tristique libero volutpat at - * Facilisis in pretium nisl aliquet - - Nulla volutpat aliquam velit -- Very easy! - -Ordered - -1. Lorem ipsum dolor sit amet -2. Consectetur adipiscing elit -3. Integer molestie lorem at massa - -4. You can use sequential numbers... -5. ...or keep all the numbers as `1.` - -Start numbering with offset: - -57. foo -1. bar - -## Code - -Inline `code` - -Indented code - - // Some comments - line 1 of code - line 2 of code - line 3 of code - -Block code "fences" - -``` -Sample text here... -``` - -Syntax highlighting - -```js -var foo = function (bar) { - return bar++; -}; - -console.log(foo(5)); -``` - -## Tables - -| Option | Description | -| ------ | ------------------------------------------------------------------------- | -| data | path to data files to supply the data that will be passed into templates. | -| engine | engine to be used for processing templates. Handlebars is the default. | -| ext | extension to be used for dest files. | - -Right aligned columns - -| Option | Description | -| -----: | ------------------------------------------------------------------------: | -| data | path to data files to supply the data that will be passed into templates. | -| engine | engine to be used for processing templates. Handlebars is the default. | -| ext | extension to be used for dest files. | - -## Links - -[link text](http://dev.nodeca.com) - -[link with title](http://nodeca.github.io/pica/demo/ "title text!") - -Autoconverted link https://github.com/nodeca/pica (enable linkify to see) - -## Images - -![Minion](https://octodex.github.com/images/minion.png) -![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat") - -Like links, Images also have a footnote style syntax - -![Alt text][id] - -With a reference later in the document defining the URL location: - -[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat" - -## Plugins - -The killer feature of `markdown-it` is very effective support of -[syntax plugins](https://www.npmjs.org/browse/keyword/markdown-it-plugin). - -### [Emojies](https://github.com/markdown-it/markdown-it-emoji) - -> Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum: -> -> Shortcuts (emoticons): :-) :-( 8-) ;) - -see [how to change output](https://github.com/markdown-it/markdown-it-emoji#change-output) with twemoji. - -### [Subscript](https://github.com/markdown-it/markdown-it-sub) / [Superscript](https://github.com/markdown-it/markdown-it-sup) - -- 19^th^ -- H~2~O - -### [\](https://github.com/markdown-it/markdown-it-ins) - -++Inserted text++ - -### [\](https://github.com/markdown-it/markdown-it-mark) - -==Marked text== - -### [Footnotes](https://github.com/markdown-it/markdown-it-footnote) - -Footnote 1 link[^first]. - -Footnote 2 link[^second]. - -Inline footnote^[Text of inline footnote] definition. - -Duplicated footnote reference[^second]. - -[^first]: Footnote **can have markup** - - and multiple paragraphs. - -[^second]: Footnote text. - -### [Definition lists](https://github.com/markdown-it/markdown-it-deflist) - -Term 1 - -: Definition 1 -with lazy continuation. - -Term 2 with _inline markup_ - -: Definition 2 - - { some code, part of Definition 2 } - - Third paragraph of definition 2. - -_Compact style:_ - -Term 1 -~ Definition 1 - -Term 2 -~ Definition 2a -~ Definition 2b - -### [Abbreviations](https://github.com/markdown-it/markdown-it-abbr) - -This is HTML abbreviation example. - -It converts "HTML", but keep intact partial entries like "xxxHTMLyyy" and so on. - -\*[HTML]: Hyper Text Markup Language - -### [Custom containers](https://github.com/markdown-it/markdown-it-container) - -::: warning -_here be dragons_ -::: diff --git a/.markdown/test2.md b/.markdown/test2.md deleted file mode 100644 index a40cad1..0000000 --- a/.markdown/test2.md +++ /dev/null @@ -1,9 +0,0 @@ -## Code - -```js -var foo = function (bar) { - return bar++; -}; - -console.log(foo(5)); -``` diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 054d599..0000000 --- a/.prettierrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "tabWidth": 2, - "useTabs": false, - "printWidth": 120 -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 1bd4de1..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "typescript.tsdk": "node_modules\\typescript\\lib", - "typescript.enablePromptUseWorkspaceTsdk": true -} diff --git a/README.md b/README.md deleted file mode 100644 index c87e042..0000000 --- a/README.md +++ /dev/null @@ -1,34 +0,0 @@ -This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). - -## Getting Started - -First, run the development server: - -```bash -npm run dev -# or -yarn dev -``` - -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. - -You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file. - -[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`. - -The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. - -## Learn More - -To learn more about Next.js, take a look at the following resources: - -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. - -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! - -## Deploy on Vercel - -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. - -Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. diff --git a/app/admin/articles/editor/[articleId]/layout.tsx b/app/admin/articles/editor/[articleId]/layout.tsx deleted file mode 100644 index 5ffca51..0000000 --- a/app/admin/articles/editor/[articleId]/layout.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default async function AdminArticleEditorLayout({ children }) { - return
{children}
; -} diff --git a/app/admin/articles/editor/[articleId]/page.tsx b/app/admin/articles/editor/[articleId]/page.tsx deleted file mode 100644 index db12810..0000000 --- a/app/admin/articles/editor/[articleId]/page.tsx +++ /dev/null @@ -1,295 +0,0 @@ -"use client"; - -import React from "react"; -import { useState, useRef, useEffect } from "react"; -import styles from "../../../../../styles/modules/ArticleEditor.module.scss"; -import { Prisma } from "@prisma/client"; -import "../../../../../styles/inputs.scss"; -import "../../../../../styles/buttons.scss"; -import Select from "react-select"; -import { useRouter } from "next/navigation"; -import urlJoin from "url-join"; -import { IContentTableEntry } from "../../../../../types/contentTable"; -import { CreateArticle, UpdateArticle } from "../../../../../types/api"; -import { formatTextToUrlName } from "../../../../../utils"; -import { isValidText } from "../../../../../validators"; -import { apiUrl } from "../../../../../global"; -import Markdown from "../../../../../components/Markdown"; - -type ArticleWithCategory = Prisma.ArticleGetPayload<{ include: { category: true } }>; - -export default function AdminArticlesEditorPage({ params }: { params: { articleId: string } }) { - const router = useRouter(); - const [title, setTitle] = useState(""); - const [selectCategoriesOptions, setSelectCategoriesOptions] = useState([]); - const [introduction, setIntroduction] = useState(""); - const [markdown, setMarkdown] = useState(""); - const [contentTable, setContentTable] = useState([]); - - const titleRef = useRef(null); - const categorySelectRef = useRef(null); - const introductionRef = useRef(null); - const markdownTextAreaRef = useRef(null); - - const errorTextRef = useRef(null); - - function changeContentTableEntryAnchor(index: number, newAnchor: string) { - setContentTable((prevArray) => { - let newArray = [...prevArray]; - newArray[index].anchor = newAnchor; - return newArray; - }); - } - - function changeContentTableEntryTitle(index: number, newTitle: string) { - setContentTable((prevArray) => { - let newArray = [...prevArray]; - newArray[index].anchor = newTitle; - return newArray; - }); - } - - function removeEntry(index: number) { - let newArray = [...contentTable]; - newArray.splice(index, 1); - setContentTable(newArray); - } - - function handleFormChange() { - setMarkdown(markdownTextAreaRef.current.value); - setTitle(titleRef.current.value); - setIntroduction(introductionRef.current.value); - } - - // Create or update article - async function handleResponse(res: Response) { - const json = await res.json(); - errorTextRef.current.innerText = json.error ?? ""; - if (json.success) { - const newArticle: ArticleWithCategory = json.data; - router.push(urlJoin(`/articles/`, newArticle.category.name, newArticle.name)); - } - } - - async function updateArticle() { - console.log("Update article"); - const payload: UpdateArticle = { - id: params.articleId, - title: titleRef.current.value, - introduction: introductionRef.current.value, - markdown: markdown, - categoryId: Number(categorySelectRef?.current?.getValue()[0]?.value), - contentTable: contentTable, - }; - console.log(payload); - - await fetch("/api/articles/", { - method: "PUT", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - }, - cache: "no-cache", - body: JSON.stringify(payload), - }) - .then(handleResponse) - .catch(console.error); - } - - async function createArticle() { - console.log("Create article"); - const payload: CreateArticle = { - title: titleRef.current.value, - introduction: introductionRef.current.value, - markdown: markdown, - categoryId: Number(categorySelectRef?.current?.getValue()[0]?.value), - contentTable: contentTable, - }; - console.log(payload); - - await fetch("/api/articles/", { - method: "POST", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - }, - cache: "no-cache", - body: JSON.stringify(payload), - }) - .then(handleResponse) - .catch(console.error); - } - - // App - useEffect(() => { - const fetchExistingArticle = async () => { - const result: Response = await fetch(urlJoin(apiUrl, `articles/${params.articleId}`), { - cache: "no-cache", - next: { revalidate: 60 * 1 }, - }); - - const article = await result.json(); - console.log(article); - if (article.code == "404") { - router.push(urlJoin(`/admin/articles/editor/0`)); - } else { - titleRef.current.value = article.title; - introductionRef.current.value = article.introduction; - markdownTextAreaRef.current.value = article.markdown; - categorySelectRef.current.setValue({ value: article.category.id, label: article.category.title }); - - setTitle(article.title); - setIntroduction(article.introduction); - setMarkdown(article.markdown); - setContentTable(article.contentTable); - } - }; - - const fetchCategoryOptions = async () => { - const result: Response = await fetch(urlJoin(apiUrl, `categories`), { - cache: "no-cache", - next: { revalidate: 60 * 1 }, - }); - - const categories = await result.json(); - let newSelectCategoriesOptions = []; - - categories?.forEach((c) => { - newSelectCategoriesOptions.push({ value: c.id, label: c.title }); - }); - setSelectCategoriesOptions(newSelectCategoriesOptions); - }; - - fetchCategoryOptions().catch((err) => { - console.log(err); - }); - - if (params.articleId != "0") { - fetchExistingArticle().catch((err) => { - console.log(err); - }); - } - }, []); - - return ( -
-

{params.articleId == "0" ? "Create new article" : "Update article"}

-
-

- -
- -
-
-
- - -
- - -
-
-
- - -
-
- -
- - -
-
- -
- -
-
- {contentTable?.map((entry: IContentTableEntry, i: number) => { - return ( -
- { - changeContentTableEntryAnchor(i, e.target.value); - }} - type="text" - placeholder={"Anchor"} - defaultValue={entry.anchor} - /> - { - changeContentTableEntryTitle(i, e.target.value); - }} - type="text" - placeholder={"Title"} - defaultValue={entry.title} - />{" "} - -
- ); - })} - - -
- -
-
-
-
-
- ); -} diff --git a/app/admin/articles/page.tsx b/app/admin/articles/page.tsx deleted file mode 100644 index 18b024d..0000000 --- a/app/admin/articles/page.tsx +++ /dev/null @@ -1,13 +0,0 @@ -"use client"; - -import React from "react"; - -export default function AdminArticlesPage() { - return ( -
-

Page to manage articles

- create new article
-

List of existing articles

-
- ); -} diff --git a/app/admin/categories/editor/[categoryId]/layout.tsx b/app/admin/categories/editor/[categoryId]/layout.tsx deleted file mode 100644 index 5c0796f..0000000 --- a/app/admin/categories/editor/[categoryId]/layout.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default async function AdminCategoriesEditorLayout({ children }) { - return
{children}
; -} diff --git a/app/admin/categories/editor/[categoryId]/page.tsx b/app/admin/categories/editor/[categoryId]/page.tsx deleted file mode 100644 index 9435edb..0000000 --- a/app/admin/categories/editor/[categoryId]/page.tsx +++ /dev/null @@ -1,180 +0,0 @@ -"use client"; -import React, { useRef, useState } from "react"; -import styles from "../../../../../styles/modules/CategoryEditor.module.scss"; -import { Prisma } from "@prisma/client"; -import "../../../../../styles/inputs.scss"; -import "../../../../../styles/buttons.scss"; -import { formatTextToUrlName } from "../../../../../utils"; -import { isValidText } from "../../../../../validators"; -import { CreateCategory, UpdateCategory } from "../../../../../types/api"; -import urlJoin from "url-join"; -import { useRouter } from "next/navigation"; -import { useEffect } from "react"; -import { apiUrl } from "../../../../../global"; - -type CategoryWithSvg = Prisma.CategoryGetPayload<{ include: { svg: true } }>; - -export default function AdminCategoriesEditor({ params }: { params: { categoryId: string } }) { - const router = useRouter(); - const [title, setTitle] = useState(""); - const [color, setColor] = useState(""); - const [svgViewbox, setSvgViewbox] = useState(""); - const [svgPath, setSvgPath] = useState(""); - - const titleRef = useRef(null); - const colorRef = useRef(null); - const svgViewboxRef = useRef(null); - const svgPathRef = useRef(null); - const errorTextRef = useRef(null); - function handleFormChange() { - setTitle(titleRef.current.value); - setColor(colorRef.current.value); - setSvgPath(svgPathRef.current.value); - setSvgViewbox(svgViewboxRef.current.value); - } - - async function handleResponse(res: Response) { - const json = await res.json(); - errorTextRef.current.innerText = json.error ?? ""; - if (json.success) { - router.push(urlJoin(`/articles/`)); - } - } - - async function updateCategory() { - console.log("Update category"); - const payload: UpdateCategory = { - id: params.categoryId, - title: titleRef.current.value, - color: colorRef.current.value, - svg: { - path: svgPathRef.current.value, - viewbox: svgViewboxRef.current.value, - }, - }; - console.log(payload); - - await fetch("/api/categories/", { - method: "PUT", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - }, - cache: "no-cache", - body: JSON.stringify(payload), - }) - .then(handleResponse) - .catch(console.error); - } - - async function createCategory() { - console.log("Create category"); - const payload: CreateCategory = { - title: titleRef.current.value, - color: colorRef.current.value, - svg: { - path: svgPathRef.current.value, - viewbox: svgViewboxRef.current.value, - }, - }; - console.log(payload); - - await fetch("/api/categories/", { - method: "POST", - headers: { - Accept: "application/json", - "Content-Type": "application/json", - }, - cache: "no-cache", - body: JSON.stringify(payload), - }) - .then(handleResponse) - .catch(console.error); - } - - useEffect(() => { - const fetchExistingCategory = async () => { - const result: Response = await fetch(urlJoin(apiUrl, `categories/${params.categoryId}`), { - cache: "no-cache", - }); - - const category = await result.json(); - console.log(category); - if (category.code == "404") { - router.push(urlJoin(`/admin/categories/editor/0`)); - } else { - titleRef.current.value = category.title; - colorRef.current.value = category.color; - svgPathRef.current.value = category.svg.path; - svgPathRef.current.value = category.svg.viewbox; - - setTitle(category.title); - setColor(category.color); - setSvgPath(category.svg.path); - setSvgViewbox(category.svg.viewbox); - } - }; - - if (params.categoryId != "0") { - fetchExistingCategory().catch((err) => { - console.log(err); - }); - } - }, []); - - return ( -
-

{params.categoryId == "0" ? "Create new category" : "Update category"}

-
-

- -
-
-
- -
- - -
-
- -
- - -
-
- -
- - -
-
-
-
- ); -} diff --git a/app/admin/categories/page.tsx b/app/admin/categories/page.tsx deleted file mode 100644 index 3b6f97a..0000000 --- a/app/admin/categories/page.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from "react"; - -export default function AdminCategoriesPage() { - return ( -
-

Page to manage categories

- create new category
-

List of existing category

-
- ); -} diff --git a/app/admin/images/Gallery.tsx b/app/admin/images/Gallery.tsx deleted file mode 100644 index 92c778a..0000000 --- a/app/admin/images/Gallery.tsx +++ /dev/null @@ -1,26 +0,0 @@ -"use client"; -import React, { useState } from "react"; -import { Gallery as ReactGridGallery, Image as ImageType, ThumbnailImageProps } from "react-grid-gallery"; -import Image from "next/image"; -const ImageComponent = (props: ThumbnailImageProps) => { - const { src, alt, style, title } = props.imageProps; - const { width, height } = props.item; - - return ( - {alt} { - window.open(src); - }} - style={style} - /> - ); -}; - -export default function Gallery({ images }: { images: ImageType[] }) { - return ; -} diff --git a/app/admin/images/page.tsx b/app/admin/images/page.tsx deleted file mode 100644 index 73319b5..0000000 --- a/app/admin/images/page.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import React from "react"; -import { Image } from "@prisma/client"; -import { Image as GalleryImage } from "react-grid-gallery"; -import urlJoin from "url-join"; -import { apiUrl } from "../../../global"; -import Gallery from "./Gallery"; - -async function getImages(): Promise { - const result = await fetch(urlJoin(apiUrl, `images`), { - cache: "no-cache", - }); - const imageData: Image[] = await result.json(); - - return imageData.map((img, i) => ({ - width: img.width, - height: img.height, - src: img.url, - caption: img.name, - })); -} - -export default async function AdminImagesPage() { - return ; -} diff --git a/app/admin/page.tsx b/app/admin/page.tsx deleted file mode 100644 index 8400b9b..0000000 --- a/app/admin/page.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import React from "react"; - -export default function AdminPage() { - return ( -
-

AdminPage to manage explainegy

- articles categories
-
- ); -} diff --git a/app/articles/[categoryName]/[articleName]/head.tsx b/app/articles/[categoryName]/[articleName]/head.tsx deleted file mode 100644 index 45950b4..0000000 --- a/app/articles/[categoryName]/[articleName]/head.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { Article } from "@prisma/client"; -import { FetchManager } from "../../../../manager/fetchManager"; - -export default async function ArticleHead({ params }: { params: { articleName: string; categoryName: string } }) { - const articleName: string = params.articleName; - const article: Article = await FetchManager.Article.getByName(articleName); - return ( - <> - {article?.title} - - - ); -} diff --git a/app/articles/[categoryName]/[articleName]/layout.tsx b/app/articles/[categoryName]/[articleName]/layout.tsx deleted file mode 100644 index 547720c..0000000 --- a/app/articles/[categoryName]/[articleName]/layout.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function ArticleLayout({ children }) { - return
{children}
; -} diff --git a/app/articles/[categoryName]/[articleName]/page.tsx b/app/articles/[categoryName]/[articleName]/page.tsx deleted file mode 100644 index 501b56d..0000000 --- a/app/articles/[categoryName]/[articleName]/page.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import ContentTable from "../../../../components/ContentTable"; -import Sidebar from "../../../../components/Sidebar"; -import styles from "../../../../styles/modules/Article.module.scss"; -import Image from "next/image"; -import Markdown from "../../../../components/Markdown"; -import { ArticleWithIncludes, FetchManager } from "../../../../manager/fetchManager"; -import { formatTextToUrlName } from "../../../../utils"; - -//* MAIN -export default async function ArticlePage({ params }: { params: { articleName: string; categoryName: string } }) { - const articleName: string = formatTextToUrlName(params.articleName); - const article: ArticleWithIncludes = await FetchManager.Article.getByName(articleName); - - const dateUpdated: Date = new Date(article.dateUpdated); - const dateCreated: Date = new Date(article.dateCreated); - const dateOptions: Intl.DateTimeFormatOptions = { month: "long", day: "numeric", year: "numeric" }; - const markdown: string = article?.markdown ?? ""; - - return ( -
- -
-
-

- {`Published on ${dateCreated.toLocaleDateString("en-US", dateOptions)}`} -
- {dateUpdated > dateCreated ? `Updated on ${dateUpdated.toLocaleDateString("en-US", dateOptions)}` : ""} -

- -

{article?.title}

- - {article?.image?.alt -

{article?.introduction}

-
- -
- -
- ); -} - -export async function generateStaticParams() { - // Fetchmanager does not work here - const articles: ArticleWithIncludes[] = await FetchManager.Article.list(false); - - return await Promise.all( - articles.map(async (article) => ({ - categoryName: article.category?.name ?? "", - articleName: article.name ?? "", - })) - ); -} diff --git a/app/articles/[categoryName]/page.tsx b/app/articles/[categoryName]/page.tsx deleted file mode 100644 index f1d6b2f..0000000 --- a/app/articles/[categoryName]/page.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import styles from "../../../styles/modules/Category.module.scss"; -import Link from "next/link"; -import { apiUrl } from "../../../global"; -import { Article, Category } from "@prisma/client"; -import urlJoin from "url-join"; - -async function GetAllArticles(categoryName: string): Promise { - const result: Response = await fetch(urlJoin(apiUrl, `articles?categoryName=${categoryName}`), { - cache: "force-cache", - next: { revalidate: 3600 }, - }); - return result.json(); -} - -async function GetPopularArticles(categoryName: string): Promise { - const result: Response = await fetch( - urlJoin(apiUrl, `articles?categoryName=${categoryName}&limit=6&orderBy=popularity`), - { - cache: "force-cache", - next: { revalidate: 3600 }, - } - ); - return result.json(); -} - -async function GetRecentArticles(categoryName: string): Promise { - const result: Response = await fetch( - urlJoin(apiUrl, `articles?categoryName=${categoryName}&limit=6&orderBy=recent`), - { - cache: "force-cache", - next: { revalidate: 3600 }, - } - ); - return result.json(); -} - -async function GetCategory(categoryName: string): Promise { - const result: Response = await fetch(urlJoin(apiUrl, `categories/name/${categoryName}`), { - cache: "force-cache", - next: { revalidate: 3600 }, - }); - return result.json(); -} - -export default async function CategoryPage({ params }: { params: { categoryName: string } }) { - const categoryName = params.categoryName.toLowerCase().replaceAll("%20", " "); - const category: Category = await GetCategory(categoryName); - const allArticles: Article[] = await GetAllArticles(categoryName); - const popularArticles: Article[] = await GetPopularArticles(categoryName); - const recentArticles: Article[] = await GetRecentArticles(categoryName); - - return ( -
-

{category?.title}

-
-
-

Most popular articles

- {popularArticles?.map((a, i) => { - { - return ( - - {a.title} - - ); - } - })} -
- - {/*
-

Most recent articles

- {recentArticles?.map((a, i) => { - { - return ( - - {a.name} - - ); - } - })} -
*/} - -
-

All articles

- {allArticles?.map((a, i) => { - { - return ( - - {a.title} - - ); - } - })} -
-
-
- ); -} diff --git a/app/articles/page.tsx b/app/articles/page.tsx deleted file mode 100644 index 644c9e9..0000000 --- a/app/articles/page.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import styles from "../../styles/modules/CategoryList.module.scss"; -import Link from "next/link"; - -import { FetchManager } from "../../manager/fetchManager"; - -export default async function CategoryList() { - const categories = await FetchManager.Category.list(); - return ( -
-

Overview

-
-
- {categories?.length > 0 - ? categories.map((cat, i) => { - return ( -
- -
- - - -
- {cat.title} - -
- ); - }) - : "We did not find any categories"} -
-
-
- ); -} diff --git a/app/head.tsx b/app/head.tsx deleted file mode 100644 index 34c8670..0000000 --- a/app/head.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export default async function RootHead() { - return ( - <> - - - ); -} diff --git a/app/layout.tsx b/app/layout.tsx deleted file mode 100644 index 1e2e2d5..0000000 --- a/app/layout.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import "../styles/globals.scss"; -import "../styles/variables_colors.scss"; -import "../styles/variables.scss"; -import Link from "next/link"; -import Footer from "../components/Footer"; -import Nav from "../components/Nav"; -import { FetchManager } from "../manager/fetchManager"; - -export default async function RootLayout({ children }: { children: React.ReactNode }) { - return ( - - - - -
- Admin -
-
-
-
{children}
-