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 { redirect } from 'next/navigation'
import { ReactNode } from "react";
function Home() {
return <div>home</div>;
}
function PostManager() {
return <PostView></PostView>;
}
function ProjectManager() {
return <ProjectView></ProjectView>;
}
import { IOptionalChildrenProps, ISlugArrayProps } from "@/components/shared/props";
const viewMapRecords: Record<string, ReactNode> = {
"home": <Home key={0}/>,
"man-post": <PostManager key={1}/>,
"man-proj": <ProjectManager key={2}/>
"home": <div>home</div>,
"man-post": <PostView/>,
"man-proj": <ProjectView/>
}
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) {
<AuthHandler params={null}>
<Sidebar
sidebarEntries={sidebarEntries}
slug={slug.toString()}
></Sidebar>
params={{slug: slug.toString()}}
/>
<div className="AdminPanelWrapper flex flex-col p-2">
{getCurrentView(slug.toString())}
</div>

View File

@ -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<SidebarEntry>;
slug:string
interface Props extends ISlugProps {
sidebarEntries: Array<SidebarEntry>;
}
export default async function Sidebar({children, sidebarEntries, slug}:Props){
return (
<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`}>
{sidebarEntries.map((sidebarEntry)=>{
const activeClass:string = (slug == sidebarEntry.view) ? 'active' : '';
return <li
key={sidebarEntry.view}
className='nav-item w-[100%]'>
<Link
href={`/admin/${sidebarEntry.view}`}
className={`${activeClass} nav-link m-2 whitespace-nowrap outline outline-1`}>
{sidebarEntry.label}
</Link></li>
})}
</ul>
</div>
);
}
export default async function Sidebar({
sidebarEntries,
params: { slug },
}: Props) {
return (
<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`}
>
{sidebarEntries.map((sidebarEntry) => {
const activeClass: string =
slug == sidebarEntry.view ? "active" : "";
return (
<li
key={sidebarEntry.view}
className="nav-item w-[100%]"
>
<Link
href={`/admin/${sidebarEntry.view}`}
className={`${activeClass} nav-link m-2 whitespace-nowrap outline outline-1`}
>
{sidebarEntry.label}
</Link>
</li>
);
})}
</ul>
</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";