mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-13 10:35:08 +01:00
only make new save item if difference
This commit is contained in:
parent
0094261aec
commit
b38e5768e3
@ -3,7 +3,7 @@ import { useInterval } from "react-use";
|
|||||||
|
|
||||||
import { playerStatus } from "@/stores/player/slices/source";
|
import { playerStatus } from "@/stores/player/slices/source";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
import { useProgressStore } from "@/stores/progress";
|
import { ProgressItem, useProgressStore } from "@/stores/progress";
|
||||||
|
|
||||||
export function ProgressSaver() {
|
export function ProgressSaver() {
|
||||||
const meta = usePlayerStore((s) => s.meta);
|
const meta = usePlayerStore((s) => s.meta);
|
||||||
@ -12,6 +12,8 @@ export function ProgressSaver() {
|
|||||||
const status = usePlayerStore((s) => s.status);
|
const status = usePlayerStore((s) => s.status);
|
||||||
const hasPlayedOnce = usePlayerStore((s) => s.mediaPlaying.hasPlayedOnce);
|
const hasPlayedOnce = usePlayerStore((s) => s.mediaPlaying.hasPlayedOnce);
|
||||||
|
|
||||||
|
const lastSavedRef = useRef<ProgressItem | null>(null);
|
||||||
|
|
||||||
const dataRef = useRef({
|
const dataRef = useRef({
|
||||||
updateItem,
|
updateItem,
|
||||||
meta,
|
meta,
|
||||||
@ -32,13 +34,24 @@ export function ProgressSaver() {
|
|||||||
if (!d.progress || !d.meta || !d.updateItem) return;
|
if (!d.progress || !d.meta || !d.updateItem) return;
|
||||||
if (d.status !== playerStatus.PLAYING) return;
|
if (d.status !== playerStatus.PLAYING) return;
|
||||||
if (!hasPlayedOnce) return;
|
if (!hasPlayedOnce) return;
|
||||||
d.updateItem({
|
|
||||||
meta: d.meta,
|
let isDifferent = false;
|
||||||
progress: {
|
if (!lastSavedRef.current) isDifferent = true;
|
||||||
duration: progress.duration,
|
else if (
|
||||||
watched: progress.time,
|
lastSavedRef.current?.duration !== progress.duration ||
|
||||||
},
|
lastSavedRef.current?.watched !== progress.time
|
||||||
});
|
)
|
||||||
|
isDifferent = true;
|
||||||
|
|
||||||
|
lastSavedRef.current = {
|
||||||
|
duration: progress.duration,
|
||||||
|
watched: progress.time,
|
||||||
|
};
|
||||||
|
if (isDifferent)
|
||||||
|
d.updateItem({
|
||||||
|
meta: d.meta,
|
||||||
|
progress: lastSavedRef.current,
|
||||||
|
});
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user