refactoring
This commit is contained in:
parent
266ad69c97
commit
2c3ccfee18
@ -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>
|
||||||
|
|||||||
@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
8
src/components/shared/props/ChildrenProps.ts
Normal file
8
src/components/shared/props/ChildrenProps.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
export interface IChildrenProps{
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
export interface IOptionalChildrenProps{
|
||||||
|
children?: ReactNode;
|
||||||
|
}
|
||||||
12
src/components/shared/props/SlugProps.ts
Normal file
12
src/components/shared/props/SlugProps.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
export interface ISlugProps{
|
||||||
|
params: {
|
||||||
|
slug: string
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export interface ISlugArrayProps{
|
||||||
|
params: {
|
||||||
|
slug: string[]
|
||||||
|
};
|
||||||
|
}
|
||||||
2
src/components/shared/props/index.ts
Normal file
2
src/components/shared/props/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from "./ChildrenProps";
|
||||||
|
export * from "./SlugProps";
|
||||||
Loading…
x
Reference in New Issue
Block a user