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 { ProjectView } from "@/components/views/admin/project";
import { PostView } from "@/components/views/admin/post";
import { redirect } from "next/navigation";
import { redirect } from 'next/navigation'
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> = {
home: <div>home</div>,
"man-post": <PostView />,
"man-proj": <ProjectView />,
"home": <Home key={0}/>,
"man-post": <PostManager key={1}/>,
"man-proj": <ProjectManager key={2}/>
}
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[];
};
};
interface AdminPageProps extends ISlugArrayProps, IOptionalChildrenProps {}
export default async function Page({
params: { slug = ["home"] },
}: AdminPageProps) {
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/");
export default async function Page({ params: { slug = ["home"] } }: Props) {
if (
(await sidebarEntries)
.map((entry) => entry.view)
.indexOf(slug.toString()) < 0
) redirect("/admin/")
return (
<main className="h-screen w-screen flex flex-col p-0 bg-gray-300 box-border m-0">
<AuthHandler params={null}>
<Sidebar
sidebarEntries={sidebarEntries}
params={{ slug: slug.toString() }}
/>
slug={slug.toString()}
></Sidebar>
<div className="AdminPanelWrapper flex flex-col p-2">
{viewMapRecords[slug.toString() || "home"]}
{getCurrentView(slug.toString())}
</div>
</AuthHandler>
{/* <section>{JSON.stringify(cookies().getAll())}</section> */}

View File

@ -1,44 +1,38 @@
import "./sidebar.css";
import React, { ReactNode } from "react";
import Link from "next/link";
import { IOptionalChildrenProps, ISlugProps } from "@/components/shared/props";
import './sidebar.css'
import React, { ReactNode } from 'react';
import Link from 'next/link';
export type SidebarEntry = {
label: string;
view: string;
};
label:string;
view:string;
}
interface Props extends ISlugProps {
sidebarEntries: Array<SidebarEntry>;
type Props = {
children?:ReactNode;
sidebarEntries:Array<SidebarEntry>;
slug:string
}
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>
);
}
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>
);
}

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";