From 00bfdfb9264b100ad1474b240b8795c0bf1d6449 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Mon, 5 Feb 2024 02:42:54 -0500 Subject: [PATCH] add support for subcollections to the navbar --- components/CollectionSelection.tsx | 139 ++++++++++++++++++ components/ModalContent/NewTokenModal.tsx | 12 +- components/Sidebar.tsx | 45 +----- .../collectionId/updateCollectionById.ts | 1 + .../controllers/collections/getCollections.ts | 1 + pages/settings/access-tokens.tsx | 4 +- types/global.ts | 1 + 7 files changed, 153 insertions(+), 50 deletions(-) create mode 100644 components/CollectionSelection.tsx diff --git a/components/CollectionSelection.tsx b/components/CollectionSelection.tsx new file mode 100644 index 0000000..47a449f --- /dev/null +++ b/components/CollectionSelection.tsx @@ -0,0 +1,139 @@ +import useCollectionStore from "@/store/collections"; +import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; +import Link from "next/link"; +import { useRouter } from "next/router"; +import React, { useEffect, useState } from "react"; + +type Props = { + links: boolean; +}; + +const CollectionSelection = ({ links }: Props) => { + const { collections } = useCollectionStore(); + const [active, setActive] = useState(""); + const router = useRouter(); + + useEffect(() => { + setActive(router.asPath); + }, [router, collections]); + + return ( +
+ {collections[0] ? ( + collections + .sort((a, b) => a.name.localeCompare(b.name)) + .filter((e) => e.parentId === null) + .map((e, i) => ( + + )) + ) : ( +
+

+ You Have No Collections... +

+
+ )} +
+ ); +}; + +export default CollectionSelection; + +const CollectionItem = ({ + collection, + active, + collections, +}: { + collection: CollectionIncludingMembersAndLinkCount; + active: string; + collections: CollectionIncludingMembersAndLinkCount[]; +}) => { + const hasChildren = + collection.subCollections && collection.subCollections.length > 0; + + const router = useRouter(); + + return hasChildren ? ( +
+ + +
+ +

{collection.name}

+ + {collection.isPublic ? ( + + ) : undefined} +
+ {collection._count?.links} +
+
+ +
+ + {/* Nested Collections, make it recursively */} + + {hasChildren && ( +
+ {collections + .filter((e) => e.parentId === collection.id) + .map((subCollection) => ( + + ))} +
+ )} +
+ ) : ( + +
+ +

{collection.name}

+ + {collection.isPublic ? ( + + ) : undefined} +
+ {collection._count?.links} +
+
+ + ); +}; diff --git a/components/ModalContent/NewTokenModal.tsx b/components/ModalContent/NewTokenModal.tsx index 50565ed..2092eaa 100644 --- a/components/ModalContent/NewTokenModal.tsx +++ b/components/ModalContent/NewTokenModal.tsx @@ -74,7 +74,7 @@ export default function NewTokenModal({ onClose }: Props) {
-
+

Name

@@ -86,15 +86,15 @@ export default function NewTokenModal({ onClose }: Props) { />
-
+

Expires in

-
+
{token.expires === TokenExpiry.sevenDays && "7 Days"} {token.expires === TokenExpiry.oneMonth && "30 Days"} @@ -102,7 +102,7 @@ export default function NewTokenModal({ onClose }: Props) { {token.expires === TokenExpiry.threeMonths && "90 Days"} {token.expires === TokenExpiry.never && "No Expiration"}
-
    +
-
+