From 79d61be7e15dc5d23fb687a5f71e0097088a99ac Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 7 Apr 2024 18:30:00 +0100 Subject: feature: Extract hook logic into separate package and add a new action bar in bookmark preview --- .../web/components/dashboard/preview/ActionBar.tsx | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 apps/web/components/dashboard/preview/ActionBar.tsx (limited to 'apps/web/components/dashboard/preview/ActionBar.tsx') diff --git a/apps/web/components/dashboard/preview/ActionBar.tsx b/apps/web/components/dashboard/preview/ActionBar.tsx new file mode 100644 index 00000000..f2e3023e --- /dev/null +++ b/apps/web/components/dashboard/preview/ActionBar.tsx @@ -0,0 +1,115 @@ +import { ActionButton } from "@/components/ui/action-button"; +import { + Tooltip, + TooltipContent, + TooltipProvider, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { toast } from "@/components/ui/use-toast"; +import { Trash2 } from "lucide-react"; + +import type { ZBookmark } from "@hoarder/trpc/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 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!", + }); + }, + 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 + +
+
+ ); +} -- cgit v1.3-1-g0d28