diff options
| author | Md Saban <45597394+mdsaban@users.noreply.github.com> | 2024-07-02 03:51:23 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-01 23:21:23 +0100 |
| commit | d193d9bf89e8a88bf70b673ea5e438d73cf40c0c (patch) | |
| tree | 56d260c0624b74bda054f8865c3bd2e166f49e8d /apps/web/lib | |
| parent | bf92fa3386be331871963f99ec5c813186a388b3 (diff) | |
| download | karakeep-d193d9bf89e8a88bf70b673ea5e438d73cf40c0c.tar.zst | |
feat: Add bulk edit option for bookmarks. Fixes #84 (#259)
* feat: add bulk edit option for bookmarks
* fix: resolve comments
* fix: resolve comments
* fix: resolve comments
* fix: resolve comments
* rename bulk action store, simplify the bulk action toolbar
---------
Co-authored-by: MohamedBassem <me@mbassem.com>
Diffstat (limited to '')
| -rw-r--r-- | apps/web/lib/bulkActions.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/apps/web/lib/bulkActions.ts b/apps/web/lib/bulkActions.ts new file mode 100644 index 00000000..1e9dbbd7 --- /dev/null +++ b/apps/web/lib/bulkActions.ts @@ -0,0 +1,39 @@ +// reference article https://refine.dev/blog/zustand-react-state/#build-a-to-do-app-using-zustand +import { create } from "zustand"; + +import type { ZBookmark } from "@hoarder/shared/types/bookmarks"; + +interface BookmarkState { + selectedBookmarks: ZBookmark[]; + isBulkEditEnabled: boolean; + setIsBulkEditEnabled: (isEnabled: boolean) => void; + toggleBookmark: (bookmark: ZBookmark) => void; +} + +const useBulkActionsStore = create<BookmarkState>((set, get) => ({ + selectedBookmarks: [], + isBulkEditEnabled: false, + + toggleBookmark: (bookmark: ZBookmark) => { + const selectedBookmarks = get().selectedBookmarks; + const isBookmarkAlreadySelected = selectedBookmarks.some( + (b) => b.id === bookmark.id, + ); + if (isBookmarkAlreadySelected) { + set({ + selectedBookmarks: selectedBookmarks.filter( + (b) => b.id !== bookmark.id, + ), + }); + } else { + set({ selectedBookmarks: [...selectedBookmarks, bookmark] }); + } + }, + + setIsBulkEditEnabled: (isEnabled) => { + set({ isBulkEditEnabled: isEnabled }); + set({ selectedBookmarks: [] }); + }, +})); + +export default useBulkActionsStore; |
