Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix(mobile): prevent pagination from cancelling refetches

Mohamed Bassemf4efff997942
diff --git a/apps/mobile/app.config.js b/apps/mobile/app.config.js
index 2903e252..095a51a0 100644
--- a/apps/mobile/app.config.js
+++ b/apps/mobile/app.config.js
@@ -47,7 +47,7 @@ export default {
NSAllowsArbitraryLoads: true,
},
},
- buildNumber: "46",
+ buildNumber: "47",
},
android: {
adaptiveIcon: {
@@ -68,7 +68,7 @@ export default {
package: IS_DEV
? "app.hoarder.hoardermobile.dev"
: "app.hoarder.hoardermobile",
- versionCode: 46,
+ versionCode: 47,
},
plugins: [
"./plugins/trust-local-certs.js",
diff --git a/apps/mobile/app/dashboard/(tabs)/(highlights)/index.tsx b/apps/mobile/app/dashboard/(tabs)/(highlights)/index.tsx
index 21b94f03..ca8c0057 100644
--- a/apps/mobile/app/dashboard/(tabs)/(highlights)/index.tsx
+++ b/apps/mobile/app/dashboard/(tabs)/(highlights)/index.tsx
@@ -13,6 +13,8 @@ export default function Highlights() {
isPlaceholderData,
error,
fetchNextPage,
+ hasNextPage,
+ isFetching,
isFetchingNextPage,
refetch,
} = useInfiniteQuery(
@@ -33,11 +35,18 @@ export default function Highlights() {
queryClient.invalidateQueries(api.highlights.getAll.pathFilter());
};
+ const onEndReached = () => {
+ if (!hasNextPage || isFetching) {
+ return;
+ }
+ void fetchNextPage({ cancelRefetch: false });
+ };
+
return (
<HighlightList
highlights={data.pages.flatMap((p) => p.highlights)}
onRefresh={onRefresh}
- fetchNextPage={fetchNextPage}
+ fetchNextPage={onEndReached}
isFetchingNextPage={isFetchingNextPage}
isRefreshing={isPending || isPlaceholderData}
/>
diff --git a/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx b/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
index 66c81c43..bb1a9a82 100644
--- a/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
+++ b/apps/mobile/app/dashboard/(tabs)/(tags)/index.tsx
@@ -45,6 +45,7 @@ export default function Tags() {
refetch,
fetchNextPage,
hasNextPage,
+ isFetching,
isFetchingNextPage,
} = usePaginatedSearchTags({
limit: 50,
@@ -72,8 +73,8 @@ export default function Tags() {
}));
const handleLoadMore = () => {
- if (hasNextPage && !isFetchingNextPage) {
- fetchNextPage();
+ if (hasNextPage && !isFetching) {
+ void fetchNextPage({ cancelRefetch: false });
}
};
diff --git a/apps/mobile/components/bookmarks/UpdatingBookmarkList.tsx b/apps/mobile/components/bookmarks/UpdatingBookmarkList.tsx
index df95a93d..20100803 100644
--- a/apps/mobile/components/bookmarks/UpdatingBookmarkList.tsx
+++ b/apps/mobile/components/bookmarks/UpdatingBookmarkList.tsx
@@ -24,6 +24,8 @@ export default function UpdatingBookmarkList({
isPlaceholderData,
error,
fetchNextPage,
+ hasNextPage,
+ isFetching,
isFetchingNextPage,
refetch,
} = useInfiniteQuery(
@@ -50,6 +52,13 @@ export default function UpdatingBookmarkList({
queryClient.invalidateQueries(api.bookmarks.getBookmark.pathFilter());
};
+ const onEndReached = () => {
+ if (!hasNextPage || isFetching) {
+ return;
+ }
+ void fetchNextPage({ cancelRefetch: false });
+ };
+
return (
<BookmarkList
bookmarks={data.pages
@@ -57,7 +66,7 @@ export default function UpdatingBookmarkList({
.filter((b) => b.content.type != BookmarkTypes.UNKNOWN)}
header={header}
onRefresh={onRefresh}
- fetchNextPage={fetchNextPage}
+ fetchNextPage={onEndReached}
isFetchingNextPage={isFetchingNextPage}
isRefreshing={isPending || isPlaceholderData}
/>
diff --git a/apps/mobile/components/search/BookmarkSearchResults.tsx b/apps/mobile/components/search/BookmarkSearchResults.tsx
index 8658ca57..c5f6289a 100644
--- a/apps/mobile/components/search/BookmarkSearchResults.tsx
+++ b/apps/mobile/components/search/BookmarkSearchResults.tsx
@@ -27,7 +27,7 @@ export default function BookmarkSearchResults({
error,
refetch,
isPending,
- fetchNextPage,
+ onEndReached,
isFetchingNextPage,
onRefresh,
} = state;
@@ -80,7 +80,7 @@ export default function BookmarkSearchResults({
return (
<BookmarkList
bookmarks={data.pages.flatMap((p) => p.bookmarks)}
- fetchNextPage={fetchNextPage}
+ fetchNextPage={onEndReached}
isFetchingNextPage={isFetchingNextPage}
onRefresh={onRefresh}
isRefreshing={isPending}
diff --git a/apps/mobile/lib/useBookmarkSearchState.ts b/apps/mobile/lib/useBookmarkSearchState.ts
index 0300eae4..e7d415f5 100644
--- a/apps/mobile/lib/useBookmarkSearchState.ts
+++ b/apps/mobile/lib/useBookmarkSearchState.ts
@@ -41,19 +41,34 @@ export function useBookmarkSearchState(rawSearch: string) {
queryClient.invalidateQueries(api.bookmarks.searchBookmarks.pathFilter());
};
- const { data, error, refetch, isPending, fetchNextPage, isFetchingNextPage } =
- useInfiniteQuery(
- api.bookmarks.searchBookmarks.infiniteQueryOptions(
- { text: query, searchMode: effectiveSearchMode },
- {
- enabled: query.trim().length > 0,
- placeholderData: keepPreviousData,
- gcTime: 0,
- initialCursor: null,
- getNextPageParam: (lastPage) => lastPage.nextCursor,
- },
- ),
- );
+ const {
+ data,
+ error,
+ refetch,
+ isPending,
+ fetchNextPage,
+ hasNextPage,
+ isFetching,
+ isFetchingNextPage,
+ } = useInfiniteQuery(
+ api.bookmarks.searchBookmarks.infiniteQueryOptions(
+ { text: query, searchMode: effectiveSearchMode },
+ {
+ enabled: query.trim().length > 0,
+ placeholderData: keepPreviousData,
+ gcTime: 0,
+ initialCursor: null,
+ getNextPageParam: (lastPage) => lastPage.nextCursor,
+ },
+ ),
+ );
+
+ const onEndReached = () => {
+ if (!hasNextPage || isFetching) {
+ return;
+ }
+ void fetchNextPage({ cancelRefetch: false });
+ };
const filteredHistory = useMemo(() => {
if (rawSearch.trim().length === 0) {
@@ -85,7 +100,7 @@ export function useBookmarkSearchState(rawSearch: string) {
error,
refetch,
isPending,
- fetchNextPage,
+ onEndReached,
isFetchingNextPage,
onRefresh,
};