From 772395ae1a3007aafed4980d32fa91db8b98794d Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 2 Jul 2024 19:56:03 +0200 Subject: [PATCH] More refactoring --- src/app/admin/[[...slug]]/page.tsx | 4 +- src/components/auth/authComponents.tsx | 16 ----- src/components/client/admin/PostTable.tsx | 2 +- src/views/admin/PostView.tsx | 61 ------------------- .../CPostView.tsx} | 0 src/views/admin/post/PostView.tsx | 61 +++++++++++++++++++ src/views/admin/post/index.ts | 2 + src/views/admin/project/CProjectView.tsx | 0 src/views/admin/{ => project}/ProjectView.tsx | 6 +- src/views/admin/project/index.ts | 2 + src/views/admin/template/CTemplateView.tsx | 0 src/views/admin/template/TemplateView.tsx | 0 12 files changed, 70 insertions(+), 84 deletions(-) delete mode 100644 src/components/auth/authComponents.tsx delete mode 100644 src/views/admin/PostView.tsx rename src/views/admin/{ClientPostView.tsx => post/CPostView.tsx} (100%) create mode 100644 src/views/admin/post/PostView.tsx create mode 100644 src/views/admin/post/index.ts create mode 100644 src/views/admin/project/CProjectView.tsx rename src/views/admin/{ => project}/ProjectView.tsx (88%) create mode 100644 src/views/admin/project/index.ts create mode 100644 src/views/admin/template/CTemplateView.tsx create mode 100644 src/views/admin/template/TemplateView.tsx diff --git a/src/app/admin/[[...slug]]/page.tsx b/src/app/admin/[[...slug]]/page.tsx index c6feb31..9b8fda5 100644 --- a/src/app/admin/[[...slug]]/page.tsx +++ b/src/app/admin/[[...slug]]/page.tsx @@ -2,8 +2,8 @@ cache: "no-store"; import AuthHandler from "@/components/server/admin/authHandler"; import Sidebar, { SidebarEntry } from "@/components/server/admin/views/sidebar"; -import ProjectView from "@/views/admin/ProjectView"; -import PostView from "@/views/admin/PostView"; +import { ProjectView } from "@/views/admin/project"; +import { PostView } from "@/views/admin/post"; import { redirect } from 'next/navigation' function Home() { diff --git a/src/components/auth/authComponents.tsx b/src/components/auth/authComponents.tsx deleted file mode 100644 index 9996a59..0000000 --- a/src/components/auth/authComponents.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { AuthContext } from "@/providers/providers"; -import { ReactNode, useContext } from "react" - -type Props = { - children:ReactNode; -} - - - -export default function AdminOnlyComponent(p:Props){ - const context = useContext(AuthContext) - return - (
- -
); -} \ No newline at end of file diff --git a/src/components/client/admin/PostTable.tsx b/src/components/client/admin/PostTable.tsx index 72d653b..e1776cc 100644 --- a/src/components/client/admin/PostTable.tsx +++ b/src/components/client/admin/PostTable.tsx @@ -18,7 +18,7 @@ import { GetPostsAttributes, PostServerActions, } from "@/app/lib/actions/entityManagement/post/postActions"; -import { PostViewProps } from "@/views/admin/ClientPostView"; +import { PostViewProps } from "@/views/admin/post"; import { aifa } from "@/util/utils"; import { StateHook } from "@/util/state"; diff --git a/src/views/admin/PostView.tsx b/src/views/admin/PostView.tsx deleted file mode 100644 index 8e7b6e8..0000000 --- a/src/views/admin/PostView.tsx +++ /dev/null @@ -1,61 +0,0 @@ -'use server' -cache: "no-store"; - -import { ReactNode, useEffect } from "react"; -import PostTable from "@/components/client/admin/PostTable"; -import { - deletePost, - getPostsWithBucketsAndProject, - updatePost, - GetPostsAttributes, - PostServerActions, -} from "@/app/lib/actions/entityManagement/post/postActions"; -import { getProjects } from "@/app/lib/actions/entityManagement/post/projectActions"; -import { Bucket, Project, Post, dbSync, Attachment } from "@/models"; -import { handleActionResult } from "../../app/lib/actions/clientActionHandler"; -import { ClientPostView } from "./ClientPostView"; - -type Props = { - children?: ReactNode; -}; - -export default async function PostView(props: Props) { - const sync = await dbSync; - - const headings:string[] = [ - "#", - "Title", - "Content", - "Project", - "CreatedAt", - "UpdatedAt", - ]; - - const actions: PostServerActions = { - deletePost: deletePost, - getPosts: getPostsWithBucketsAndProject, - getProjects: getProjects, - savePost: updatePost, - // uploadAttachment:tryCreateAttachment - }; - - const posts: GetPostsAttributes[]| undefined = handleActionResult( - await getPostsWithBucketsAndProject() - ); - const projects = await Project.findAll().then((projects) => - projects.map((project) => JSON.parse(JSON.stringify(project))) - ); - - return ( -
-
- -
-
- ); -} diff --git a/src/views/admin/ClientPostView.tsx b/src/views/admin/post/CPostView.tsx similarity index 100% rename from src/views/admin/ClientPostView.tsx rename to src/views/admin/post/CPostView.tsx diff --git a/src/views/admin/post/PostView.tsx b/src/views/admin/post/PostView.tsx new file mode 100644 index 0000000..cd68c2d --- /dev/null +++ b/src/views/admin/post/PostView.tsx @@ -0,0 +1,61 @@ +"use server"; +cache: "no-store"; + +import { ReactNode, useEffect } from "react"; +import PostTable from "@/components/client/admin/PostTable"; +import { + deletePost, + getPostsWithBucketsAndProject, + updatePost, + GetPostsAttributes, + PostServerActions, +} from "@/app/lib/actions/entityManagement/post/postActions"; +import { getProjects } from "@/app/lib/actions/entityManagement/post/projectActions"; +import { Bucket, Project, Post, dbSync, Attachment } from "@/models"; +import { handleActionResult } from "@/app/lib/actions/clientActionHandler"; +import { ClientPostView } from "@/views/admin/post"; + +type Props = { + children?: ReactNode; +}; + +export async function PostView(props: Props) { + const sync = await dbSync; + + const headings: string[] = [ + "#", + "Title", + "Content", + "Project", + "CreatedAt", + "UpdatedAt", + ]; + + const actions: PostServerActions = { + deletePost: deletePost, + getPosts: getPostsWithBucketsAndProject, + getProjects: getProjects, + savePost: updatePost, + // uploadAttachment:tryCreateAttachment + }; + + const posts: GetPostsAttributes[] | undefined = handleActionResult( + await getPostsWithBucketsAndProject() + ); + const projects = await Project.findAll().then((projects) => + projects.map((project) => JSON.parse(JSON.stringify(project))) + ); + + return ( +
+
+ +
+
+ ); +} diff --git a/src/views/admin/post/index.ts b/src/views/admin/post/index.ts new file mode 100644 index 0000000..55161e8 --- /dev/null +++ b/src/views/admin/post/index.ts @@ -0,0 +1,2 @@ +export * from './ClientPostView'; +export * from './PostView'; diff --git a/src/views/admin/project/CProjectView.tsx b/src/views/admin/project/CProjectView.tsx new file mode 100644 index 0000000..e69de29 diff --git a/src/views/admin/ProjectView.tsx b/src/views/admin/project/ProjectView.tsx similarity index 88% rename from src/views/admin/ProjectView.tsx rename to src/views/admin/project/ProjectView.tsx index dba648d..d8e8e64 100644 --- a/src/views/admin/ProjectView.tsx +++ b/src/views/admin/project/ProjectView.tsx @@ -1,9 +1,7 @@ cache: "no-store"; -import { tryFetchPosts } from "@/app/api/post/route"; -import { constructAPIUrl } from "@/util/utils"; import { ReactNode, useEffect } from "react"; -import EntityManagementTable from "../../components/client/EntityManagementTable"; +import EntityManagementTable from "../../../components/client/EntityManagementTable"; import PostTable from "@/components/client/admin/PostTable"; import { deletePost, @@ -28,7 +26,7 @@ async function getHeadings() { return headings; } -export default async function ProjectView(props: Props) { +export async function ProjectView(props: Props) { const sync = await dbSync; const actions = { diff --git a/src/views/admin/project/index.ts b/src/views/admin/project/index.ts new file mode 100644 index 0000000..2693056 --- /dev/null +++ b/src/views/admin/project/index.ts @@ -0,0 +1,2 @@ +export * from './CProjectView'; +export * from './ProjectView'; diff --git a/src/views/admin/template/CTemplateView.tsx b/src/views/admin/template/CTemplateView.tsx new file mode 100644 index 0000000..e69de29 diff --git a/src/views/admin/template/TemplateView.tsx b/src/views/admin/template/TemplateView.tsx new file mode 100644 index 0000000..e69de29