el.xwx.moe/components/Sidebar/index.tsx

142 lines
3.9 KiB
TypeScript
Raw Normal View History

2023-03-22 18:11:54 -05:00
import useCollectionStore from "@/store/collections";
2023-02-18 21:32:02 -06:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faFolder,
2023-03-05 15:03:20 -06:00
faBox,
2023-03-10 13:25:33 -06:00
faHashtag,
2023-02-24 22:22:33 -06:00
faBookmark,
faChartSimple,
2023-02-18 21:32:02 -06:00
} from "@fortawesome/free-solid-svg-icons";
import SidebarItem from "./SidebarItem";
2023-03-22 18:11:54 -05:00
import useTagStore from "@/store/tags";
2023-03-05 15:03:20 -06:00
import Link from "next/link";
2023-05-01 05:07:01 -05:00
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
2023-02-08 17:58:55 -06:00
2023-05-15 13:29:51 -05:00
export default function ({ className }: { className?: string }) {
2023-04-24 16:30:40 -05:00
const { collections } = useCollectionStore();
2023-03-22 18:11:54 -05:00
const { tags } = useTagStore();
2023-05-01 05:07:01 -05:00
const router = useRouter();
const [active, setActive] = useState("");
useEffect(() => {
setActive(router.asPath);
}, [router]);
2023-02-08 17:58:55 -06:00
return (
2023-05-15 13:29:51 -05:00
<div
2023-05-28 17:06:49 -05:00
className={`bg-gray-100 h-screen w-64 xl:w-80 overflow-y-auto border-solid border-r-sky-100 border z-20 ${className}`}
2023-05-15 13:29:51 -05:00
>
2023-05-28 17:06:49 -05:00
<p className="p-4 text-sky-500 font-bold text-2xl my-2 leading-4">
2023-03-28 02:31:50 -05:00
Linkwarden
</p>
2023-02-18 21:32:02 -06:00
<Link href="/dashboard">
<div
className={`${
active === "/dashboard"
? "bg-sky-500"
2023-05-28 17:06:49 -05:00
: "hover:bg-slate-200 bg-gray-100"
} outline-sky-100 outline-1 duration-100 py-1 px-4 cursor-pointer flex items-center gap-2`}
>
<FontAwesomeIcon
icon={faChartSimple}
2023-05-28 17:06:49 -05:00
className={`w-4 h-4 ${
active === "/dashboard" ? "text-white" : "text-sky-300"
}`}
/>
<p
className={`${
active === "/dashboard" ? "text-white" : "text-sky-900"
}`}
>
Dashboard
</p>
</div>
</Link>
2023-05-31 21:45:19 -05:00
<Link href="/collections">
2023-05-01 05:07:01 -05:00
<div
className={`${
2023-05-31 21:45:19 -05:00
active === "/collections" ? "bg-sky-500" : "hover:bg-slate-200"
} outline-sky-100 outline-1 duration-100 py-1 px-4 cursor-pointer flex items-center gap-2`}
2023-05-01 05:07:01 -05:00
>
<FontAwesomeIcon
2023-05-31 21:45:19 -05:00
icon={faBox}
2023-05-28 17:06:49 -05:00
className={`w-4 h-4 ${
2023-05-31 21:45:19 -05:00
active === "/collections" ? "text-white" : "text-sky-300"
2023-05-01 05:07:01 -05:00
}`}
/>
<p
2023-05-31 21:45:19 -05:00
className={`${
active === "/collections" ? "text-white" : "text-sky-900"
}`}
2023-05-01 05:07:01 -05:00
>
2023-05-31 21:45:19 -05:00
All Collections
2023-05-01 05:07:01 -05:00
</p>
2023-03-05 15:03:20 -06:00
</div>
</Link>
2023-02-24 22:22:33 -06:00
2023-05-31 21:45:19 -05:00
<Link href="/links">
2023-05-01 05:07:01 -05:00
<div
className={`${
2023-05-31 21:45:19 -05:00
active === "/links"
? "bg-sky-500"
: "hover:bg-slate-200 bg-gray-100"
} outline-sky-100 outline-1 duration-100 py-1 px-4 cursor-pointer flex items-center gap-2`}
2023-05-01 05:07:01 -05:00
>
<FontAwesomeIcon
2023-05-31 21:45:19 -05:00
icon={faBookmark}
2023-05-28 17:06:49 -05:00
className={`w-4 h-4 ${
2023-05-31 21:45:19 -05:00
active === "/links" ? "text-white" : "text-sky-300"
2023-05-01 05:07:01 -05:00
}`}
/>
<p
2023-05-31 21:45:19 -05:00
className={`${active === "/links" ? "text-white" : "text-sky-900"}`}
2023-05-01 05:07:01 -05:00
>
2023-05-31 21:45:19 -05:00
All Links
2023-05-01 05:07:01 -05:00
</p>
2023-03-05 15:03:20 -06:00
</div>
</Link>
2023-04-24 16:30:40 -05:00
<div className="text-gray-500 mt-5">
2023-05-28 17:06:49 -05:00
<p className="text-sm px-4 mb-2">Collections</p>
</div>
2023-02-18 21:32:02 -06:00
<div>
2023-05-25 13:44:08 -05:00
{collections
.sort((a, b) => a.name.localeCompare(b.name))
.map((e, i) => {
return (
<SidebarItem
key={i}
text={e.name}
icon={<FontAwesomeIcon icon={faFolder} />}
path={`/collections/${e.id}`}
className="capitalize"
/>
);
})}
</div>
2023-04-24 16:30:40 -05:00
<div className="text-gray-500 mt-5">
2023-05-28 17:06:49 -05:00
<p className="text-sm px-4 mb-2">Tags</p>
</div>
<div>
2023-05-25 21:21:35 -05:00
{tags
.sort((a, b) => a.name.localeCompare(b.name))
.map((e, i) => {
return (
<SidebarItem
key={i}
text={e.name}
icon={<FontAwesomeIcon icon={faHashtag} />}
path={`/tags/${e.id}`}
/>
);
})}
2023-02-18 21:32:02 -06:00
</div>
2023-02-08 17:58:55 -06:00
</div>
);
}