diff --git a/src/components/player/atoms/settings/CaptionsView.tsx b/src/components/player/atoms/settings/CaptionsView.tsx index 9129326c..1872e361 100644 --- a/src/components/player/atoms/settings/CaptionsView.tsx +++ b/src/components/player/atoms/settings/CaptionsView.tsx @@ -713,6 +713,7 @@ export function CaptionsView({ selected={ (!currentTranslateTask && selectedLanguage === language) || (!!currentTranslateTask && + !currentTranslateTask.error && currentTranslateTask.targetCaption.language === language) } rightText={captionsForLang.length.toString()} diff --git a/src/components/player/atoms/settings/LanguageSubtitlesView.tsx b/src/components/player/atoms/settings/LanguageSubtitlesView.tsx index 1e51b8b0..09de7d02 100644 --- a/src/components/player/atoms/settings/LanguageSubtitlesView.tsx +++ b/src/components/player/atoms/settings/LanguageSubtitlesView.tsx @@ -127,14 +127,21 @@ export function LanguageSubtitlesView({ countryCode={v.language} selected={ v.id === selectedCaptionId || - v.id === currentTranslateTask?.targetCaption?.id + (!!currentTranslateTask && + !currentTranslateTask.error && + v.id === currentTranslateTask.targetCaption.id) + } + disabled={ + !!currentTranslateTask && + !currentTranslateTask.done && + !currentTranslateTask.error } - disabled={!!currentTranslateTask && !currentTranslateTask.done} loading={ (v.id === currentlyDownloading && downloadReq.loading) || (!!currentTranslateTask && v.id === currentTranslateTask.targetCaption.id && - !currentTranslateTask.done) + !currentTranslateTask.done && + !currentTranslateTask.error) } error={ v.id === currentlyDownloading && downloadReq.error @@ -142,7 +149,9 @@ export function LanguageSubtitlesView({ : undefined } onClick={() => - (!currentTranslateTask || currentTranslateTask.done) && + (!currentTranslateTask || + currentTranslateTask.done || + currentTranslateTask.error) && startDownload(v.id) } onTranslate={() => { @@ -153,7 +162,11 @@ export function LanguageSubtitlesView({ : "/captionsOverlay/translateSubtitleOverlay", ); }} - isTranslatedTarget={v.id === currentTranslateTask?.targetCaption?.id} + isTranslatedTarget={ + !!currentTranslateTask && + !currentTranslateTask.error && + v.id === currentTranslateTask.targetCaption.id + } onDoubleClick={handleDoubleClick} flag translatable diff --git a/src/components/player/atoms/settings/TranslateSubtitleView.tsx b/src/components/player/atoms/settings/TranslateSubtitleView.tsx index b515adfe..62223141 100644 --- a/src/components/player/atoms/settings/TranslateSubtitleView.tsx +++ b/src/components/player/atoms/settings/TranslateSubtitleView.tsx @@ -84,7 +84,7 @@ export function TranslateSubtitleView({ }: LanguageSubtitlesViewProps) { const { t } = useTranslation(); const router = useOverlayRouter(id); - const { setDirectCaption } = useCaptions(); + const { setDirectCaption, disable: disableCaptions } = useCaptions(); const translateTask = usePlayerStore((s) => s.caption.translateTask); const translateCaption = usePlayerStore((s) => s.translateCaption); const clearTranslateTask = usePlayerStore((s) => s.clearTranslateTask); @@ -109,6 +109,7 @@ export function TranslateSubtitleView({ async function onClick() { clearTranslateTask(); + disableCaptions(); await translateCaption(caption, langCode); } diff --git a/src/components/player/hooks/useCaptions.ts b/src/components/player/hooks/useCaptions.ts index 199c05b8..7d51475c 100644 --- a/src/components/player/hooks/useCaptions.ts +++ b/src/components/player/hooks/useCaptions.ts @@ -19,7 +19,6 @@ export function useCaptions() { (s) => s.resetSubtitleSpecificSettings, ); const setCaption = usePlayerStore((s) => s.setCaption); - const clearTranslateTask = usePlayerStore((s) => s.clearTranslateTask); const currentTranslateTask = usePlayerStore((s) => s.caption.translateTask); const lastSelectedLanguage = useSubtitleStore((s) => s.lastSelectedLanguage); const setIsOpenSubtitles = useSubtitleStore((s) => s.setIsOpenSubtitles); @@ -119,16 +118,9 @@ export function useCaptions() { captionToSet.srtData = srtData; } - clearTranslateTask(); setDirectCaption(captionToSet, caption); }, - [ - captions, - getSubtitleTracks, - setSubtitlePreference, - setDirectCaption, - clearTranslateTask, - ], + [captions, getSubtitleTracks, setSubtitlePreference, setDirectCaption], ); const selectLanguage = useCallback( @@ -141,11 +133,10 @@ export function useCaptions() { ); const disable = useCallback(async () => { - clearTranslateTask(); setIsOpenSubtitles(false); setCaption(null); setLanguage(null); - }, [setCaption, setLanguage, setIsOpenSubtitles, clearTranslateTask]); + }, [setCaption, setLanguage, setIsOpenSubtitles]); const selectLastUsedLanguage = useCallback(async () => { const language = lastSelectedLanguage ?? "en"; @@ -226,7 +217,6 @@ export function useCaptions() { selectCaptionById(sameLanguageCaption.id); } else { // No caption with the same language found, clear the selection - clearTranslateTask(); setCaption(null); } } @@ -235,7 +225,6 @@ export function useCaptions() { selectedCaption, setCaption, selectCaptionById, - clearTranslateTask, currentTranslateTask, ]); diff --git a/src/stores/player/slices/source.ts b/src/stores/player/slices/source.ts index 3d435e9f..911e0853 100644 --- a/src/stores/player/slices/source.ts +++ b/src/stores/player/slices/source.ts @@ -238,6 +238,14 @@ export const createSourceSlice: MakeSlice = (set, get) => ({ setCaption(caption) { const store = get(); store.display?.setCaption(caption); + if ( + !caption || + (store.caption.translateTask && + store.caption.translateTask.targetCaption.id !== caption?.id && + store.caption.translateTask.translatedCaption?.id !== caption?.id) + ) { + store.clearTranslateTask(); + } set((s) => { s.caption.selected = caption; });