Files
streamyfin/hooks/useTVOptionModal.ts
Gauvain 03ae18e3c0 fix(tv): only defer option-modal selection when it navigates
The close-first + runAfterInteractions change (needed so the in-player audio
switch's replacePlayer isn't swallowed by the modal route) also runs for every
other tv-option-modal caller — detail-page audio, library filters, settings —
whose onSelect only updates state. Deferring those until after dismissal
re-renders the page after focus returns and yanks TV focus, leaving navigation
stuck. Gate the deferral behind deferApplyUntilDismissed (set only by the
in-player audio caller); everyone else applies before closing, as before.
2026-07-07 00:36:31 +02:00

39 lines
1012 B
TypeScript

import { useCallback } from "react";
import useRouter from "@/hooks/useAppRouter";
import {
type TVOptionItem,
tvOptionModalAtom,
} from "@/utils/atoms/tvOptionModal";
import { store } from "@/utils/store";
interface ShowOptionsParams<T> {
title: string;
options: TVOptionItem<T>[];
onSelect: (value: T) => void;
cardWidth?: number;
cardHeight?: number;
deferApplyUntilDismissed?: boolean;
}
export const useTVOptionModal = () => {
const router = useRouter();
const showOptions = useCallback(
<T>(params: ShowOptionsParams<T>) => {
// Use store.set for synchronous update before navigation
store.set(tvOptionModalAtom, {
title: params.title,
options: params.options,
onSelect: params.onSelect,
cardWidth: params.cardWidth,
cardHeight: params.cardHeight,
deferApplyUntilDismissed: params.deferApplyUntilDismissed,
});
router.push("/(auth)/tv-option-modal");
},
[router],
);
return { showOptions };
};