aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared-react/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'packages/shared-react/hooks')
-rw-r--r--packages/shared-react/hooks/bookmarks.ts19
-rw-r--r--packages/shared-react/hooks/lists.ts7
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[],