mirror of
https://github.com/sussy-code/smov.git
synced 2025-01-01 16:37:39 +01:00
Merge pull request #1055 from lmmelo16/dev
Fix #241: Last episode completed does not save
This commit is contained in:
commit
c00bff5c7c
2 changed files with 27 additions and 2 deletions
|
@ -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 a new issue