refactoring

This commit is contained in:
Andreas 2024-07-07 00:23:32 +02:00
parent 266ad69c97
commit 2c3ccfee18
5 changed files with 69 additions and 54 deletions

View File

@ -6,21 +6,12 @@ import { ProjectView } from "@/components/views/admin/project";
import { PostView } from "@/components/views/admin/post"; import { PostView } from "@/components/views/admin/post";
import { redirect } from 'next/navigation' import { redirect } from 'next/navigation'
import { ReactNode } from "react"; import { ReactNode } from "react";
import { IOptionalChildrenProps, ISlugArrayProps } from "@/components/shared/props";
function Home() {
return <div>home</div>;
}
function PostManager() {
return <PostView></PostView>;
}
function ProjectManager() {
return <ProjectView></ProjectView>;
}
const viewMapRecords: Record<string, ReactNode> = { const viewMapRecords: Record<string, ReactNode> = {
"home": <Home key={0}/>, "home": <div>home</div>,
"man-post": <PostManager key={1}/>, "man-post": <PostView/>,
"man-proj": <ProjectManager key={2}/> "man-proj": <ProjectView/>
} }
const sidebarEntries: SidebarEntry[] = [ const sidebarEntries: SidebarEntry[] = [
@ -36,13 +27,9 @@ function getCurrentView(view: string): ReactNode {
return viewJSX; return viewJSX;
} }
type Props = { interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {}
params: {
slug: string[];
};
};
export default async function Page({ params: { slug = ["home"] } }: Props) { export default async function Page({ params: { slug = ["home"] } }: AdminPageProps) {
if ( if (
(await sidebarEntries) (await sidebarEntries)
.map((entry) => entry.view) .map((entry) => entry.view)
@ -53,8 +40,8 @@ export default async function Page({ params: { slug = ["home"] } }: Props) {
<AuthHandler params={null}> <AuthHandler params={null}>
<Sidebar <Sidebar
sidebarEntries={sidebarEntries} sidebarEntries={sidebarEntries}
slug={slug.toString()} params={{slug: slug.toString()}}
></Sidebar> />
<div className="AdminPanelWrapper flex flex-col p-2"> <div className="AdminPanelWrapper flex flex-col p-2">
{getCurrentView(slug.toString())} {getCurrentView(slug.toString())}
</div> </div>

View File

@ -1,36 +1,42 @@
import './sidebar.css' import "./sidebar.css";
import React, { ReactNode } from 'react'; import React, { ReactNode } from "react";
import Link from 'next/link'; import Link from "next/link";
import { IOptionalChildrenProps, ISlugProps } from "@/components/shared/props";
export type SidebarEntry = { export type SidebarEntry = {
label: string; label: string;
view: string; view: string;
} };
type Props = { interface Props extends ISlugProps {
children?:ReactNode;
sidebarEntries: Array<SidebarEntry>; sidebarEntries: Array<SidebarEntry>;
slug:string
} }
export default async function Sidebar({
sidebarEntries,
export default async function Sidebar({children, sidebarEntries, slug}:Props){ params: { slug },
}: Props) {
return ( return (
<div className='w-fit h[100%] drop-shadow-2xl shadow-xl'> <div className="w-fit h[100%] drop-shadow-2xl shadow-xl">
<ul className={`navbar-light bg-light nav nav-pills flex-column mb-auto container-fluid h-[100%] items-start justify-start p-0 w-fit`}> <ul
className={`navbar-light bg-light nav nav-pills flex-column mb-auto container-fluid h-[100%] items-start justify-start p-0 w-fit`}
>
{sidebarEntries.map((sidebarEntry) => { {sidebarEntries.map((sidebarEntry) => {
const activeClass:string = (slug == sidebarEntry.view) ? 'active' : ''; const activeClass: string =
return <li slug == sidebarEntry.view ? "active" : "";
return (
<li
key={sidebarEntry.view} key={sidebarEntry.view}
className='nav-item w-[100%]'> className="nav-item w-[100%]"
>
<Link <Link
href={`/admin/${sidebarEntry.view}`} href={`/admin/${sidebarEntry.view}`}
className={`${activeClass} nav-link m-2 whitespace-nowrap outline outline-1`}> className={`${activeClass} nav-link m-2 whitespace-nowrap outline outline-1`}
>
{sidebarEntry.label} {sidebarEntry.label}
</Link></li> </Link>
</li>
);
})} })}
</ul> </ul>
</div> </div>

View File

@ -0,0 +1,8 @@
import { ReactNode } from "react";
export interface IChildrenProps{
children: ReactNode;
}
export interface IOptionalChildrenProps{
children?: ReactNode;
}

View File

@ -0,0 +1,12 @@
import { ReactNode } from "react";
export interface ISlugProps{
params: {
slug: string
};
}
export interface ISlugArrayProps{
params: {
slug: string[]
};
}

View File

@ -0,0 +1,2 @@
export * from "./ChildrenProps";
export * from "./SlugProps";