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-06-10 17:55:18 -05:00
|
|
|
import { Disclosure, Transition } from "@headlessui/react";
|
2023-12-17 17:54:33 -06:00
|
|
|
import SidebarHighlightLink from "@/components/SidebarHighlightLink";
|
2024-02-19 13:37:07 -06:00
|
|
|
import CollectionListing from "@/components/CollectionListing";
|
2024-06-09 08:27:16 -05:00
|
|
|
import { useTranslation } from "next-i18next";
|
2024-07-30 13:57:09 -05:00
|
|
|
import { useCollections } from "@/hooks/store/collections";
|
2023-02-08 17:58:55 -06:00
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function Sidebar({ className }: { className?: string }) {
|
2024-06-09 08:27:16 -05:00
|
|
|
const { t } = useTranslation();
|
2023-06-10 17:55:18 -05:00
|
|
|
const [tagDisclosure, setTagDisclosure] = useState<boolean>(() => {
|
|
|
|
const storedValue = localStorage.getItem("tagDisclosure");
|
|
|
|
return storedValue ? storedValue === "true" : true;
|
|
|
|
});
|
|
|
|
|
|
|
|
const [collectionDisclosure, setCollectionDisclosure] = useState<boolean>(
|
|
|
|
() => {
|
|
|
|
const storedValue = localStorage.getItem("collectionDisclosure");
|
|
|
|
return storedValue ? storedValue === "true" : true;
|
2023-12-17 22:32:33 -06:00
|
|
|
}
|
2023-06-10 17:55:18 -05:00
|
|
|
);
|
|
|
|
|
2024-07-30 13:57:09 -05:00
|
|
|
const { data: { response: collections } = { response: [] } } =
|
|
|
|
useCollections();
|
|
|
|
|
2023-03-22 18:11:54 -05:00
|
|
|
const { tags } = useTagStore();
|
2024-02-22 01:51:51 -06:00
|
|
|
const [active, setActive] = useState("");
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-05-01 05:07:01 -05:00
|
|
|
const router = useRouter();
|
|
|
|
|
2023-06-10 17:55:18 -05:00
|
|
|
useEffect(() => {
|
|
|
|
localStorage.setItem("tagDisclosure", tagDisclosure ? "true" : "false");
|
|
|
|
}, [tagDisclosure]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
localStorage.setItem(
|
|
|
|
"collectionDisclosure",
|
2023-12-17 22:32:33 -06:00
|
|
|
collectionDisclosure ? "true" : "false"
|
2023-06-10 17:55:18 -05:00
|
|
|
);
|
|
|
|
}, [collectionDisclosure]);
|
|
|
|
|
2023-05-01 05:07:01 -05:00
|
|
|
useEffect(() => {
|
|
|
|
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-12-16 08:16:25 -06:00
|
|
|
id="sidebar"
|
2024-02-22 02:51:24 -06:00
|
|
|
className={`bg-base-200 h-full w-80 overflow-y-auto border-solid border border-base-200 border-r-neutral-content p-2 z-20 ${
|
|
|
|
className || ""
|
|
|
|
}`}
|
2023-05-15 13:29:51 -05:00
|
|
|
>
|
2023-12-17 22:55:38 -06:00
|
|
|
<div className="grid grid-cols-2 gap-2">
|
|
|
|
<SidebarHighlightLink
|
2024-07-18 08:51:16 -05:00
|
|
|
title={t("dashboard")}
|
2023-12-17 22:55:38 -06:00
|
|
|
href={`/dashboard`}
|
|
|
|
icon={"bi-house"}
|
|
|
|
active={active === `/dashboard`}
|
2023-12-17 17:54:33 -06:00
|
|
|
/>
|
2023-12-17 22:55:38 -06:00
|
|
|
<SidebarHighlightLink
|
2024-07-18 08:51:16 -05:00
|
|
|
title={t("pinned")}
|
2023-12-17 22:55:38 -06:00
|
|
|
href={`/links/pinned`}
|
|
|
|
icon={"bi-pin-angle"}
|
|
|
|
active={active === `/links/pinned`}
|
2023-12-17 17:54:33 -06:00
|
|
|
/>
|
2023-12-17 22:55:38 -06:00
|
|
|
<SidebarHighlightLink
|
2024-07-18 08:51:16 -05:00
|
|
|
title={t("all_links")}
|
2023-12-17 22:55:38 -06:00
|
|
|
href={`/links`}
|
|
|
|
icon={"bi-link-45deg"}
|
|
|
|
active={active === `/links`}
|
2023-12-17 17:54:33 -06:00
|
|
|
/>
|
2023-12-17 22:55:38 -06:00
|
|
|
<SidebarHighlightLink
|
2024-07-18 08:51:16 -05:00
|
|
|
title={t("all_collections")}
|
2023-12-17 22:55:38 -06:00
|
|
|
href={`/collections`}
|
2023-12-19 10:50:43 -06:00
|
|
|
icon={"bi-folder"}
|
2023-12-17 22:55:38 -06:00
|
|
|
active={active === `/collections`}
|
2023-12-17 17:54:33 -06:00
|
|
|
/>
|
2023-06-02 06:59:52 -05:00
|
|
|
</div>
|
2023-02-13 15:22:47 -06:00
|
|
|
|
2023-06-10 17:55:18 -05:00
|
|
|
<Disclosure defaultOpen={collectionDisclosure}>
|
|
|
|
<Disclosure.Button
|
|
|
|
onClick={() => {
|
|
|
|
setCollectionDisclosure(!collectionDisclosure);
|
|
|
|
}}
|
2023-12-16 08:16:25 -06:00
|
|
|
className="flex items-center justify-between w-full text-left mb-2 pl-2 font-bold text-neutral mt-5"
|
2023-06-10 17:55:18 -05:00
|
|
|
>
|
2024-06-09 08:27:16 -05:00
|
|
|
<p className="text-sm">{t("collections")}</p>
|
2023-12-16 08:16:25 -06:00
|
|
|
<i
|
2024-02-22 02:51:24 -06:00
|
|
|
className={`bi-chevron-down ${
|
|
|
|
collectionDisclosure ? "rotate-reverse" : "rotate"
|
|
|
|
}`}
|
2023-12-16 08:16:25 -06:00
|
|
|
></i>
|
2023-06-10 17:55:18 -05:00
|
|
|
</Disclosure.Button>
|
|
|
|
<Transition
|
|
|
|
enter="transition duration-100 ease-out"
|
|
|
|
enterFrom="transform opacity-0 -translate-y-3"
|
|
|
|
enterTo="transform opacity-100 translate-y-0"
|
|
|
|
leave="transition duration-100 ease-out"
|
|
|
|
leaveFrom="transform opacity-100 translate-y-0"
|
|
|
|
leaveTo="transform opacity-0 -translate-y-3"
|
|
|
|
>
|
2024-02-05 01:42:54 -06:00
|
|
|
<Disclosure.Panel>
|
2024-03-02 08:07:33 -06:00
|
|
|
<CollectionListing />
|
2023-06-10 17:55:18 -05:00
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
|
|
|
</Disclosure>
|
|
|
|
<Disclosure defaultOpen={tagDisclosure}>
|
|
|
|
<Disclosure.Button
|
|
|
|
onClick={() => {
|
|
|
|
setTagDisclosure(!tagDisclosure);
|
|
|
|
}}
|
2023-12-16 08:16:25 -06:00
|
|
|
className="flex items-center justify-between w-full text-left mb-2 pl-2 font-bold text-neutral mt-5"
|
2023-06-10 17:55:18 -05:00
|
|
|
>
|
2024-06-09 08:27:16 -05:00
|
|
|
<p className="text-sm">{t("tags")}</p>
|
2023-12-16 08:16:25 -06:00
|
|
|
<i
|
2024-02-22 02:51:24 -06:00
|
|
|
className={`bi-chevron-down ${
|
|
|
|
tagDisclosure ? "rotate-reverse" : "rotate"
|
|
|
|
}`}
|
2023-12-16 08:16:25 -06:00
|
|
|
></i>
|
2023-06-10 17:55:18 -05:00
|
|
|
</Disclosure.Button>
|
|
|
|
<Transition
|
|
|
|
enter="transition duration-100 ease-out"
|
|
|
|
enterFrom="transform opacity-0 -translate-y-3"
|
|
|
|
enterTo="transform opacity-100 translate-y-0"
|
|
|
|
leave="transition duration-100 ease-out"
|
|
|
|
leaveFrom="transform opacity-100 translate-y-0"
|
|
|
|
leaveTo="transform opacity-0 -translate-y-3"
|
|
|
|
>
|
|
|
|
<Disclosure.Panel className="flex flex-col gap-1">
|
2023-07-19 16:49:54 -05:00
|
|
|
{tags[0] ? (
|
|
|
|
tags
|
|
|
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
|
|
.map((e, i) => {
|
|
|
|
return (
|
|
|
|
<Link key={i} href={`/tags/${e.id}`}>
|
|
|
|
<div
|
2024-02-22 02:51:24 -06:00
|
|
|
className={`${
|
|
|
|
active === `/tags/${e.id}`
|
|
|
|
? "bg-primary/20"
|
|
|
|
: "hover:bg-neutral/20"
|
|
|
|
} duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}
|
2023-07-19 16:49:54 -05:00
|
|
|
>
|
2023-12-16 08:16:25 -06:00
|
|
|
<i className="bi-hash text-2xl text-primary drop-shadow"></i>
|
2023-11-24 07:39:55 -06:00
|
|
|
<p className="truncate w-full pr-7">{e.name}</p>
|
2023-11-25 04:39:56 -06:00
|
|
|
<div className="drop-shadow text-neutral text-xs">
|
2023-11-15 12:12:06 -06:00
|
|
|
{e._count?.links}
|
|
|
|
</div>
|
2023-07-19 16:49:54 -05:00
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
) : (
|
|
|
|
<div
|
|
|
|
className={`duration-100 py-1 px-2 flex items-center gap-2 w-full rounded-md h-8 capitalize`}
|
|
|
|
>
|
2023-11-25 04:39:56 -06:00
|
|
|
<p className="text-neutral text-xs font-semibold truncate w-full pr-7">
|
2024-06-09 08:27:16 -05:00
|
|
|
{t("you_have_no_tags")}
|
2023-07-19 16:49:54 -05:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-06-10 17:55:18 -05:00
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
|
|
|
</Disclosure>
|
2023-02-08 17:58:55 -06:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|