p-stream/src/video/components/controllers/SeriesController.tsx
Yılmaz ÇABUK 4880d46dc4 style: sort imports according to ESLint rules
This commit updates the import statements in the codebase to comply with ESLint rules for import ordering. All imports have been sorted alphabetically and grouped according to the specified import groups in the ESLint configuration. This improves the codebase's consistency and maintainability.
2023-04-24 18:41:54 +03:00

43 lines
1.2 KiB
TypeScript

import { useEffect, useRef } from "react";
import { useHistory } from "react-router-dom";
import { useVideoPlayerDescriptor } from "@/video/state/hooks";
import { useMeta } from "@/video/state/logic/meta";
interface SeriesControllerProps {
onSelect?: (state: { episodeId?: string; seasonId?: string }) => void;
}
export function SeriesController(props: SeriesControllerProps) {
const descriptor = useVideoPlayerDescriptor();
const meta = useMeta(descriptor);
const history = useHistory();
const lastState = useRef<{
episodeId?: string;
seasonId?: string;
} | null>(null);
useEffect(() => {
const currentState = {
episodeId: meta?.episode?.episodeId,
seasonId: meta?.episode?.seasonId,
};
if (lastState.current === null) {
if (!meta) return;
lastState.current = currentState;
return;
}
// when changes are detected, trigger event handler
if (
currentState.episodeId !== lastState.current?.episodeId ||
currentState.seasonId !== lastState.current?.seasonId
) {
lastState.current = currentState;
props.onSelect?.(currentState);
}
}, [meta, props, history]);
return null;
}