Prevent terminal on game keys

Disable opening the terminal with the "/" shortcut while on game pages, by using useLocation to detect /games paths and adding isOnGamePage guard to the keydown handler. Also added location-based check to avoid triggering when navigating in-game.

X-Lovable-Edit-ID: edt-ac92b015-c278-4c1a-81eb-778385ddc5aa
This commit is contained in:
gpt-engineer-app[bot]
2026-01-10 23:17:48 +00:00
+8 -4
View File
@@ -1,5 +1,5 @@
import { useState, useRef, useEffect } from 'react'; import { useState, useRef, useEffect } from 'react';
import { useNavigate } from 'react-router-dom'; import { useNavigate, useLocation } from 'react-router-dom';
import { motion, AnimatePresence } from 'framer-motion'; import { motion, AnimatePresence } from 'framer-motion';
import { Terminal, X } from 'lucide-react'; import { Terminal, X } from 'lucide-react';
import { useSettings } from '@/contexts/SettingsContext'; import { useSettings } from '@/contexts/SettingsContext';
@@ -70,9 +70,13 @@ const TerminalCommand = () => {
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
const outputRef = useRef<HTMLDivElement>(null); const outputRef = useRef<HTMLDivElement>(null);
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation();
const { playSound } = useSettings(); const { playSound } = useSettings();
const { unlockAchievement } = useAchievements(); const { unlockAchievement } = useAchievements();
// Check if user is on a game page
const isOnGamePage = location.pathname.startsWith('/games/');
useEffect(() => { useEffect(() => {
if (isOpen && inputRef.current) { if (isOpen && inputRef.current) {
inputRef.current.focus(); inputRef.current.focus();
@@ -98,8 +102,8 @@ const TerminalCommand = () => {
playSound('beep'); playSound('beep');
} }
// Open terminal when pressing "/" (only if not in input) // Open terminal when pressing "/" (only if not in input and not on a game page)
if (e.key === '/' && !isOpen && !isInputFocused) { if (e.key === '/' && !isOpen && !isInputFocused && !isOnGamePage) {
e.preventDefault(); e.preventDefault();
setIsOpen(true); setIsOpen(true);
playSound('beep'); playSound('beep');
@@ -114,7 +118,7 @@ const TerminalCommand = () => {
window.addEventListener('keydown', handleKeyDown); window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown);
}, [isOpen, playSound]); }, [isOpen, playSound, isOnGamePage]);
const handleSubmit = (e: React.FormEvent) => { const handleSubmit = (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();