diff options
| author | MohamedBassem <me@mbassem.com> | 2024-04-23 13:56:35 +0100 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-04-23 13:56:35 +0100 |
| commit | 77b1aba5acc66dfaeb02b08d60d88442336026a6 (patch) | |
| tree | 950f71d7c868869902e742644697e077db734769 /packages/shared-react/hooks | |
| parent | 0e260954c13cfedb03e75d3f0db8a2e839fd008d (diff) | |
| download | karakeep-77b1aba5acc66dfaeb02b08d60d88442336026a6.tar.zst | |
feature(extension): Allow adding tags and lists to newly hoarded bookmarks
Diffstat (limited to 'packages/shared-react/hooks')
| -rw-r--r-- | packages/shared-react/hooks/bookmarks.ts | 19 | ||||
| -rw-r--r-- | packages/shared-react/hooks/lists.ts | 7 |
2 files changed, 26 insertions, 0 deletions
diff --git a/packages/shared-react/hooks/bookmarks.ts b/packages/shared-react/hooks/bookmarks.ts index 2a549d1f..ceaed3a9 100644 --- a/packages/shared-react/hooks/bookmarks.ts +++ b/packages/shared-react/hooks/bookmarks.ts @@ -1,7 +1,26 @@ import { api } from "../trpc"; +import { isBookmarkStillLoading } from "../utils/bookmarkUtils"; import { useBookmarkGridContext } from "./bookmark-grid-context"; import { useAddBookmarkToList } from "./lists"; +export function useAutoRefreshingBookmarkQuery( + input: Parameters<typeof api.bookmarks.getBookmark.useQuery>[0], +) { + return api.bookmarks.getBookmark.useQuery(input, { + refetchInterval: (query) => { + const data = query.state.data; + if (!data) { + return false; + } + // If the link is not crawled or not tagged + if (isBookmarkStillLoading(data)) { + return 1000; + } + return false; + }, + }); +} + export function useCreateBookmarkWithPostHook( ...opts: Parameters<typeof api.bookmarks.createBookmark.useMutation> ) { diff --git a/packages/shared-react/hooks/lists.ts b/packages/shared-react/hooks/lists.ts index 61e50689..10633a08 100644 --- a/packages/shared-react/hooks/lists.ts +++ b/packages/shared-react/hooks/lists.ts @@ -41,6 +41,9 @@ export function useAddBookmarkToList( ...opts[0], onSuccess: (res, req, meta) => { apiUtils.bookmarks.getBookmarks.invalidate({ listId: req.listId }); + apiUtils.lists.getListsOfBookmark.invalidate({ + bookmarkId: req.bookmarkId, + }); return opts[0]?.onSuccess?.(res, req, meta); }, }); @@ -54,6 +57,9 @@ export function useRemoveBookmarkFromList( ...opts[0], onSuccess: (res, req, meta) => { apiUtils.bookmarks.getBookmarks.invalidate({ listId: req.listId }); + apiUtils.lists.getListsOfBookmark.invalidate({ + bookmarkId: req.bookmarkId, + }); return opts[0]?.onSuccess?.(res, req, meta); }, }); @@ -90,6 +96,7 @@ export function augmentBookmarkListsWithInitialData( data: ZBookmarkList[]; root: ZBookmarkListRoot; allPaths: ZBookmarkList[][]; + getPathById: (id: string) => ZBookmarkList[] | undefined; } | undefined, initialData: ZBookmarkList[], |
