mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 23:59:08 +00:00
chore: refactor
This commit is contained in:
56
components/video-player/controls/useControlsTimeout.ts
Normal file
56
components/video-player/controls/useControlsTimeout.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
interface UseControlsTimeoutProps {
|
||||
showControls: boolean;
|
||||
isSliding: boolean;
|
||||
episodeView: boolean;
|
||||
onHideControls: () => void;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export const useControlsTimeout = ({
|
||||
showControls,
|
||||
isSliding,
|
||||
episodeView,
|
||||
onHideControls,
|
||||
timeout = 4000,
|
||||
}: UseControlsTimeoutProps) => {
|
||||
const controlsTimeoutRef = useRef<NodeJS.Timeout>();
|
||||
|
||||
useEffect(() => {
|
||||
const resetControlsTimeout = () => {
|
||||
if (controlsTimeoutRef.current) {
|
||||
clearTimeout(controlsTimeoutRef.current);
|
||||
}
|
||||
|
||||
if (showControls && !isSliding && !episodeView) {
|
||||
controlsTimeoutRef.current = setTimeout(() => {
|
||||
onHideControls();
|
||||
}, timeout);
|
||||
}
|
||||
};
|
||||
|
||||
resetControlsTimeout();
|
||||
|
||||
return () => {
|
||||
if (controlsTimeoutRef.current) {
|
||||
clearTimeout(controlsTimeoutRef.current);
|
||||
}
|
||||
};
|
||||
}, [showControls, isSliding, episodeView, timeout, onHideControls]);
|
||||
|
||||
const handleControlsInteraction = () => {
|
||||
if (showControls) {
|
||||
if (controlsTimeoutRef.current) {
|
||||
clearTimeout(controlsTimeoutRef.current);
|
||||
}
|
||||
controlsTimeoutRef.current = setTimeout(() => {
|
||||
onHideControls();
|
||||
}, timeout);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
handleControlsInteraction,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user