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 { 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;

View File

@ -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 {