diff --git a/components/CollectionSelection.tsx b/components/CollectionSelection.tsx index 47a449f..e9aa758 100644 --- a/components/CollectionSelection.tsx +++ b/components/CollectionSelection.tsx @@ -60,8 +60,32 @@ const CollectionItem = ({ const router = useRouter(); + // Check if the current collection or any of its subcollections is active + const isActiveOrParentOfActive = React.useMemo(() => { + const isActive = active === `/collections/${collection.id}`; + if (isActive) return true; + + const checkIfParentOfActive = (parentId: number): boolean => { + return collections.some((e) => { + if (e.id === parseInt(active.split("/collections/")[1])) { + if (e.parentId === parentId) return true; + if (e.parentId) return checkIfParentOfActive(e.parentId); + } + return false; + }); + }; + + return checkIfParentOfActive(collection.id as number); + }, [active, collection.id, collections]); + + const [isOpen, setIsOpen] = useState(isActiveOrParentOfActive); + + useEffect(() => { + setIsOpen(isActiveOrParentOfActive); + }, [isActiveOrParentOfActive]); + return hasChildren ? ( -
+
- {/* Nested Collections, make it recursively */} - {hasChildren && ( -
+
{collections .filter((e) => e.parentId === collection.id) .map((subCollection) => ( diff --git a/components/ModalContent/NewLinkModal.tsx b/components/ModalContent/NewLinkModal.tsx index 03deba0..20bcef2 100644 --- a/components/ModalContent/NewLinkModal.tsx +++ b/components/ModalContent/NewLinkModal.tsx @@ -179,7 +179,7 @@ export default function NewLinkModal({ onClose }: Props) { setLink({ ...link, description: e.target.value }) } placeholder="Will be auto generated if nothing is provided." - className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-sky-300 dark:focus:border-sky-600 border-solid border outline-none duration-100" + className="resize-none w-full rounded-md p-2 border-neutral-content bg-base-200 focus:border-primary border-solid border outline-none duration-100" />
diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index 6118718..be55933 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -24,6 +24,7 @@ import CardView from "@/components/LinkViews/Layouts/CardView"; // import GridView from "@/components/LinkViews/Layouts/GridView"; import ListView from "@/components/LinkViews/Layouts/ListView"; import { dropdownTriggerer } from "@/lib/client/utils"; +import Link from "next/link"; export default function Index() { const { settings } = useLocalSettingsStore(); @@ -111,15 +112,46 @@ export default function Index() { > {activeCollection && (
-
- +
+
+ -

- {activeCollection?.name} -

+

+ {activeCollection?.name} +

+
+ + {activeCollection.subCollections && + activeCollection.subCollections.length > 0 ? ( +
+ + View Sub-Collections + + +
+ {collections + .filter((e) => e.parentId === activeCollection?.id) + .map((e, i) => { + return ( + + +

{e.name}

+ + ); + })} +
+
+ ) : undefined}
@@ -228,6 +260,32 @@ export default function Index() {

{activeCollection?.description}

) : undefined} + {/* {activeCollection?.subCollections && + activeCollection?.subCollections.length > 0 ? ( +
+ Sub-Collections +
+ {collections + .filter((e) => e.parentId === activeCollection?.id) + .map((e, i) => { + return ( + + +

{e.name}

+ + ); + })} +
+
+ ) : undefined} */} +
diff --git a/pages/collections/index.tsx b/pages/collections/index.tsx index ca342cf..f5ed526 100644 --- a/pages/collections/index.tsx +++ b/pages/collections/index.tsx @@ -39,7 +39,7 @@ export default function Collections() {
{sortedCollections - .filter((e) => e.ownerId === data?.user.id) + .filter((e) => e.ownerId === data?.user.id && e.parentId === null) .map((e, i) => { return ; })}