import { useRouter } from "next/navigation"; import { ActionButton } from "@/components/ui/action-button"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import { toast } from "@/components/ui/use-toast"; import { Trash2 } from "lucide-react"; import type { ZBookmark } from "@hoarder/shared/types/bookmarks"; import { useDeleteBookmark, useUpdateBookmark, } from "@hoarder/shared-react/hooks/bookmarks"; import { ArchivedActionIcon, FavouritedActionIcon } from "../bookmarks/icons"; export default function ActionBar({ bookmark }: { bookmark: ZBookmark }) { const router = useRouter(); const onError = () => { toast({ variant: "destructive", title: "Something went wrong", description: "There was a problem with your request.", }); }; const { mutate: favBookmark, isPending: pendingFav } = useUpdateBookmark({ onSuccess: () => { toast({ description: "The bookmark has been updated!", }); }, onError, }); const { mutate: archiveBookmark, isPending: pendingArchive } = useUpdateBookmark({ onSuccess: (resp) => { toast({ description: `The bookmark has been ${resp.archived ? "Archived" : "Un-archived"}!`, }); }, onError, }); const { mutate: deleteBookmark, isPending: pendingDeletion } = useDeleteBookmark({ onSuccess: () => { toast({ description: "The bookmark has been deleted!", }); router.back(); }, onError, }); return (
{ favBookmark({ bookmarkId: bookmark.id, favourited: !bookmark.favourited, }); }} > {bookmark.favourited ? "Un-favourite" : "Favourite"} { archiveBookmark({ bookmarkId: bookmark.id, archived: !bookmark.archived, }); }} > {bookmark.archived ? "Un-archive" : "Archive"} { deleteBookmark({ bookmarkId: bookmark.id }); }} > Delete
); }