Skip to content

Commit 6d0148c

Browse files
committed
feat: add error handling and state revalidation for bookmark deletion
1 parent 765dafd commit 6d0148c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/QuranReader/ContextMenu/components/PageBookmarkAction.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,20 @@ const PageBookmarkAction: React.FC<PageBookmarkActionProps> = ({ pageNumber }) =
8181

8282
// Handle bookmark removal
8383
const handleBookmarkRemove = () => {
84-
deleteBookmarkById(bookmark.id).then(() => {
85-
toast(t('quran-reader:page-bookmark-removed'), {
86-
status: ToastStatus.Success,
84+
deleteBookmarkById(bookmark.id)
85+
.then(() => {
86+
mutate();
87+
toast(t('quran-reader:page-bookmark-removed'), {
88+
status: ToastStatus.Success,
89+
});
90+
})
91+
.catch(() => {
92+
// Revalidate to restore the bookmark state in case of failure
93+
mutate(bookmark, { revalidate: true });
94+
toast(t('common:error.general'), {
95+
status: ToastStatus.Error,
96+
});
8797
});
88-
});
8998
};
9099

91100
const onToggleBookmarkClicked = () => {

0 commit comments

Comments
 (0)