1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

Merge pull request #1055 from lmmelo16/dev

Fix #241: Last episode completed does not save
This commit is contained in:
Jorrin 2024-03-29 18:14:00 +01:00 committed by GitHub
commit c00bff5c7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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 {