mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
Fix bug where sometimes the wrong episode is played through episode selector
This commit is contained in:
parent
f30161fb1c
commit
51b7305799
3 changed files with 20 additions and 13 deletions
|
@ -1,5 +1,9 @@
|
||||||
import { useInitializePlayer } from "@/components/player/hooks/useInitializePlayer";
|
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 { usePlayerStore } from "@/stores/player/store";
|
||||||
import { SourceSliceSource } from "@/stores/player/utils/qualities";
|
import { SourceSliceSource } from "@/stores/player/utils/qualities";
|
||||||
import { ProgressMediaItem, useProgressStore } from "@/stores/progress";
|
import { ProgressMediaItem, useProgressStore } from "@/stores/progress";
|
||||||
|
@ -37,10 +41,11 @@ export function usePlayer() {
|
||||||
const progressStore = useProgressStore();
|
const progressStore = useProgressStore();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
meta,
|
||||||
reset,
|
reset,
|
||||||
status,
|
status,
|
||||||
setMeta(m: PlayerMeta) {
|
setMeta(m: PlayerMeta, newStatus?: PlayerStatus) {
|
||||||
setMeta(m);
|
setMeta(m, newStatus);
|
||||||
},
|
},
|
||||||
playMedia(source: SourceSliceSource, sourceId: string | null) {
|
playMedia(source: SourceSliceSource, sourceId: string | null) {
|
||||||
setSource(source, getProgress(progressStore.items, meta));
|
setSource(source, getProgress(progressStore.items, meta));
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo } from "react";
|
||||||
|
|
||||||
import { DetailedMeta } from "@/backend/metadata/getmeta";
|
import { DetailedMeta } from "@/backend/metadata/getmeta";
|
||||||
import { MWMediaType } from "@/backend/metadata/types/mw";
|
import { MWMediaType } from "@/backend/metadata/types/mw";
|
||||||
import { usePlayer } from "@/components/player/hooks/usePlayer";
|
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() {
|
export function usePlayerMeta() {
|
||||||
const { setMeta, setScrapeStatus } = usePlayer();
|
const { meta, setMeta } = usePlayer();
|
||||||
const [meta, _setPlayerMeta] = useState<PlayerMeta | null>(null);
|
|
||||||
const scrapeMedia = useMemo(
|
const scrapeMedia = useMemo(
|
||||||
() => (meta ? metaToScrapeMedia(meta) : null),
|
() => (meta ? metaToScrapeMedia(meta) : null),
|
||||||
[meta]
|
[meta]
|
||||||
|
@ -15,11 +18,9 @@ export function usePlayerMeta() {
|
||||||
|
|
||||||
const setDirectMeta = useCallback(
|
const setDirectMeta = useCallback(
|
||||||
(m: PlayerMeta) => {
|
(m: PlayerMeta) => {
|
||||||
_setPlayerMeta(m);
|
setMeta(m, playerStatus.SCRAPING);
|
||||||
setScrapeStatus();
|
|
||||||
setMeta(m);
|
|
||||||
},
|
},
|
||||||
[_setPlayerMeta, setMeta, setScrapeStatus]
|
[setMeta]
|
||||||
);
|
);
|
||||||
|
|
||||||
const setPlayerMeta = useCallback(
|
const setPlayerMeta = useCallback(
|
||||||
|
|
|
@ -60,7 +60,7 @@ export interface SourceSlice {
|
||||||
setStatus(status: PlayerStatus): void;
|
setStatus(status: PlayerStatus): void;
|
||||||
setSource(stream: SourceSliceSource, startAt: number): void;
|
setSource(stream: SourceSliceSource, startAt: number): void;
|
||||||
switchQuality(quality: SourceQuality): void;
|
switchQuality(quality: SourceQuality): void;
|
||||||
setMeta(meta: PlayerMeta): void;
|
setMeta(meta: PlayerMeta, status?: PlayerStatus): void;
|
||||||
setCaption(caption: Caption | null): void;
|
setCaption(caption: Caption | null): void;
|
||||||
setSourceId(id: string | null): void;
|
setSourceId(id: string | null): void;
|
||||||
enableAutomaticQuality(): void;
|
enableAutomaticQuality(): void;
|
||||||
|
@ -111,10 +111,11 @@ export const createSourceSlice: MakeSlice<SourceSlice> = (set, get) => ({
|
||||||
s.status = status;
|
s.status = status;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setMeta(meta) {
|
setMeta(meta, newStatus) {
|
||||||
set((s) => {
|
set((s) => {
|
||||||
s.meta = meta;
|
s.meta = meta;
|
||||||
s.interface.hideNextEpisodeBtn = false;
|
s.interface.hideNextEpisodeBtn = false;
|
||||||
|
if (newStatus) s.status = newStatus;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setCaption(caption) {
|
setCaption(caption) {
|
||||||
|
|
Loading…
Reference in a new issue