From 2619f4cfefdf9264a7f4c3a8741493323fdde901 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Fri, 28 Nov 2025 15:39:57 +0000 Subject: fix: separate shared lists in the sidebar (#2180) * fix: separate shared lists in the sidebar * fix sub * i18n --- apps/web/components/dashboard/sidebar/AllLists.tsx | 137 +++++++++++++++++++-- 1 file changed, 130 insertions(+), 7 deletions(-) (limited to 'apps/web/components/dashboard/sidebar') diff --git a/apps/web/components/dashboard/sidebar/AllLists.tsx b/apps/web/components/dashboard/sidebar/AllLists.tsx index 1cc3f3a5..f8b80cba 100644 --- a/apps/web/components/dashboard/sidebar/AllLists.tsx +++ b/apps/web/components/dashboard/sidebar/AllLists.tsx @@ -1,16 +1,24 @@ "use client"; -import { useCallback, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import SidebarItem from "@/components/shared/sidebar/SidebarItem"; import { Button } from "@/components/ui/button"; -import { CollapsibleTriggerTriangle } from "@/components/ui/collapsible"; +import { + Collapsible, + CollapsibleContent, + CollapsibleTriggerTriangle, +} from "@/components/ui/collapsible"; import { useTranslation } from "@/lib/i18n/client"; import { cn } from "@/lib/utils"; import { MoreHorizontal, Plus } from "lucide-react"; import type { ZBookmarkList } from "@karakeep/shared/types/lists"; +import { + augmentBookmarkListsWithInitialData, + useBookmarkLists, +} from "@karakeep/shared-react/hooks/lists"; import { ZBookmarkListTreeNode } from "@karakeep/shared/utils/listUtils"; import { CollapsibleBookmarkLists } from "../lists/CollapsibleBookmarkLists"; @@ -31,6 +39,36 @@ export default function AllLists({ const [selectedListId, setSelectedListId] = useState(null); + // Fetch live lists data + const { data: listsData } = useBookmarkLists(undefined, { + initialData: { lists: initialData.lists }, + }); + const lists = augmentBookmarkListsWithInitialData( + listsData, + initialData.lists, + ); + + // Check if any shared list is currently being viewed + const isViewingSharedList = useMemo(() => { + return lists.data.some( + (list) => list.userRole !== "owner" && pathName.includes(list.id), + ); + }, [lists.data, pathName]); + + // Check if there are any shared lists + const hasSharedLists = useMemo(() => { + return lists.data.some((list) => list.userRole !== "owner"); + }, [lists.data]); + + const [sharedListsOpen, setSharedListsOpen] = useState(isViewingSharedList); + + // Auto-open shared lists if viewing one + useEffect(() => { + if (isViewingSharedList && !sharedListsOpen) { + setSharedListsOpen(true); + } + }, [isViewingSharedList, sharedListsOpen]); + return ( ); } -- cgit v1.2.3-70-g09d2