el.xwx.moe/components/Sidebar.tsx

142 lines
4.6 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";
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(() => {
2023-06-05 15:47:01 -05:00
console.log(window.location.hash);
2023-05-01 05:07:01 -05:00
setActive(router.asPath);
2023-06-05 04:54:43 -05:00
}, [router, collections]);
2023-05-01 05:07:01 -05:00
2023-02-08 17:58:55 -06:00
return (
2023-05-15 13:29:51 -05:00
<div
2023-06-02 06:59:52 -05:00
className={`bg-gray-100 h-screen w-64 xl:w-80 overflow-y-auto border-solid border-r-sky-100 px-2 border z-20 ${className}`}
2023-05-15 13:29:51 -05:00
>
2023-06-05 04:54:43 -05:00
<p className="p-2 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
2023-06-02 06:59:52 -05:00
<div className="flex flex-col gap-1">
<Link href="/dashboard">
<div
className={`${
2023-06-02 06:59:52 -05:00
active === "/dashboard"
2023-06-05 04:54:43 -05:00
? "bg-sky-200"
2023-06-02 06:59:52 -05:00
: "hover:bg-slate-200 bg-gray-100"
} outline-sky-100 outline-1 duration-100 py-1 px-2 rounded-md cursor-pointer flex items-center gap-2`}
>
2023-06-02 06:59:52 -05:00
<FontAwesomeIcon
icon={faChartSimple}
2023-06-05 04:54:43 -05:00
className={`w-6 h-6 drop-shadow text-sky-500`}
2023-06-02 06:59:52 -05:00
/>
2023-06-05 04:54:43 -05:00
<p className="text-sky-600">Dashboard</p>
2023-06-02 06:59:52 -05:00
</div>
</Link>
2023-06-02 06:59:52 -05:00
<Link href="/collections">
<div
2023-05-31 21:45:19 -05:00
className={`${
2023-06-05 04:54:43 -05:00
active === "/collections" ? "bg-sky-200" : "hover:bg-slate-200"
2023-06-02 06:59:52 -05:00
} outline-sky-100 outline-1 duration-100 py-1 px-2 rounded-md cursor-pointer flex items-center gap-2`}
2023-05-01 05:07:01 -05:00
>
2023-06-02 06:59:52 -05:00
<FontAwesomeIcon
icon={faBox}
2023-06-05 04:54:43 -05:00
className={`w-6 h-6 drop-shadow text-sky-500`}
2023-06-02 06:59:52 -05:00
/>
2023-06-05 04:54:43 -05:00
<p className="text-sky-600">All Collections</p>
2023-06-02 06:59:52 -05:00
</div>
</Link>
2023-02-24 22:22:33 -06:00
2023-06-02 06:59:52 -05:00
<Link href="/links">
<div
className={`${
active === "/links"
2023-06-05 04:54:43 -05:00
? "bg-sky-200"
2023-06-02 06:59:52 -05:00
: "hover:bg-slate-200 bg-gray-100"
} outline-sky-100 outline-1 duration-100 py-1 px-2 rounded-md cursor-pointer flex items-center gap-2`}
2023-05-01 05:07:01 -05:00
>
2023-06-02 06:59:52 -05:00
<FontAwesomeIcon
icon={faBookmark}
2023-06-05 04:54:43 -05:00
className={`w-6 h-6 drop-shadow text-sky-500`}
2023-06-02 06:59:52 -05:00
/>
2023-06-05 04:54:43 -05:00
<p className="text-sky-600">All Links</p>
2023-06-02 06:59:52 -05:00
</div>
</Link>
</div>
2023-04-24 16:30:40 -05:00
<div className="text-gray-500 mt-5">
2023-06-05 04:54:43 -05:00
<p className="text-sm mb-2 pl-2 font-semibold">Collections</p>
</div>
2023-06-02 06:59:52 -05:00
<div className="flex flex-col gap-1">
2023-05-25 13:44:08 -05:00
{collections
.sort((a, b) => a.name.localeCompare(b.name))
.map((e, i) => {
return (
2023-06-05 04:54:43 -05:00
<Link key={i} href={`/collections/${e.id}`}>
<div
className={`${
active === `/collections/${e.id}`
? "bg-sky-200"
: "hover:bg-slate-200 bg-gray-100"
} duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8 capitalize`}
>
<FontAwesomeIcon
icon={faFolder}
className="w-6 h-6 drop-shadow"
style={{ color: e.color }}
/>
<p className="text-sky-600 truncate w-4/6">{e.name}</p>
</div>
</Link>
2023-05-25 13:44:08 -05:00
);
})}
</div>
2023-04-24 16:30:40 -05:00
<div className="text-gray-500 mt-5">
2023-06-05 04:54:43 -05:00
<p className="text-sm mb-2 pl-2 font-semibold">Tags</p>
</div>
2023-06-02 06:59:52 -05:00
<div className="flex flex-col gap-1">
2023-05-25 21:21:35 -05:00
{tags
.sort((a, b) => a.name.localeCompare(b.name))
.map((e, i) => {
return (
2023-06-05 04:54:43 -05:00
<Link key={i} href={`/tags/${e.id}`}>
<div
className={`${
active === `/tags/${e.id}`
? "bg-sky-200"
: "hover:bg-slate-200 bg-gray-100"
} duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
>
<FontAwesomeIcon
icon={faHashtag}
className="w-4 h-4 text-sky-500 mt-1"
/>
<p className="text-sky-600 truncate w-4/6">{e.name}</p>
</div>
</Link>
2023-05-25 21:21:35 -05:00
);
})}
2023-02-18 21:32:02 -06:00
</div>
2023-02-08 17:58:55 -06:00
</div>
);
}