Perplexica/ui/components/Sidebar.tsx

101 lines
3.3 KiB
TypeScript
Raw Normal View History

2024-07-05 14:36:50 +08:00
"use client";
2024-04-09 16:21:05 +05:30
2024-07-05 14:36:50 +08:00
import { cn } from "@/lib/utils";
2024-07-09 10:24:27 +08:00
import { BookOpenText, Home, Search, SquarePen, Settings, Newspaper } from "lucide-react";
2024-07-05 14:36:50 +08:00
import Link from "next/link";
import { useSelectedLayoutSegments } from "next/navigation";
import React, { useState, type ReactNode } from "react";
import Layout from "./Layout";
import SettingsDialog from "./SettingsDialog";
2024-05-24 20:29:49 +08:00
2024-05-30 21:38:37 +05:30
const VerticalIconContainer = ({ children }: { children: ReactNode }) => {
2024-07-05 14:36:50 +08:00
return <div className="flex flex-col items-center gap-y-3 w-full">{children}</div>;
2024-05-30 21:38:37 +05:30
};
2024-04-09 16:21:05 +05:30
const Sidebar = ({ children }: { children: React.ReactNode }) => {
const segments = useSelectedLayoutSegments();
2024-04-23 16:52:41 +05:30
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
2024-04-09 16:21:05 +05:30
const navLinks = [
{
icon: Home,
2024-07-05 14:36:50 +08:00
href: "/",
active: segments.length === 0 || segments.includes("c"),
label: "Home",
2024-04-09 16:21:05 +05:30
},
{
icon: Search,
2024-07-05 14:36:50 +08:00
href: "/discover",
active: segments.includes("discover"),
label: "Discover",
2024-04-09 16:21:05 +05:30
},
{
icon: BookOpenText,
2024-07-05 14:36:50 +08:00
href: "/library",
active: segments.includes("library"),
label: "Library",
2024-04-09 16:21:05 +05:30
},
2024-07-08 16:20:56 +08:00
{
2024-07-09 10:24:27 +08:00
icon: Newspaper,
2024-07-08 16:20:56 +08:00
href: "/news",
active: segments.includes("news"),
label: "News",
},
2024-04-09 16:21:05 +05:30
];
return (
<div>
<div className="hidden lg:fixed lg:inset-y-0 lg:z-50 lg:flex lg:w-20 lg:flex-col">
2024-05-27 11:49:09 +08:00
<div className="flex grow flex-col items-center justify-between gap-y-5 overflow-y-auto bg-light-secondary dark:bg-dark-secondary px-2 py-8">
2024-04-09 16:21:05 +05:30
<a href="/">
2024-05-24 20:29:49 +08:00
<SquarePen className="cursor-pointer" />
2024-04-09 16:21:05 +05:30
</a>
2024-05-24 20:29:49 +08:00
<VerticalIconContainer>
{navLinks.map((link, index) => (
2024-04-09 16:21:05 +05:30
<Link
key={index}
2024-04-09 16:21:05 +05:30
href={link.href}
className={cn(
2024-07-05 14:36:50 +08:00
"relative flex flex-row items-center justify-center cursor-pointer hover:bg-black/10 dark:hover:bg-white/10 duration-150 transition w-full py-2 rounded-lg",
link.active ? "text-black dark:text-white" : "text-black/70 dark:text-white/70",
2024-04-09 16:21:05 +05:30
)}
>
<link.icon />
{link.active && (
2024-05-24 20:29:49 +08:00
<div className="absolute right-0 -mr-2 h-full w-1 rounded-l-lg bg-black dark:bg-white" />
2024-04-09 16:21:05 +05:30
)}
</Link>
))}
2024-05-24 20:29:49 +08:00
</VerticalIconContainer>
2024-07-05 14:36:50 +08:00
<Settings onClick={() => setIsSettingsOpen(!isSettingsOpen)} className="cursor-pointer" />
2024-05-24 20:29:49 +08:00
2024-07-05 14:36:50 +08:00
<SettingsDialog isOpen={isSettingsOpen} setIsOpen={setIsSettingsOpen} />
2024-04-09 16:21:05 +05:30
</div>
</div>
2024-05-27 11:49:09 +08:00
<div className="fixed bottom-0 w-full z-50 flex flex-row items-center gap-x-6 bg-light-primary dark:bg-dark-primary px-4 py-4 shadow-sm lg:hidden">
{navLinks.map((link, index) => (
2024-04-09 16:21:05 +05:30
<Link
href={link.href}
key={index}
2024-04-09 16:21:05 +05:30
className={cn(
2024-07-05 14:36:50 +08:00
"relative flex flex-col items-center space-y-1 text-center w-full",
link.active ? "text-black dark:text-white" : "text-black dark:text-white/70",
2024-04-09 16:21:05 +05:30
)}
>
2024-07-05 14:36:50 +08:00
{link.active && <div className="absolute top-0 -mt-4 h-1 w-full rounded-b-lg bg-black dark:bg-white" />}
2024-04-09 16:21:05 +05:30
<link.icon />
<p className="text-xs">{link.label}</p>
</Link>
))}
</div>
<Layout>{children}</Layout>
</div>
);
};
export default Sidebar;