From 8e8a0b5d992bbcc76de0093c5fc13d6b3ccd6755 Mon Sep 17 00:00:00 2001 From: cocos02 Date: Fri, 12 Jun 2026 13:34:05 +0800 Subject: [PATCH] fix: chapter list follows JSON order, remember last selected chapter --- src/components/StoryGallery.vue | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/components/StoryGallery.vue b/src/components/StoryGallery.vue index ed8a705..2d694aa 100644 --- a/src/components/StoryGallery.vue +++ b/src/components/StoryGallery.vue @@ -109,31 +109,19 @@ function endingStatus(endingId: string) { return props.visitedIds.has(props.endings.find(e => e.id === endingId)?.sceneId ?? '') } -function chaptersByProgress() { - return [...props.chapters].sort((a, b) => { - const pa = chapterProgress(a.id).pct - const pb = chapterProgress(b.id).pct - return pb - pa - }) +function resolveInitialChapter(): string { + const saved = localStorage.getItem('story_chapter') + if (saved && props.chapters.some(c => c.id === saved)) return saved + const first = props.chapters[0] + return first?.id ?? '' } -const defaultChapter = computed(() => { - const sorted = chaptersByProgress() - for (const ch of sorted) { - if (chapterProgress(ch.id).pct > 0) return ch - } - return sorted[0] ?? null -}) - -const currentChapterId = ref('') - -if (defaultChapter.value) { - currentChapterId.value = defaultChapter.value.id -} +const currentChapterId = ref(resolveInitialChapter()) function selectChapter(chapterId: string) { if (!props.unlockedChapterIds.has(chapterId)) return currentChapterId.value = chapterId + localStorage.setItem('story_chapter', chapterId) showChapterPicker.value = false } @@ -256,7 +244,7 @@ const tree = computed(() => buildTreeForChapter(currentChapterId.value))