Compare commits

...

2 Commits

Author SHA1 Message Date
dc66da7d00 refactor of the admin panel page 2024-07-07 00:31:04 +02:00
2c3ccfee18 refactoring 2024-07-07 00:23:32 +02:00
5 changed files with 86 additions and 75 deletions

View File

@ -4,59 +4,42 @@ import AuthHandler from "@/components/server/admin/authHandler";
import Sidebar, { SidebarEntry } from "@/components/server/admin/views/sidebar"; import Sidebar, { SidebarEntry } from "@/components/server/admin/views/sidebar";
import { ProjectView } from "@/components/views/admin/project"; 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 {
function Home() { IOptionalChildrenProps,
return <div>home</div>; ISlugArrayProps,
} } from "@/components/shared/props";
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[] = [
{ 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" },
];
function getCurrentView(view: string): ReactNode {
const viewJSX = viewMapRecords[view || "home"];
return viewJSX;
}
type Props = {
params: {
slug: string[];
};
}; };
export default async function Page({ params: { slug = ["home"] } }: Props) { interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {}
if (
(await sidebarEntries) export default async function Page({
.map((entry) => entry.view) params: { slug = ["home"] },
.indexOf(slug.toString()) < 0 }: AdminPageProps) {
) redirect("/admin/") const sidebarEntries: SidebarEntry[] = [
{ 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" },
];
if (sidebarEntries.map((entry) => entry.view).indexOf(slug.toString()) < 0)
redirect("/admin/");
return ( return (
<main className="h-screen w-screen flex flex-col p-0 bg-gray-300 box-border m-0"> <main className="h-screen w-screen flex flex-col p-0 bg-gray-300 box-border m-0">
<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())} {viewMapRecords[slug.toString() || "home"]}
</div> </div>
</AuthHandler> </AuthHandler>
{/* <section>{JSON.stringify(cookies().getAll())}</section> */} {/* <section>{JSON.stringify(cookies().getAll())}</section> */}

View File

@ -1,38 +1,44 @@
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
{sidebarEntries.map((sidebarEntry)=>{ className={`navbar-light bg-light nav nav-pills flex-column mb-auto container-fluid h-[100%] items-start justify-start p-0 w-fit`}
const activeClass:string = (slug == sidebarEntry.view) ? 'active' : ''; >
return <li {sidebarEntries.map((sidebarEntry) => {
key={sidebarEntry.view} const activeClass: string =
className='nav-item w-[100%]'> slug == sidebarEntry.view ? "active" : "";
<Link return (
href={`/admin/${sidebarEntry.view}`} <li
className={`${activeClass} nav-link m-2 whitespace-nowrap outline outline-1`}> key={sidebarEntry.view}
{sidebarEntry.label} className="nav-item w-[100%]"
</Link></li> >
})} <Link
</ul> href={`/admin/${sidebarEntry.view}`}
</div> 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";