diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx index 967af7b..c9074e6 100644 --- a/components/Sidebar.tsx +++ b/components/Sidebar.tsx @@ -6,13 +6,27 @@ import { faHashtag, faBookmark, faChartSimple, + faChevronDown, } from "@fortawesome/free-solid-svg-icons"; import useTagStore from "@/store/tags"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import { Disclosure, Transition } from "@headlessui/react"; export default function Sidebar({ className }: { className?: string }) { + const [tagDisclosure, setTagDisclosure] = useState(() => { + const storedValue = localStorage.getItem("tagDisclosure"); + return storedValue ? storedValue === "true" : true; + }); + + const [collectionDisclosure, setCollectionDisclosure] = useState( + () => { + const storedValue = localStorage.getItem("collectionDisclosure"); + return storedValue ? storedValue === "true" : true; + } + ); + const { collections } = useCollectionStore(); const { tags } = useTagStore(); @@ -20,6 +34,17 @@ export default function Sidebar({ className }: { className?: string }) { const [active, setActive] = useState(""); + useEffect(() => { + localStorage.setItem("tagDisclosure", tagDisclosure ? "true" : "false"); + }, [tagDisclosure]); + + useEffect(() => { + localStorage.setItem( + "collectionDisclosure", + collectionDisclosure ? "true" : "false" + ); + }, [collectionDisclosure]); + useEffect(() => { setActive(router.asPath); }, [router, collections]); @@ -80,61 +105,104 @@ export default function Sidebar({ className }: { className?: string }) { -
-

Collections

-
-
- {collections - .sort((a, b) => a.name.localeCompare(b.name)) - .map((e, i) => { - return ( - -
- + + { + setCollectionDisclosure(!collectionDisclosure); + }} + className="flex items-center justify-between text-sm w-full text-left mb-2 pl-2 font-bold text-gray-500 mt-5" + > +

Collections

-

{e.name}

-
- - ); - })} -
-
-

Tags

-
-
- {tags - .sort((a, b) => a.name.localeCompare(b.name)) - .map((e, i) => { - return ( - -
- + + + + + {collections + .sort((a, b) => a.name.localeCompare(b.name)) + .map((e, i) => { + return ( + +
+ -

{e.name}

-
- - ); - })} -
+

{e.name}

+
+ + ); + })} + + + + + { + setTagDisclosure(!tagDisclosure); + }} + className="flex items-center justify-between text-sm w-full text-left mb-2 pl-2 font-bold text-gray-500 mt-5" + > +

Tags

+ +
+ + + {tags + .sort((a, b) => a.name.localeCompare(b.name)) + .map((e, i) => { + return ( + +
+ + +

{e.name}

+
+ + ); + })} +
+
+
); } diff --git a/styles/globals.css b/styles/globals.css index e760b44..e5d185e 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -27,6 +27,16 @@ hyphens: auto; } +.rotate { + transition: transform 0.1s ease; + transform: rotate(-90deg); +} + +.rotate-reverse { + transition: transform 0.1s ease; + transform: rotate(0deg); +} + .fade-in { animation: fade-in-animation 100ms; }