pstream is dead; long live pstream taciturnaxolotl.github.io/pstream-ng/
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve caption selection logic

Pas 94921e58 d88feda4

+32 -7
+25 -1
src/components/player/hooks/useCaptions.ts
··· 1 - import { useCallback, useMemo } from "react"; 1 + import { useCallback, useEffect, useMemo } from "react"; 2 2 import subsrt from "subsrt-ts"; 3 3 4 4 import { downloadCaption, downloadWebVTT } from "@/backend/helpers/subs"; ··· 175 175 // Select the random caption 176 176 await selectCaptionById(randomCaption.id); 177 177 }, [lastSelectedLanguage, captions, selectedCaption, selectCaptionById]); 178 + 179 + // Validate selected caption when caption list changes 180 + useEffect(() => { 181 + if (!selectedCaption) return; 182 + 183 + const isSelectedCaptionStillAvailable = captions.some( 184 + (caption) => caption.id === selectedCaption.id, 185 + ); 186 + 187 + if (!isSelectedCaptionStillAvailable) { 188 + // Try to find a caption with the same language 189 + const sameLanguageCaption = captions.find( 190 + (caption) => caption.language === selectedCaption.language, 191 + ); 192 + 193 + if (sameLanguageCaption) { 194 + // Automatically select the first caption with the same language 195 + selectCaptionById(sameLanguageCaption.id); 196 + } else { 197 + // No caption with the same language found, clear the selection 198 + setCaption(null); 199 + } 200 + } 201 + }, [captions, selectedCaption, setCaption, selectCaptionById]); 178 202 179 203 return { 180 204 selectLanguage,
+7 -6
src/components/player/hooks/useInitializePlayer.ts
··· 26 26 ); 27 27 const { selectLastUsedLanguageIfEnabled } = useCaptions(); 28 28 29 - const funRef = useRef(selectLastUsedLanguageIfEnabled); 30 - useEffect(() => { 31 - funRef.current = selectLastUsedLanguageIfEnabled; 32 - }, [selectLastUsedLanguageIfEnabled]); 29 + // Only select subtitles on initial load, not when source changes 30 + const hasInitializedRef = useRef(false); 33 31 34 32 useEffect(() => { 35 - if (sourceIdentifier) funRef.current(); 36 - }, [sourceIdentifier]); 33 + if (sourceIdentifier && !hasInitializedRef.current) { 34 + hasInitializedRef.current = true; 35 + selectLastUsedLanguageIfEnabled(); 36 + } 37 + }, [sourceIdentifier, selectLastUsedLanguageIfEnabled]); 37 38 }