diff options
Diffstat (limited to 'packages/shared-react/hooks/bookmarks.ts')
| -rw-r--r-- | packages/shared-react/hooks/bookmarks.ts | 19 |
1 files changed, 19 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> ) { |
