BookmarkStore manages the application’s bookmark state, including CRUD operations, filtering by tags, sorting, and time period selection. Built with Zustand for global state management.
Import
Usage
State Properties
Array of bookmark objects. Each bookmark contains
id, title, domain, url, description, image, created_at, saved_by, tags, and pinned properties.Loading state for async operations (fetch, add, delete, update).
Currently selected tag filter. Set to
"all" to show all bookmarks.Sort order for bookmarks. Can be
"asc" (oldest first) or "desc" (newest first).Time period filter for bookmarks. Options:
"all", "month", or "week".Methods
fetch
Fetches all bookmarks for a specific user from Supabase.The user ID to fetch bookmarks for.
Promise<StoreResponse>
Whether the operation succeeded.
Array of bookmarks on success, error message string on failure.
add
Adds a new bookmark by fetching metadata from the URL.The URL to bookmark. Must be a valid URL starting with
https://.The user ID of the person saving the bookmark.
Promise<StoreResponse>
delete
Deletes a bookmark and updates the local state.The ID of the bookmark to delete.
Promise<StoreResponse>
update
Updates an existing bookmark.The ID of the bookmark to update.
The updated bookmark object with new values.
Promise<StoreResponse>
setSelectedTag
Sets the currently selected tag filter.The tag name to filter by, or
"all" to show all bookmarks.setOrder
Sets the sort order for bookmarks.The sort order:
"asc" (oldest first) or "desc" (newest first).setTimePeriod
Sets the time period filter for bookmarks.The time period:
"all", "month", or "week".Type Definitions
Implementation Details
- State Management: Uses Zustand for lightweight, hook-based state management
- Database: All CRUD operations interact with Supabase
- Metadata Fetching: The
addmethod automatically fetches page metadata (title, description, images) from the provided URL - Optimistic Updates: Delete and update methods immediately update local state for responsive UI
- Error Handling: All async methods return a
StoreResponseobject withsuccessflag anddatapayload - Automatic Sorting: Bookmarks are fetched sorted by
pinnedstatus (descending) thencreated_at(descending)