diff --git a/src/app/admin/[[...slug]]/page.tsx b/src/app/admin/[[...slug]]/page.tsx index 42fc1f4..fb6e3db 100644 --- a/src/app/admin/[[...slug]]/page.tsx +++ b/src/app/admin/[[...slug]]/page.tsx @@ -6,21 +6,12 @@ import { ProjectView } from "@/components/views/admin/project"; import { PostView } from "@/components/views/admin/post"; import { redirect } from 'next/navigation' import { ReactNode } from "react"; - -function Home() { - return
home
; -} -function PostManager() { - return ; -} -function ProjectManager() { - return ; -} +import { IOptionalChildrenProps, ISlugArrayProps } from "@/components/shared/props"; const viewMapRecords: Record = { - "home": , - "man-post": , - "man-proj": + "home":
home
, + "man-post": , + "man-proj": } const sidebarEntries: SidebarEntry[] = [ @@ -36,13 +27,9 @@ function getCurrentView(view: string): ReactNode { return viewJSX; } -type Props = { - params: { - slug: string[]; - }; -}; +interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {} -export default async function Page({ params: { slug = ["home"] } }: Props) { +export default async function Page({ params: { slug = ["home"] } }: AdminPageProps) { if ( (await sidebarEntries) .map((entry) => entry.view) @@ -53,8 +40,8 @@ export default async function Page({ params: { slug = ["home"] } }: Props) { + params={{slug: slug.toString()}} + />
{getCurrentView(slug.toString())}
diff --git a/src/components/server/admin/views/sidebar.tsx b/src/components/server/admin/views/sidebar.tsx index 028505a..72cf738 100644 --- a/src/components/server/admin/views/sidebar.tsx +++ b/src/components/server/admin/views/sidebar.tsx @@ -1,38 +1,44 @@ -import './sidebar.css' -import React, { ReactNode } from 'react'; -import Link from 'next/link'; - +import "./sidebar.css"; +import React, { ReactNode } from "react"; +import Link from "next/link"; +import { IOptionalChildrenProps, ISlugProps } from "@/components/shared/props"; export type SidebarEntry = { - label:string; - view:string; - } + label: string; + view: string; +}; -type Props = { - children?:ReactNode; - sidebarEntries:Array; - slug:string +interface Props extends ISlugProps { + sidebarEntries: Array; } - - -export default async function Sidebar({children, sidebarEntries, slug}:Props){ - - return ( -
-
    - {sidebarEntries.map((sidebarEntry)=>{ - const activeClass:string = (slug == sidebarEntry.view) ? 'active' : ''; - return
  • - - {sidebarEntry.label} -
  • - })} -
-
- ); -} \ No newline at end of file +export default async function Sidebar({ + sidebarEntries, + params: { slug }, +}: Props) { + return ( +
+
    + {sidebarEntries.map((sidebarEntry) => { + const activeClass: string = + slug == sidebarEntry.view ? "active" : ""; + return ( +
  • + + {sidebarEntry.label} + +
  • + ); + })} +
+
+ ); +} diff --git a/src/components/shared/props/ChildrenProps.ts b/src/components/shared/props/ChildrenProps.ts new file mode 100644 index 0000000..c9aaf50 --- /dev/null +++ b/src/components/shared/props/ChildrenProps.ts @@ -0,0 +1,8 @@ +import { ReactNode } from "react"; + +export interface IChildrenProps{ + children: ReactNode; +} +export interface IOptionalChildrenProps{ + children?: ReactNode; +} \ No newline at end of file diff --git a/src/components/shared/props/SlugProps.ts b/src/components/shared/props/SlugProps.ts new file mode 100644 index 0000000..bf7c6de --- /dev/null +++ b/src/components/shared/props/SlugProps.ts @@ -0,0 +1,12 @@ +import { ReactNode } from "react"; + +export interface ISlugProps{ + params: { + slug: string + }; +} +export interface ISlugArrayProps{ + params: { + slug: string[] + }; +} \ No newline at end of file diff --git a/src/components/shared/props/index.ts b/src/components/shared/props/index.ts new file mode 100644 index 0000000..fa3f028 --- /dev/null +++ b/src/components/shared/props/index.ts @@ -0,0 +1,2 @@ +export * from "./ChildrenProps"; +export * from "./SlugProps"; \ No newline at end of file