diff --git a/.gitignore b/.gitignore index 6ab2567..37165c5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ /node_modules /.pnp .pnp.js -/copy + # testing /coverage @@ -18,9 +18,7 @@ # misc .DS_Store *.pem - -/docker_data/postgres/ - +#! .env # debug npm-debug.log* yarn-debug.log* @@ -36,5 +34,3 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts - -.vscode diff --git a/.prettierrc b/.prettierrc index 054d599..6a990e9 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { "tabWidth": 2, "useTabs": false, - "printWidth": 120 + "printWidth": 180 } diff --git a/README.md b/README.md index c87e042..965a122 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ First, run the development server: npm run dev # or yarn dev +# or +pnpm dev ``` Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. @@ -18,6 +20,8 @@ You can start editing the page by modifying `pages/index.tsx`. The page auto-upd 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. +This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. + ## Learn More To learn more about Next.js, take a look at the following resources: 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/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 21e0aa6..0000000 --- a/app/admin/categories/editor/[categoryId]/page.tsx +++ /dev/null @@ -1,179 +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 = { - title: titleRef.current.value, - color: colorRef.current.value, - svg: { - path: svgPathRef.current.value, - viewbox: svgViewboxRef.current.value, - }, - }; - console.log(payload); - - await fetch(`/api/categories/${params.categoryId.toString()}`, { - 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/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 7f15275..0000000 --- a/app/articles/[categoryName]/[articleName]/page.tsx +++ /dev/null @@ -1,73 +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; test: 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 ?? ""; - - console.log(params.test); - 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 ?? "", - })) - ); -} - -export function getServerSideProps() { - console.log("-----------------------------------"); - return { test: "weird test" }; -} 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 c5c21dc..0000000 --- a/app/layout.tsx +++ /dev/null @@ -1,27 +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"; -import AdminNav from "../components/AdminNav"; -import AdminControl from "../components/AdminControl"; - -export default async function RootLayout({ children }: { children: React.ReactNode }) { - return ( - - - - -
-
-
{children}
-