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}
);
};