From 51b73057990b6f93971e33a3082648e71928c527 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Tue, 24 Oct 2023 21:14:17 +0200 Subject: [PATCH] Fix bug where sometimes the wrong episode is played through episode selector --- src/components/player/hooks/usePlayer.ts | 11 ++++++++--- src/components/player/hooks/usePlayerMeta.ts | 17 +++++++++-------- src/stores/player/slices/source.ts | 5 +++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/components/player/hooks/usePlayer.ts b/src/components/player/hooks/usePlayer.ts index 86a34758..98cbb7a8 100644 --- a/src/components/player/hooks/usePlayer.ts +++ b/src/components/player/hooks/usePlayer.ts @@ -1,5 +1,9 @@ import { useInitializePlayer } from "@/components/player/hooks/useInitializePlayer"; -import { PlayerMeta, playerStatus } from "@/stores/player/slices/source"; +import { + PlayerMeta, + PlayerStatus, + playerStatus, +} from "@/stores/player/slices/source"; import { usePlayerStore } from "@/stores/player/store"; import { SourceSliceSource } from "@/stores/player/utils/qualities"; import { ProgressMediaItem, useProgressStore } from "@/stores/progress"; @@ -37,10 +41,11 @@ export function usePlayer() { const progressStore = useProgressStore(); return { + meta, reset, status, - setMeta(m: PlayerMeta) { - setMeta(m); + setMeta(m: PlayerMeta, newStatus?: PlayerStatus) { + setMeta(m, newStatus); }, playMedia(source: SourceSliceSource, sourceId: string | null) { setSource(source, getProgress(progressStore.items, meta)); diff --git a/src/components/player/hooks/usePlayerMeta.ts b/src/components/player/hooks/usePlayerMeta.ts index 5be2057c..c843bc9c 100644 --- a/src/components/player/hooks/usePlayerMeta.ts +++ b/src/components/player/hooks/usePlayerMeta.ts @@ -1,13 +1,16 @@ -import { useCallback, useMemo, useState } from "react"; +import { useCallback, useMemo } from "react"; import { DetailedMeta } from "@/backend/metadata/getmeta"; import { MWMediaType } from "@/backend/metadata/types/mw"; import { usePlayer } from "@/components/player/hooks/usePlayer"; -import { PlayerMeta, metaToScrapeMedia } from "@/stores/player/slices/source"; +import { + PlayerMeta, + metaToScrapeMedia, + playerStatus, +} from "@/stores/player/slices/source"; export function usePlayerMeta() { - const { setMeta, setScrapeStatus } = usePlayer(); - const [meta, _setPlayerMeta] = useState(null); + const { meta, setMeta } = usePlayer(); const scrapeMedia = useMemo( () => (meta ? metaToScrapeMedia(meta) : null), [meta] @@ -15,11 +18,9 @@ export function usePlayerMeta() { const setDirectMeta = useCallback( (m: PlayerMeta) => { - _setPlayerMeta(m); - setScrapeStatus(); - setMeta(m); + setMeta(m, playerStatus.SCRAPING); }, - [_setPlayerMeta, setMeta, setScrapeStatus] + [setMeta] ); const setPlayerMeta = useCallback( diff --git a/src/stores/player/slices/source.ts b/src/stores/player/slices/source.ts index 59522ae4..40ad3800 100644 --- a/src/stores/player/slices/source.ts +++ b/src/stores/player/slices/source.ts @@ -60,7 +60,7 @@ export interface SourceSlice { setStatus(status: PlayerStatus): void; setSource(stream: SourceSliceSource, startAt: number): void; switchQuality(quality: SourceQuality): void; - setMeta(meta: PlayerMeta): void; + setMeta(meta: PlayerMeta, status?: PlayerStatus): void; setCaption(caption: Caption | null): void; setSourceId(id: string | null): void; enableAutomaticQuality(): void; @@ -111,10 +111,11 @@ export const createSourceSlice: MakeSlice = (set, get) => ({ s.status = status; }); }, - setMeta(meta) { + setMeta(meta, newStatus) { set((s) => { s.meta = meta; s.interface.hideNextEpisodeBtn = false; + if (newStatus) s.status = newStatus; }); }, setCaption(caption) {