From 395234f9193fcba89e9531f8580729bdba1dbb9f Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 25 Jun 2024 08:18:54 +0200 Subject: [PATCH] refactoring --- src/app/admin/[[...slug]]/page.tsx | 54 +++++++++++++++--------------- src/components/client/TableGen.tsx | 12 +++++-- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/app/admin/[[...slug]]/page.tsx b/src/app/admin/[[...slug]]/page.tsx index 092a2dd..6fc3735 100644 --- a/src/app/admin/[[...slug]]/page.tsx +++ b/src/app/admin/[[...slug]]/page.tsx @@ -15,58 +15,58 @@ type Props = { -function Home(){ +function Home() { return
home
} -function PostManager(){ +function PostManager() { return
posts
} -function ProjectManager(){ +function ProjectManager() { return
projects
} -async function getViewMap():Promise>{ +async function getViewMap(): Promise> { return new Map([ - ['home', ], - ['man-post', ], - ['man-proj', ] -]); + ['home', ], + ['man-post', ], + ['man-proj', ] + ]); } -async function getSidebarEntries():Promise>{ +async function getSidebarEntries(): Promise> { return [ - { label: 'Home', view: 'home'}, - { label: 'Post Management', view: 'man-post'}, - { label: 'Project Management', view: 'man-proj'}, - { label: 'Tag Management', view: 'man-tags'}, - { label: 'User Management', view: 'man-user'}, + { label: 'Home', view: 'home' }, + { label: 'Post Management', view: 'man-post' }, + { label: 'Project Management', view: 'man-proj' }, + { label: 'Tag Management', view: 'man-tags' }, + { label: 'User Management', view: 'man-user' }, ] } -async function getCurrentView(view:string):Promise{ +async function getCurrentView(view: string): Promise { const viewMap = await getViewMap(); const viewJSX = viewMap.get(view); return viewJSX ? viewJSX : ; } -export default async function Page(props:Props){ - const sidebarEntries:Array = await getSidebarEntries(); +export default async function Page(props: Props) { + const sidebarEntries: Array = await getSidebarEntries(); - const slug:string|string[] = props.params.slug ? props.params.slug : 'home'; + const slug: string | string[] = props.params.slug ? props.params.slug : 'home'; return ( -
- - -
- {await getCurrentView(slug.toString())} -
-
- {/*
{JSON.stringify(cookies().getAll())}
*/} -
+
+ + +
+ {await getCurrentView(slug.toString())} +
+
+ {/*
{JSON.stringify(cookies().getAll())}
*/} +
); } \ No newline at end of file diff --git a/src/components/client/TableGen.tsx b/src/components/client/TableGen.tsx index ce5d200..93dfb24 100644 --- a/src/components/client/TableGen.tsx +++ b/src/components/client/TableGen.tsx @@ -1,18 +1,26 @@ 'use client' import { ReactNode } from "react"; +type TableGenOptions = { + editButton:boolean; + deleteButton:boolean; +} + type Props = { headings:Array; children:ReactNode; + options?:TableGenOptions } export default function TableGen(props:Props){ + const options = props.options ? props.options : {editButton: true, deleteButton: true} + console.log(props.headings) return <> - {[...props.headings,'Edit', 'Delete'].map((h)=> - + {[...props.headings,options.editButton ? 'Edit' : null, options.deleteButton ? 'Delete' : null].map((h)=> + h ? : '' )}
{h}{h}