mirror of
https://github.com/cpvalente/ontime.git
synced 2026-07-26 10:38:55 +00:00
1849b4d39f
* chore: migrate eslint to oxlint * chore: migrate prettier to oxfmt * chore: migrate typescript * chore: toThrow should have a expected value * chore: cast test value as Day * chore: small title fix * chore: mocks should be hoisted * chore: incorrect async useage * chore: test should be inside description * chore: test sohuld include an expeced * chore: oxfmt --------- Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { MILLIS_PER_MINUTE } from 'ontime-utils';
|
|
import { useCallback, useEffect, useRef } from 'react';
|
|
import { createPortal } from 'react-dom';
|
|
|
|
import { setClientRemote } from '../../hooks/useSocket';
|
|
import { useClientStore } from '../../stores/clientStore';
|
|
|
|
import style from './IdentifyOverlay.module.scss';
|
|
|
|
export default function IdentifyOverlay() {
|
|
const clients = useClientStore((store) => store.clients);
|
|
const id = useClientStore((store) => store.id);
|
|
const showOverlay = clients[id]?.identify;
|
|
|
|
if (!showOverlay) {
|
|
return null;
|
|
}
|
|
|
|
const portalRoot = document.getElementById('identify-portal');
|
|
|
|
if (!portalRoot) {
|
|
return null;
|
|
}
|
|
return createPortal(<Overlay />, portalRoot);
|
|
}
|
|
|
|
function Overlay() {
|
|
const clients = useClientStore((store) => store.clients);
|
|
const id = useClientStore((store) => store.id);
|
|
const name = useClientStore((store) => store.name);
|
|
|
|
const timerRef = useRef<NodeJS.Timeout | null>(null);
|
|
|
|
const { setIdentify } = setClientRemote;
|
|
const showOverlay = clients[id]?.identify;
|
|
|
|
const handleClose = useCallback(() => {
|
|
if (timerRef.current) {
|
|
clearTimeout(timerRef.current);
|
|
}
|
|
|
|
setIdentify({ target: id, identify: false });
|
|
}, [id, setIdentify]);
|
|
|
|
// start a timer that will close the overlay after some time
|
|
useEffect(() => {
|
|
if (showOverlay) {
|
|
timerRef.current = setTimeout(handleClose, MILLIS_PER_MINUTE);
|
|
}
|
|
return () => {
|
|
if (timerRef.current) {
|
|
clearTimeout(timerRef.current);
|
|
}
|
|
};
|
|
}, [showOverlay, id, setIdentify, handleClose]);
|
|
|
|
return (
|
|
<div className={style.overlay} data-testid='identify-overlay' onClick={handleClose}>
|
|
<div className={style.name}>{name}</div>
|
|
<div className={style.message}>Click to close</div>
|
|
</div>
|
|
);
|
|
}
|