From 6ced24e4d1fee90b130fa56a397f845283965d0c Mon Sep 17 00:00:00 2001 From: Tachibana Shin Date: Sun, 7 May 2023 17:01:52 +0000 Subject: [PATCH] auto restore last ep --- src/pages/phim/_season.vue | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/pages/phim/_season.vue b/src/pages/phim/_season.vue index cabfd12a..dd23d4e2 100644 --- a/src/pages/phim/_season.vue +++ b/src/pages/phim/_season.vue @@ -1016,6 +1016,33 @@ const currentMetaChap = computed(() => { (item) => item.id === currentChap.value ) }) +watch( + currentSeason, + (_, __, onCleanup) => { + // replace router if last episode viewing exists + const watcherRestoreLastEp = watchPostEffect(() => { + const episodeIdFirst = currentDataSeason.value?.chaps[0].id + + if ( + !route.params.chap && + currentChap.value && + currentChap.value !== episodeIdFirst && + currentMetaChap.value + ) { + if (import.meta.env.DEV) + console.log("%c Redirect to suspend path", "color: green") + router.replace({ + path: `/phim/${route.params.season}/${currentChap.value}`, + query: route.query, + hash: route.hash, + }) + watcherRestoreLastEp() + } + }) + onCleanup(watcherRestoreLastEp) + }, + { immediate: true } +) const nextChap = computed< | {