From 8015ec5a92a2c1c36dd9c798fcef8467b7e9a851 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 6 Dec 2023 21:06:46 +0100 Subject: [PATCH] Reset caption specific settings Co-authored-by: William Oldham --- src/components/player/hooks/useCaptions.ts | 6 +++++- src/stores/subtitles/index.ts | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/player/hooks/useCaptions.ts b/src/components/player/hooks/useCaptions.ts index 522b22be..ec99c4fb 100644 --- a/src/components/player/hooks/useCaptions.ts +++ b/src/components/player/hooks/useCaptions.ts @@ -7,6 +7,9 @@ import { useSubtitleStore } from "@/stores/subtitles"; export function useCaptions() { const setLanguage = useSubtitleStore((s) => s.setLanguage); const enabled = useSubtitleStore((s) => s.enabled); + const resetSubtitleSpecificSettings = useSubtitleStore( + (s) => s.resetSubtitleSpecificSettings + ); const setCaption = usePlayerStore((s) => s.setCaption); const lastSelectedLanguage = useSubtitleStore((s) => s.lastSelectedLanguage); const captionList = usePlayerStore((s) => s.captionList); @@ -21,9 +24,10 @@ export function useCaptions() { srtData, url: caption.url, }); + resetSubtitleSpecificSettings(); setLanguage(language); }, - [setLanguage, captionList, setCaption] + [setLanguage, captionList, setCaption, resetSubtitleSpecificSettings] ); const disable = useCallback(async () => { diff --git a/src/stores/subtitles/index.ts b/src/stores/subtitles/index.ts index 1652ee93..1a461b3e 100644 --- a/src/stores/subtitles/index.ts +++ b/src/stores/subtitles/index.ts @@ -34,6 +34,7 @@ export interface SubtitleStore { setOverrideCasing(enabled: boolean): void; setDelay(delay: number): void; importSubtitleLanguage(lang: string | null): void; + resetSubtitleSpecificSettings(): void; } export const useSubtitleStore = create( @@ -51,6 +52,12 @@ export const useSubtitleStore = create( backgroundOpacity: 0.5, size: 1, }, + resetSubtitleSpecificSettings() { + set((s) => { + s.delay = 0; + s.overrideCasing = false; + }); + }, updateStyling(newStyling) { set((s) => { if (newStyling.backgroundOpacity !== undefined)