mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Do not try to update watchstatus if the user is not connected
This commit is contained in:
parent
e13f2a7e42
commit
fbc8e14125
@ -18,7 +18,7 @@
|
|||||||
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { WatchStatusV, queryFn } from "@kyoo/models";
|
import { WatchStatusV, queryFn, useAccount } from "@kyoo/models";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useEffect, useCallback } from "react";
|
import { useEffect, useCallback } from "react";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
@ -32,6 +32,7 @@ export const WatchStatusObserver = ({
|
|||||||
type: "episode" | "movie";
|
type: "episode" | "movie";
|
||||||
slug: string;
|
slug: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
const account = useAccount();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { mutate } = useMutation({
|
const { mutate } = useMutation({
|
||||||
mutationFn: (seconds: number) =>
|
mutationFn: (seconds: number) =>
|
||||||
@ -56,6 +57,7 @@ export const WatchStatusObserver = ({
|
|||||||
|
|
||||||
// update watch status every 10 seconds and on unmount.
|
// update watch status every 10 seconds and on unmount.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!account) return;
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
mutate(readProgress());
|
mutate(readProgress());
|
||||||
}, 10_000);
|
}, 10_000);
|
||||||
@ -63,12 +65,13 @@ export const WatchStatusObserver = ({
|
|||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
mutate(readProgress());
|
mutate(readProgress());
|
||||||
};
|
};
|
||||||
}, [type, slug, readProgress, mutate]);
|
}, [account, type, slug, readProgress, mutate]);
|
||||||
|
|
||||||
// update watch status when play status change (and on mount).
|
// update watch status when play status change (and on mount).
|
||||||
const isPlaying = useAtomValue(playAtom);
|
const isPlaying = useAtomValue(playAtom);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!account) return;
|
||||||
mutate(readProgress());
|
mutate(readProgress());
|
||||||
}, [type, slug, isPlaying, readProgress, mutate]);
|
}, [account, type, slug, isPlaying, readProgress, mutate]);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user