Compare commits

..

No commits in common. "dc66da7d001a15a85c22f2856e0072b9f8feae49" and "266ad69c97aa1c975ccbcc7e794638075e23f169" have entirely different histories.

5 changed files with 75 additions and 86 deletions

View File

@ -4,42 +4,59 @@ 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 {
IOptionalChildrenProps, function Home() {
ISlugArrayProps, return <div>home</div>;
} 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: <div>home</div>, "home": <Home key={0}/>,
"man-post": <PostView />, "man-post": <PostManager key={1}/>,
"man-proj": <ProjectView />, "man-proj": <ProjectManager key={2}/>
}; }
interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {} const sidebarEntries: SidebarEntry[] = [
export default async function Page({
params: { slug = ["home"] },
}: AdminPageProps) {
const sidebarEntries: SidebarEntry[] = [
{ label: "Home", view: "home" }, { label: "Home", view: "home" },
{ label: "Post Management", view: "man-post" }, { label: "Post Management", view: "man-post" },
{ label: "Project Management", view: "man-proj" }, { label: "Project Management", view: "man-proj" },
{ label: "Tag Management", view: "man-tags" }, { label: "Tag Management", view: "man-tags" },
{ label: "User Management", view: "man-user" }, { label: "User Management", view: "man-user" },
]; ];
if (sidebarEntries.map((entry) => entry.view).indexOf(slug.toString()) < 0)
redirect("/admin/"); 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) {
if (
(await 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}
params={{ slug: slug.toString() }} slug={slug.toString()}
/> ></Sidebar>
<div className="AdminPanelWrapper flex flex-col p-2"> <div className="AdminPanelWrapper flex flex-col p-2">
{viewMapRecords[slug.toString() || "home"]} {getCurrentView(slug.toString())}
</div> </div>
</AuthHandler> </AuthHandler>
{/* <section>{JSON.stringify(cookies().getAll())}</section> */} {/* <section>{JSON.stringify(cookies().getAll())}</section> */}

View File

@ -1,42 +1,36 @@
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;
}; }
interface Props extends ISlugProps { type Props = {
sidebarEntries: Array<SidebarEntry>; children?:ReactNode;
sidebarEntries:Array<SidebarEntry>;
slug:string
} }
export default async function Sidebar({
sidebarEntries,
params: { slug }, export default async function Sidebar({children, sidebarEntries, slug}:Props){
}: 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 <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`}>
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' : '';
{sidebarEntries.map((sidebarEntry) => { return <li
const activeClass: string =
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> </Link></li>
</li>
);
})} })}
</ul> </ul>
</div> </div>

View File

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

View File

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

View File

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