mirror of
https://github.com/DerTyp7/explainegy-nextjs.git
synced 2025-10-29 21:02:13 +01:00
asd
This commit is contained in:
@@ -74,7 +74,6 @@ export default function AdminArticlesEditorPage({ params }: { params: { articleI
|
|||||||
async function updateArticle() {
|
async function updateArticle() {
|
||||||
console.log("Update article");
|
console.log("Update article");
|
||||||
const payload: UpdateArticle = {
|
const payload: UpdateArticle = {
|
||||||
id: params.articleId,
|
|
||||||
title: titleRef.current.value,
|
title: titleRef.current.value,
|
||||||
introduction: introductionRef.current.value,
|
introduction: introductionRef.current.value,
|
||||||
markdown: markdown,
|
markdown: markdown,
|
||||||
@@ -83,7 +82,7 @@ export default function AdminArticlesEditorPage({ params }: { params: { articleI
|
|||||||
};
|
};
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
await fetch("/api/articles/", {
|
await fetch(`/api/articles/${params.articleId.toString()}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ export default function AdminCategoriesEditor({ params }: { params: { categoryId
|
|||||||
async function updateCategory() {
|
async function updateCategory() {
|
||||||
console.log("Update category");
|
console.log("Update category");
|
||||||
const payload: UpdateCategory = {
|
const payload: UpdateCategory = {
|
||||||
id: params.categoryId,
|
|
||||||
title: titleRef.current.value,
|
title: titleRef.current.value,
|
||||||
color: colorRef.current.value,
|
color: colorRef.current.value,
|
||||||
svg: {
|
svg: {
|
||||||
@@ -54,7 +53,7 @@ export default function AdminCategoriesEditor({ params }: { params: { categoryId
|
|||||||
};
|
};
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
|
|
||||||
await fetch("/api/categories/", {
|
await fetch(`/api/categories/${params.categoryId.toString()}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import Link from "next/link";
|
|||||||
import Footer from "../components/Footer";
|
import Footer from "../components/Footer";
|
||||||
import Nav from "../components/Nav";
|
import Nav from "../components/Nav";
|
||||||
import { FetchManager } from "../manager/fetchManager";
|
import { FetchManager } from "../manager/fetchManager";
|
||||||
|
import AdminNav from "../components/AdminNav";
|
||||||
|
import AdminControl from "../components/AdminControl";
|
||||||
|
|
||||||
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
@@ -12,11 +14,10 @@ export default async function RootLayout({ children }: { children: React.ReactNo
|
|||||||
<head></head>
|
<head></head>
|
||||||
|
|
||||||
<body className="body">
|
<body className="body">
|
||||||
<div>
|
|
||||||
<Link href={"/admin"}> Admin</Link>
|
|
||||||
</div>
|
|
||||||
<header>
|
<header>
|
||||||
<Nav categories={await FetchManager.Category.list()} />
|
<Nav categories={await FetchManager.Category.list()} />
|
||||||
|
<AdminNav />
|
||||||
|
<AdminControl />
|
||||||
</header>
|
</header>
|
||||||
<main>{children}</main>
|
<main>{children}</main>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
|||||||
11
components/AdminControl.tsx
Normal file
11
components/AdminControl.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import React from "react";
|
||||||
|
import styles from "../styles/modules/AdminControl.module.scss";
|
||||||
|
|
||||||
|
export default function AdminControl() {
|
||||||
|
return (
|
||||||
|
<div className={styles.adminControl}>
|
||||||
|
<button className="danger">Delete this article</button>
|
||||||
|
<button className="warning">Edit this article</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
15
components/AdminNav.tsx
Normal file
15
components/AdminNav.tsx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import React from "react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import styles from "../styles/modules/AdminNav.module.scss";
|
||||||
|
|
||||||
|
function AdminNav() {
|
||||||
|
return (
|
||||||
|
<div className={styles.adminNav}>
|
||||||
|
<Link href={"/admin"}>Admin</Link>
|
||||||
|
<Link href={"/admin/articles/editor/0"}>New article</Link>
|
||||||
|
<Link href={"/admin/categories/editor/0"}>New category</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdminNav;
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -9,7 +9,7 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@next/font": "13.0.7",
|
"@next/font": "13.0.7",
|
||||||
"@prisma/client": "^4.8.0",
|
"@prisma/client": "^4.9.0",
|
||||||
"@types/express": "^4.17.15",
|
"@types/express": "^4.17.15",
|
||||||
"@types/marked": "^4.0.8",
|
"@types/marked": "^4.0.8",
|
||||||
"@types/react": "18.0.26",
|
"@types/react": "18.0.26",
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
"@fec/remark-a11y-emoji": "^3.1.0",
|
"@fec/remark-a11y-emoji": "^3.1.0",
|
||||||
"@types/node": "^18.11.17",
|
"@types/node": "^18.11.17",
|
||||||
"@types/prismjs": "^1.26.0",
|
"@types/prismjs": "^1.26.0",
|
||||||
"prisma": "^4.8.0"
|
"prisma": "^4.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@ampproject/remapping": {
|
"node_modules/@ampproject/remapping": {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@next/font": "13.0.7",
|
"@next/font": "13.0.7",
|
||||||
"@prisma/client": "^4.8.0",
|
"@prisma/client": "^4.9.0",
|
||||||
"@types/express": "^4.17.15",
|
"@types/express": "^4.17.15",
|
||||||
"@types/marked": "^4.0.8",
|
"@types/marked": "^4.0.8",
|
||||||
"@types/react": "18.0.26",
|
"@types/react": "18.0.26",
|
||||||
@@ -46,6 +46,6 @@
|
|||||||
"@fec/remark-a11y-emoji": "^3.1.0",
|
"@fec/remark-a11y-emoji": "^3.1.0",
|
||||||
"@types/node": "^18.11.17",
|
"@types/node": "^18.11.17",
|
||||||
"@types/prismjs": "^1.26.0",
|
"@types/prismjs": "^1.26.0",
|
||||||
"prisma": "^4.8.0"
|
"prisma": "^4.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
res.status(500).json(error);
|
res.status(500).json(error);
|
||||||
});
|
});
|
||||||
} else if (req.method == "PUT") {//* PUT
|
} else if (req.method == "PUT") {//* PUT
|
||||||
|
console.log("PUT")
|
||||||
const data: UpdateArticle = req.body;
|
const data: UpdateArticle = req.body;
|
||||||
|
|
||||||
if (!isValidText(data.title)) {
|
if (!isValidText(data.title)) {
|
||||||
@@ -53,22 +54,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newArticle: Prisma.ArticleUncheckedUpdateInput = {
|
const newArticle: Prisma.ArticleUncheckedUpdateInput = {
|
||||||
title: data.title,
|
title: data.title ?? undefined,
|
||||||
name: formatTextToUrlName(data.title),
|
name: formatTextToUrlName(data.title) ?? undefined,
|
||||||
introduction: data.introduction,
|
introduction: data.introduction ?? undefined,
|
||||||
|
|
||||||
categoryId: data.categoryId.toString(),
|
categoryId: data.categoryId?.toString() ?? undefined,
|
||||||
contentTable: data.contentTable,
|
contentTable: data.contentTable ?? undefined,
|
||||||
markdown: data.markdown,
|
markdown: data.markdown ?? undefined,
|
||||||
imageId: data.imageId.toString(),
|
imageId: data.imageId?.toString() ?? undefined,
|
||||||
}
|
}
|
||||||
|
console.log(newArticle)
|
||||||
await prisma.article.update({ data: newArticle, where: { id: articleId }, include: { category: true } })
|
await prisma.article.update({ data: newArticle, where: { id: articleId }, include: { category: true } })
|
||||||
.then(
|
.then(
|
||||||
(data) => {
|
(data) => {
|
||||||
res.json({ success: true, data: data });
|
res.json({ success: true, data: data });
|
||||||
},
|
},
|
||||||
(errorReason) => {
|
(errorReason) => {
|
||||||
|
console.log(errorReason)
|
||||||
if (errorReason.code === "P2002") {
|
if (errorReason.code === "P2002") {
|
||||||
res.json({ target: errorReason.meta.target[0], error: "Already exists" });
|
res.json({ target: errorReason.meta.target[0], error: "Already exists" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.name = formatTextToUrlName(data.title);
|
data.name = formatTextToUrlName(data.title);
|
||||||
|
data.categoryId = data.categoryId.toString();
|
||||||
|
|
||||||
prisma.article
|
prisma.article
|
||||||
.create({ data: data, include: { category: true } })
|
.create({ data: data, include: { category: true } })
|
||||||
.then(
|
.then(
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
code: "404",
|
code: "404",
|
||||||
message: "No article with this name found!",
|
message: "No article with this name found!",
|
||||||
};
|
};
|
||||||
res.status(404).send(JSON.stringify(error));
|
res.status(404).json(error);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -31,6 +31,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
code: "500",
|
code: "500",
|
||||||
message: err,
|
message: err,
|
||||||
};
|
};
|
||||||
res.status(500).send(JSON.stringify(error));
|
res.status(500).json(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ button {
|
|||||||
border-color: var(--color-accent);
|
border-color: var(--color-accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.error {
|
&.danger {
|
||||||
border-color: var(--color-error);
|
border-color: var(--color-danger);
|
||||||
}
|
}
|
||||||
&.success {
|
&.success {
|
||||||
border-color: var(--color-success);
|
border-color: var(--color-success);
|
||||||
|
|||||||
12
styles/modules/AdminControl.module.scss
Normal file
12
styles/modules/AdminControl.module.scss
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
@import "../variables.scss";
|
||||||
|
|
||||||
|
.adminControl {
|
||||||
|
border-bottom: 2px solid var(--color-danger);
|
||||||
|
padding: 10px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
column-gap: 50px;
|
||||||
|
margin-top: -10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
12
styles/modules/AdminNav.module.scss
Normal file
12
styles/modules/AdminNav.module.scss
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
@import "../variables.scss";
|
||||||
|
|
||||||
|
.adminNav {
|
||||||
|
border-top: 2px solid var(--color-danger);
|
||||||
|
padding: 10px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
column-gap: 50px;
|
||||||
|
margin-top: -10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
--color-font-muted: #929292;
|
--color-font-muted: #929292;
|
||||||
--color-shadow-nav: #00000033;
|
--color-shadow-nav: #00000033;
|
||||||
|
|
||||||
--color-error: #cf000f;
|
--color-danger: #cf000f;
|
||||||
--color-success: #009944;
|
--color-success: #009944;
|
||||||
--color-info: #63c0df;
|
--color-info: #63c0df;
|
||||||
--color-warning: #f0541e;
|
--color-warning: #f0541e;
|
||||||
|
|||||||
Reference in New Issue
Block a user