From c9e546400042e2203b7c82c9ed5e2a4e635b07f4 Mon Sep 17 00:00:00 2001 From: zimplexing Date: Tue, 8 Jul 2025 22:07:20 +0800 Subject: [PATCH] Implement toggle functionality for intro and outro time settings with user feedback --- stores/playerStore.ts | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/stores/playerStore.ts b/stores/playerStore.ts index 6793017..6db5007 100644 --- a/stores/playerStore.ts +++ b/stores/playerStore.ts @@ -188,11 +188,22 @@ const usePlayerStore = create((set, get) => ({ }, setIntroEndTime: () => { - const { status, detail } = get(); - if (status?.isLoaded && detail) { - const introEndTime = status.positionMillis; - set({ introEndTime }); - get()._savePlayRecord({ introEndTime }); + const { status, detail, introEndTime: existingIntroEndTime } = get(); + if (!status?.isLoaded || !detail) return; + + if (existingIntroEndTime) { + // Clear the time + set({ introEndTime: undefined }); + get()._savePlayRecord({ introEndTime: undefined }); + Toast.show({ + type: "info", + text1: "已清除片头时间", + }); + } else { + // Set the time + const newIntroEndTime = status.positionMillis; + set({ introEndTime: newIntroEndTime }); + get()._savePlayRecord({ introEndTime: newIntroEndTime }); Toast.show({ type: "success", text1: "设置成功", @@ -202,11 +213,22 @@ const usePlayerStore = create((set, get) => ({ }, setOutroStartTime: () => { - const { status, detail } = get(); - if (status?.isLoaded && detail) { - const outroStartTime = status.positionMillis; - set({ outroStartTime }); - get()._savePlayRecord({ outroStartTime }); + const { status, detail, outroStartTime: existingOutroStartTime } = get(); + if (!status?.isLoaded || !detail) return; + + if (existingOutroStartTime) { + // Clear the time + set({ outroStartTime: undefined }); + get()._savePlayRecord({ outroStartTime: undefined }); + Toast.show({ + type: "info", + text1: "已清除片尾时间", + }); + } else { + // Set the time + const newOutroStartTime = status.positionMillis; + set({ outroStartTime: newOutroStartTime }); + get()._savePlayRecord({ outroStartTime: newOutroStartTime }); Toast.show({ type: "success", text1: "设置成功",