mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-26 19:31:52 +01:00
Fix #241: Last episode completed does not save
After ending episode or clicking on next episode, store state wasn't updating. Changed NextEpisodeButton and which series episodes are displayed
This commit is contained in:
parent
21fd5304a1
commit
f4dd6f95a4
@ -7,6 +7,7 @@ import { usePlayerMeta } from "@/components/player/hooks/usePlayerMeta";
|
|||||||
import { Transition } from "@/components/utils/Transition";
|
import { Transition } from "@/components/utils/Transition";
|
||||||
import { PlayerMeta } from "@/stores/player/slices/source";
|
import { PlayerMeta } from "@/stores/player/slices/source";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
|
import { useProgressStore } from "@/stores/progress";
|
||||||
|
|
||||||
function shouldShowNextEpisodeButton(
|
function shouldShowNextEpisodeButton(
|
||||||
time: number,
|
time: number,
|
||||||
@ -55,6 +56,7 @@ export function NextEpisodeButton(props: {
|
|||||||
const setShouldStartFromBeginning = usePlayerStore(
|
const setShouldStartFromBeginning = usePlayerStore(
|
||||||
(s) => s.setShouldStartFromBeginning,
|
(s) => s.setShouldStartFromBeginning,
|
||||||
);
|
);
|
||||||
|
const updateItem = useProgressStore((s) => s.updateItem);
|
||||||
|
|
||||||
let show = false;
|
let show = false;
|
||||||
if (showingState === "always") show = true;
|
if (showingState === "always") show = true;
|
||||||
@ -79,7 +81,19 @@ export function NextEpisodeButton(props: {
|
|||||||
setShouldStartFromBeginning(true);
|
setShouldStartFromBeginning(true);
|
||||||
setDirectMeta(metaCopy);
|
setDirectMeta(metaCopy);
|
||||||
props.onChange?.(metaCopy);
|
props.onChange?.(metaCopy);
|
||||||
}, [setDirectMeta, nextEp, meta, props, setShouldStartFromBeginning]);
|
const defaultProgress = { duration: 0, watched: 0 };
|
||||||
|
updateItem({
|
||||||
|
meta: metaCopy,
|
||||||
|
progress: defaultProgress,
|
||||||
|
});
|
||||||
|
}, [
|
||||||
|
setDirectMeta,
|
||||||
|
nextEp,
|
||||||
|
meta,
|
||||||
|
props,
|
||||||
|
setShouldStartFromBeginning,
|
||||||
|
updateItem,
|
||||||
|
]);
|
||||||
|
|
||||||
if (!meta?.episode || !nextEp) return null;
|
if (!meta?.episode || !nextEp) return null;
|
||||||
if (metaType !== "show") return null;
|
if (metaType !== "show") return null;
|
||||||
|
@ -46,6 +46,15 @@ function progressIsAcceptableRange(duration: number, watched: number): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isFirstEpisodeOfShow(
|
||||||
|
item: ProgressMediaItem,
|
||||||
|
episode: ProgressEpisodeItem,
|
||||||
|
): boolean {
|
||||||
|
const seasonId = episode.seasonId;
|
||||||
|
const season = item.seasons[seasonId];
|
||||||
|
return season.number === 1 && episode.number === 1;
|
||||||
|
}
|
||||||
|
|
||||||
export function shouldShowProgress(
|
export function shouldShowProgress(
|
||||||
item: ProgressMediaItem,
|
item: ProgressMediaItem,
|
||||||
): ShowProgressResult {
|
): ShowProgressResult {
|
||||||
@ -66,8 +75,10 @@ export function shouldShowProgress(
|
|||||||
.sort((a, b) => b.updatedAt - a.updatedAt)
|
.sort((a, b) => b.updatedAt - a.updatedAt)
|
||||||
.filter(
|
.filter(
|
||||||
(epi) =>
|
(epi) =>
|
||||||
!progressIsNotStarted(epi.progress.duration, epi.progress.watched),
|
!progressIsNotStarted(epi.progress.duration, epi.progress.watched) ||
|
||||||
|
!isFirstEpisodeOfShow(item, epi),
|
||||||
)[0];
|
)[0];
|
||||||
|
|
||||||
const season = item.seasons[ep?.seasonId];
|
const season = item.seasons[ep?.seasonId];
|
||||||
if (!ep || !season)
|
if (!ep || !season)
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user