Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions services/app/src/pages/game/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ const Game = () => {
const { currentPlayer, lastTurn, removeFigureFromBoard, isAnotherSessionActive } = useChessBoardContext();

const [showAvatarModal, setShowAvatarModal] = useState(false);
const [isInGame, setIsInGame] = useState(true);

useEffect(() => {
let timeoutId;

const handleVisibilityChange = () => {
if (document.hidden) {
timeoutId = setTimeout(() => {
setIsInGame(false)
}, 5 * 60 * 1000);
} else {
clearTimeout(timeoutId);
}
};

document.addEventListener('visibilitychange', handleVisibilityChange);

return () => {
document.removeEventListener('visibilitychange', handleVisibilityChange);
clearTimeout(timeoutId);
};
}, []);


const connectToWs = useCallback(() => {
openWsConnection({
Expand Down Expand Up @@ -68,6 +91,7 @@ const Game = () => {
return (
<div className='page-layout'>
{isAnotherSessionActive && <Navigate to={ROUTES.userTaken} />}
{!isInGame && <Navigate to={ROUTES.error} />}
<AvatarUploadModal
isOpen={showAvatarModal}
onClose={() => setShowAvatarModal(false)}
Expand Down