From 3735cdc4cd7dad875d592382804603191103d78e Mon Sep 17 00:00:00 2001 From: aaronshiel Date: Mon, 7 Oct 2024 22:55:37 -0700 Subject: [PATCH] disabled controls --- client/src/components/video-player.tsx | 14 ++++++- client/src/hooks/controls-disable-helper.tsx | 39 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 client/src/hooks/controls-disable-helper.tsx diff --git a/client/src/components/video-player.tsx b/client/src/components/video-player.tsx index f6d1dbc1..e15cfad6 100644 --- a/client/src/components/video-player.tsx +++ b/client/src/components/video-player.tsx @@ -23,6 +23,7 @@ import { useWithVideoPlayerHeight } from "use-with-video-player-height"; import { useWithScreenOrientation } from "use-with-orientation"; import { useSelector } from "react-redux"; import { getUtterance } from "api"; +import { controlsDisableHelper } from "hooks/controls-disable-helper"; export interface VideoPlayerData { videoUrl: string; @@ -88,6 +89,7 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element { getUtterance(state.mentorsById[state.curMentor], UtteranceName.INTRO) ); const [introEnded, setIntroEnded] = useState(false); + const { enabled: controlsEnabled, interacted } = controlsDisableHelper(); useEffect(() => { if (isIntro && videoUrl) { @@ -356,14 +358,23 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element {
{ + interacted(); + }} + onClick={() => { + interacted(); + }} + onMouseMove={() => { + interacted(); + }} > - {/* TODO: shouldDisplayWebLinks && !isIdle */} {shouldDiplayWebLinks ? answerLinkCard : null} {mentorName ? mentorNameCard : null} void; +} + +export function controlsDisableHelper(): ControlsDisableHelper { + const [enabled, setEnabled] = useState(false); + const [lastInteractionTime, setLastInteractionTime] = useState(Date.now()); + + useInterval( + () => { + if (Date.now() - lastInteractionTime > 3000) { + setEnabled(false); + } + }, + enabled ? 1000 : null + ); + + function interacted() { + setLastInteractionTime(Date.now()); + if (!enabled) { + setEnabled(true); + } + } + + return { + enabled, + interacted, + }; +}