mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-04-23 17:24:42 +01:00
fix(tv): modals
This commit is contained in:
36
hooks/useTVOptionModal.ts
Normal file
36
hooks/useTVOptionModal.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
|
||||
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,
|
||||
});
|
||||
router.push("/(auth)/tv-option-modal");
|
||||
},
|
||||
[router],
|
||||
);
|
||||
|
||||
return { showOptions };
|
||||
};
|
||||
40
hooks/useTVSubtitleModal.ts
Normal file
40
hooks/useTVSubtitleModal.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type {
|
||||
BaseItemDto,
|
||||
MediaStream,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useCallback } from "react";
|
||||
import useRouter from "@/hooks/useAppRouter";
|
||||
import { tvSubtitleModalAtom } from "@/utils/atoms/tvSubtitleModal";
|
||||
import { store } from "@/utils/store";
|
||||
|
||||
interface ShowSubtitleModalParams {
|
||||
item: BaseItemDto;
|
||||
mediaSourceId?: string | null;
|
||||
subtitleTracks: MediaStream[];
|
||||
currentSubtitleIndex: number;
|
||||
onSubtitleIndexChange: (index: number) => void;
|
||||
onServerSubtitleDownloaded?: () => void;
|
||||
onLocalSubtitleDownloaded?: (path: string) => void;
|
||||
}
|
||||
|
||||
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,
|
||||
onSubtitleIndexChange: params.onSubtitleIndexChange,
|
||||
onServerSubtitleDownloaded: params.onServerSubtitleDownloaded,
|
||||
onLocalSubtitleDownloaded: params.onLocalSubtitleDownloaded,
|
||||
});
|
||||
router.push("/(auth)/tv-subtitle-modal");
|
||||
},
|
||||
[router],
|
||||
);
|
||||
|
||||
return { showSubtitleModal };
|
||||
};
|
||||
Reference in New Issue
Block a user