-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(web): Add an archive button to list management dialog
- Loading branch information
1 parent
bfcf0a4
commit f99f4c0
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
apps/web/components/dashboard/bookmarks/action-buttons/ArchiveBookmarkButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import { ActionButton, ActionButtonProps } from "@/components/ui/action-button"; | ||
import { toast } from "@/components/ui/use-toast"; | ||
import { api } from "@/lib/trpc"; | ||
|
||
import { useUpdateBookmark } from "@hoarder/shared-react/hooks/bookmarks"; | ||
|
||
interface ArchiveBookmarkButtonProps | ||
extends Omit<ActionButtonProps, "loading" | "disabled"> { | ||
bookmarkId: string; | ||
onDone?: () => void; | ||
} | ||
|
||
const ArchiveBookmarkButton = React.forwardRef< | ||
HTMLButtonElement, | ||
ArchiveBookmarkButtonProps | ||
>(({ bookmarkId, onDone, ...props }, ref) => { | ||
const { data } = api.bookmarks.getBookmark.useQuery({ bookmarkId }); | ||
|
||
const { mutate: updateBookmark, isPending: isArchivingBookmark } = | ||
useUpdateBookmark({ | ||
onSuccess: () => { | ||
toast({ | ||
description: "Bookmark has been archived!", | ||
}); | ||
onDone?.(); | ||
}, | ||
onError: (e) => { | ||
if (e.data?.code == "BAD_REQUEST") { | ||
toast({ | ||
variant: "destructive", | ||
description: e.message, | ||
}); | ||
} else { | ||
toast({ | ||
variant: "destructive", | ||
title: "Something went wrong", | ||
}); | ||
} | ||
}, | ||
}); | ||
|
||
if (!data) { | ||
return <span />; | ||
} | ||
|
||
return ( | ||
<ActionButton | ||
ref={ref} | ||
loading={isArchivingBookmark} | ||
disabled={data.archived} | ||
onClick={() => | ||
updateBookmark({ | ||
bookmarkId, | ||
archived: !data.archived, | ||
}) | ||
} | ||
{...props} | ||
/> | ||
); | ||
}); | ||
|
||
ArchiveBookmarkButton.displayName = "ArchiveBookmarkButton"; | ||
export default ArchiveBookmarkButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters