mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-11 17:55:33 +00:00
Fix translated caption not applying when menu is closed
This commit is contained in:
parent
44618524dd
commit
5539061ae4
2 changed files with 21 additions and 18 deletions
|
|
@ -2,6 +2,7 @@ import { useEffect } from "react";
|
||||||
|
|
||||||
import { Icons } from "@/components/Icon";
|
import { Icons } from "@/components/Icon";
|
||||||
import { OverlayAnchor } from "@/components/overlays/OverlayAnchor";
|
import { OverlayAnchor } from "@/components/overlays/OverlayAnchor";
|
||||||
|
import { useCaptions } from "@/components/player/hooks/useCaptions";
|
||||||
import { VideoPlayerButton } from "@/components/player/internals/Button";
|
import { VideoPlayerButton } from "@/components/player/internals/Button";
|
||||||
import { useOverlayRouter } from "@/hooks/useOverlayRouter";
|
import { useOverlayRouter } from "@/hooks/useOverlayRouter";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
|
|
@ -9,11 +10,28 @@ import { usePlayerStore } from "@/stores/player/store";
|
||||||
export function Captions() {
|
export function Captions() {
|
||||||
const router = useOverlayRouter("settings");
|
const router = useOverlayRouter("settings");
|
||||||
const setHasOpenOverlay = usePlayerStore((s) => s.setHasOpenOverlay);
|
const setHasOpenOverlay = usePlayerStore((s) => s.setHasOpenOverlay);
|
||||||
|
const { setDirectCaption } = useCaptions();
|
||||||
|
const translateTask = usePlayerStore((s) => s.caption.translateTask);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setHasOpenOverlay(router.isRouterActive);
|
setHasOpenOverlay(router.isRouterActive);
|
||||||
}, [setHasOpenOverlay, router.isRouterActive]);
|
}, [setHasOpenOverlay, router.isRouterActive]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!translateTask) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (translateTask.done) {
|
||||||
|
const tCaption = translateTask.translatedCaption!;
|
||||||
|
setDirectCaption(tCaption, {
|
||||||
|
id: tCaption.id,
|
||||||
|
url: "",
|
||||||
|
language: tCaption.language,
|
||||||
|
needsProxy: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [translateTask, setDirectCaption]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<OverlayAnchor id={router.id}>
|
<OverlayAnchor id={router.id}>
|
||||||
<VideoPlayerButton
|
<VideoPlayerButton
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ const availableLanguages: string[] = [
|
||||||
"cy",
|
"cy",
|
||||||
];
|
];
|
||||||
|
|
||||||
export interface LanguageSubtitlesViewProps {
|
export interface TranslateSubtitlesViewProps {
|
||||||
id: string;
|
id: string;
|
||||||
caption: CaptionListItem;
|
caption: CaptionListItem;
|
||||||
overlayBackLink?: boolean;
|
overlayBackLink?: boolean;
|
||||||
|
|
@ -81,29 +81,14 @@ export function TranslateSubtitleView({
|
||||||
id,
|
id,
|
||||||
caption,
|
caption,
|
||||||
overlayBackLink,
|
overlayBackLink,
|
||||||
}: LanguageSubtitlesViewProps) {
|
}: TranslateSubtitlesViewProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const router = useOverlayRouter(id);
|
const router = useOverlayRouter(id);
|
||||||
const { setDirectCaption, disable: disableCaptions } = useCaptions();
|
const { disable: disableCaptions } = useCaptions();
|
||||||
const translateTask = usePlayerStore((s) => s.caption.translateTask);
|
const translateTask = usePlayerStore((s) => s.caption.translateTask);
|
||||||
const translateCaption = usePlayerStore((s) => s.translateCaption);
|
const translateCaption = usePlayerStore((s) => s.translateCaption);
|
||||||
const clearTranslateTask = usePlayerStore((s) => s.clearTranslateTask);
|
const clearTranslateTask = usePlayerStore((s) => s.clearTranslateTask);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!translateTask) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (translateTask.done) {
|
|
||||||
const tCaption = translateTask.translatedCaption!;
|
|
||||||
setDirectCaption(tCaption, {
|
|
||||||
id: tCaption.id,
|
|
||||||
url: "",
|
|
||||||
language: tCaption.language,
|
|
||||||
needsProxy: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [translateTask, setDirectCaption]);
|
|
||||||
|
|
||||||
function renderTargetLang(langCode: string) {
|
function renderTargetLang(langCode: string) {
|
||||||
const friendlyName = getPrettyLanguageNameFromLocale(langCode);
|
const friendlyName = getPrettyLanguageNameFromLocale(langCode);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue