mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-07-07 04:53:01 +01:00
The close-first + runAfterInteractions pattern is needed only in the player, where selecting a subtitle can navigate (replacePlayer for a burn-in switch while transcoding). On the item detail page the selection just updates state, so deferring it until after the modal is dismissed re-renders the page after focus returns and yanks TV focus — leaving navigation stuck. Gate the deferral behind deferApplyUntilDismissed (set by the in-player caller only); the detail page runs the selection before closing, preserving focus.
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
|
import { useCallback } from "react";
|
|
import type { Track } from "@/components/video-player/controls/types";
|
|
import useRouter from "@/hooks/useAppRouter";
|
|
import { tvSubtitleModalAtom } from "@/utils/atoms/tvSubtitleModal";
|
|
import { store } from "@/utils/store";
|
|
|
|
interface ShowSubtitleModalParams {
|
|
item: BaseItemDto;
|
|
mediaSourceId?: string | null;
|
|
subtitleTracks: Track[];
|
|
currentSubtitleIndex: number;
|
|
onDisableSubtitles?: () => void;
|
|
onServerSubtitleDownloaded?: () => void;
|
|
onLocalSubtitleDownloaded?: (path: string) => void;
|
|
refreshSubtitleTracks?: () => Promise<Track[]>;
|
|
deferApplyUntilDismissed?: boolean;
|
|
}
|
|
|
|
export const useTVSubtitleModal = () => {
|
|
const router = useRouter();
|
|
|
|
const showSubtitleModal = useCallback(
|
|
(params: ShowSubtitleModalParams) => {
|
|
store.set(tvSubtitleModalAtom, {
|
|
item: params.item,
|
|
mediaSourceId: params.mediaSourceId,
|
|
subtitleTracks: params.subtitleTracks,
|
|
currentSubtitleIndex: params.currentSubtitleIndex,
|
|
onDisableSubtitles: params.onDisableSubtitles,
|
|
onServerSubtitleDownloaded: params.onServerSubtitleDownloaded,
|
|
onLocalSubtitleDownloaded: params.onLocalSubtitleDownloaded,
|
|
refreshSubtitleTracks: params.refreshSubtitleTracks,
|
|
deferApplyUntilDismissed: params.deferApplyUntilDismissed,
|
|
});
|
|
router.push("/(auth)/tv-subtitle-modal");
|
|
},
|
|
[router],
|
|
);
|
|
|
|
return { showSubtitleModal };
|
|
};
|