mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 15:48:05 +00:00
fix: refresh data on open page in background replace cached data
This commit is contained in:
21
utils/query/networkAwareInvalidate.ts
Normal file
21
utils/query/networkAwareInvalidate.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
type InvalidateOptions,
|
||||
type InvalidateQueryFilters,
|
||||
onlineManager,
|
||||
type QueryClient,
|
||||
} from "@tanstack/react-query";
|
||||
|
||||
/**
|
||||
* Invalidates queries only when online. When offline, the invalidation
|
||||
* is skipped to preserve cached data for offline use.
|
||||
*/
|
||||
export function invalidateQueriesWhenOnline(
|
||||
queryClient: QueryClient,
|
||||
filters: InvalidateQueryFilters,
|
||||
options?: InvalidateOptions,
|
||||
): Promise<void> {
|
||||
if (!onlineManager.isOnline()) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return queryClient.invalidateQueries(filters, options);
|
||||
}
|
||||
Reference in New Issue
Block a user