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:
Joao Melo 2024-03-25 17:59:11 +00:00
parent 21fd5304a1
commit f4dd6f95a4
2 changed files with 27 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import { usePlayerMeta } from "@/components/player/hooks/usePlayerMeta";
import { Transition } from "@/components/utils/Transition";
import { PlayerMeta } from "@/stores/player/slices/source";
import { usePlayerStore } from "@/stores/player/store";
import { useProgressStore } from "@/stores/progress";
function shouldShowNextEpisodeButton(
time: number,
@ -55,6 +56,7 @@ export function NextEpisodeButton(props: {
const setShouldStartFromBeginning = usePlayerStore(
(s) => s.setShouldStartFromBeginning,
);
const updateItem = useProgressStore((s) => s.updateItem);
let show = false;
if (showingState === "always") show = true;
@ -79,7 +81,19 @@ export function NextEpisodeButton(props: {
setShouldStartFromBeginning(true);
setDirectMeta(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 (metaType !== "show") return null;

View File

@ -46,6 +46,15 @@ function progressIsAcceptableRange(duration: number, watched: number): boolean {
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(
item: ProgressMediaItem,
): ShowProgressResult {
@ -66,8 +75,10 @@ export function shouldShowProgress(
.sort((a, b) => b.updatedAt - a.updatedAt)
.filter(
(epi) =>
!progressIsNotStarted(epi.progress.duration, epi.progress.watched),
!progressIsNotStarted(epi.progress.duration, epi.progress.watched) ||
!isFirstEpisodeOfShow(item, epi),
)[0];
const season = item.seasons[ep?.seasonId];
if (!ep || !season)
return {