mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-03-17 23:06:20 +00:00
refactor: Feature/offline mode rework (#859)
Co-authored-by: lostb1t <coding-mosses0z@icloud.com> Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com> Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com> Co-authored-by: Gauvino <uruknarb20@gmail.com> Co-authored-by: storm1er <le.storm1er@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Chris <182387676+whoopsi-daisy@users.noreply.github.com> Co-authored-by: arch-fan <55891793+arch-fan@users.noreply.github.com> Co-authored-by: Alex Kim <alexkim@Alexs-MacBook-Pro.local>
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useDownload } from "@/providers/DownloadProvider";
|
||||
import { useTwoWaySync } from "./useTwoWaySync";
|
||||
|
||||
/**
|
||||
* useRevalidatePlaybackProgressCache invalidates queries related to playback progress.
|
||||
*/
|
||||
export function useInvalidatePlaybackProgressCache() {
|
||||
const queryClient = useQueryClient();
|
||||
const { getDownloadedItems } = useDownload();
|
||||
const { syncPlaybackState } = useTwoWaySync();
|
||||
|
||||
const revalidate = async () => {
|
||||
// List of all the queries to invalidate
|
||||
@@ -17,11 +21,34 @@ export function useInvalidatePlaybackProgressCache() {
|
||||
["episodes"],
|
||||
["seasons"],
|
||||
["home"],
|
||||
["downloadedItems"],
|
||||
];
|
||||
|
||||
// Invalidate each query
|
||||
for (const queryKey of queriesToInvalidate) {
|
||||
await queryClient.invalidateQueries({ queryKey });
|
||||
// We Invalidate all the queries to the latest server versions
|
||||
await Promise.all(
|
||||
queriesToInvalidate.map((queryKey) =>
|
||||
queryClient.invalidateQueries({ queryKey }),
|
||||
),
|
||||
);
|
||||
|
||||
const downloadedFiles = getDownloadedItems();
|
||||
// Sync playback state for downloaded items
|
||||
if (downloadedFiles) {
|
||||
// We sync the playback state for the downloaded items
|
||||
const syncResults = await Promise.all(
|
||||
downloadedFiles.map((downloadedItem) =>
|
||||
syncPlaybackState(downloadedItem.item.Id!),
|
||||
),
|
||||
);
|
||||
// We invalidate the queries again in case we have updated a server's playback progress.
|
||||
const shouldInvalidate = syncResults.some((result) => result);
|
||||
|
||||
console.log("shouldInvalidate", shouldInvalidate);
|
||||
if (shouldInvalidate) {
|
||||
queriesToInvalidate.map((queryKey) =>
|
||||
queryClient.invalidateQueries({ queryKey }),
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user