import * as React from "react"; import { useSet } from "@uidotdev/usehooks"; import { Check, ChevronsUpDown } from "lucide-react"; import { useAddBookmarkToList, useBookmarkLists, useRemoveBookmarkFromList, } from "@karakeep/shared-react/hooks/lists"; import { cn } from "../utils/css"; import { api } from "../utils/trpc"; import { Button } from "./ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "./ui/command"; import { DynamicPopoverContent } from "./ui/dynamic-popover"; import { Popover, PopoverTrigger } from "./ui/popover"; export function ListsSelector({ bookmarkId }: { bookmarkId: string }) { const currentlyUpdating = useSet(); const [open, setOpen] = React.useState(false); const { mutate: addToList } = useAddBookmarkToList(); const { mutate: removeFromList } = useRemoveBookmarkFromList(); const { data: existingLists } = api.lists.getListsOfBookmark.useQuery({ bookmarkId, }); const { data: allLists } = useBookmarkLists(); const existingListIds = new Set(existingLists?.lists.map((list) => list.id)); const toggleList = (listId: string) => { currentlyUpdating.add(listId); if (existingListIds.has(listId)) { removeFromList( { bookmarkId, listId }, { onSettled: (_resp, _err, req) => currentlyUpdating.delete(req.listId), }, ); } else { addToList( { bookmarkId, listId }, { onSettled: (_resp, _err, req) => currentlyUpdating.delete(req.listId), }, ); } }; return ( You don't have any lists. {allLists?.allPaths.map((path) => { const lastItem = path[path.length - 1]; return ( {path .map((item) => `${item.icon} ${item.name}`) .join(" / ")} ); })} ); }