lifetracker/apps/web/components/dashboard/sidebar/Sidebar.tsx

114 lines
2.8 KiB
TypeScript

import { redirect } from "next/navigation";
import SidebarItem from "@/components/shared/sidebar/SidebarItem";
import { Separator } from "@/components/ui/separator";
import { api } from "@/server/api/client";
import { getServerAuthSession } from "@/server/auth";
import { Archive, ArrowRightFromLine, Calendar, CheckCheck, Gauge, GaugeCircleIcon, Home, LineChart, PanelLeftOpen, Ruler, Search, SunMoon, Tag } from "lucide-react";
import serverConfig from "@lifetracker/shared/config";
import AllLists from "./AllLists";
import TimezoneDisplay from "./TimezoneDisplay";
import { ActionButtonWithTooltip } from "@/components/ui/action-button";
export default async function Sidebar() {
const session = await getServerAuthSession();
if (!session) {
redirect("/");
}
const searchItem = serverConfig.meilisearch
? [
{
name: "Search",
icon: <Search size={18} />,
path: "/dashboard/search",
},
]
: [];
const menu: {
name: string;
icon: JSX.Element;
path: string;
}[] = [
{
name: "Day View",
icon: <SunMoon size={18} />,
path: "/dashboard/day/today",
},
{
name: "Timeline View",
icon: <Calendar size={18} />,
path: "/dashboard/timeline",
},
{
name: "Analytics",
icon: <GaugeCircleIcon size={18} />,
path: "/dashboard/analytics",
},
...searchItem,
{
name: "Metrics",
icon: <Ruler size={18} />,
path: "/dashboard/metrics",
},
{
name: "Categories",
icon: <Tag size={18} />,
path: "/dashboard/categories",
},
];
const FullView = () => {
return <aside className="flex h-[calc(100vh-64px)] w-60 flex-col gap-5 border-r p-4 ">
<div>
<ul className="space-y-2 text-sm font-medium">
{menu.map((item) => (
<SidebarItem
key={item.name}
logo={item.icon}
name={item.name}
path={item.path}
/>
))}
</ul>
</div>
<Separator />
<div className="mt-auto flex items-center border-t pt-2 text-sm text-gray-400">
<TimezoneDisplay />
</div>
</aside>
}
const CollapsedView = () => {
return (
<div className="flex flex-col">
<ul className="space-y-2 text-sm font-medium">
<SidebarItem
key={0}
logo={<PanelLeftOpen size="18" />}
name={""}
path={""}
/>
<Separator />
{menu.map((item) => (
<SidebarItem
key={item.name}
logo={item.icon}
path={item.path}
name={""}
/>
))}
</ul>
</div>
)
}
return (
<CollapsedView />
);
}