"use client";
import { useMemo, useState } from "react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
import {
Collapsible,
CollapsibleContent,
CollapsibleTriggerChevron,
} from "@/components/ui/collapsible";
import { useTranslation } from "@/lib/i18n/client";
import { MoreHorizontal } from "lucide-react";
import type { ZBookmarkList } from "@karakeep/shared/types/lists";
import {
augmentBookmarkListsWithInitialData,
useBookmarkLists,
} from "@karakeep/shared-react/hooks/lists";
import { CollapsibleBookmarkLists } from "./CollapsibleBookmarkLists";
import { ListOptions } from "./ListOptions";
function ListItem({
name,
icon,
path,
style,
list,
open,
collapsible,
}: {
name: string;
icon: string;
path: string;
style?: React.CSSProperties;
list?: ZBookmarkList;
open?: boolean;
collapsible: boolean;
}) {
return (
{collapsible && (
)}
{icon} {name}
{list && (
)}
);
}
export default function AllListsView({
initialData,
}: {
initialData: ZBookmarkList[];
}) {
const { t } = useTranslation();
// Fetch live lists data
const { data: listsData } = useBookmarkLists(undefined, {
initialData: { lists: initialData },
});
const lists = augmentBookmarkListsWithInitialData(listsData, initialData);
// Check if there are any shared lists
const hasSharedLists = useMemo(() => {
return lists.data.some((list) => list.userRole !== "owner");
}, [lists.data]);
const [sharedListsOpen, setSharedListsOpen] = useState(true);
return (
{/* Owned Lists */}
node.item.userRole === "owner"}
render={({ node, level, open }) => (
0}
open={open}
style={{ marginLeft: `${level * 1}rem` }}
/>
)}
/>
{/* Shared Lists */}
{hasSharedLists && (
node.item.userRole !== "owner"}
indentOffset={1}
render={({ node, level, open }) => (
0}
open={open}
style={{ marginLeft: `${level * 1}rem` }}
/>
)}
/>
)}
);
}