Skip to content

Commit 073dbd7

Browse files
committed
feat(game): disable command input when not connected to the game
1 parent 127c80e commit 073dbd7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

electron/renderer/components/game/game-command-input.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import type {
66
ReactElement,
77
ReactNode,
88
} from 'react';
9-
import { useCallback, useMemo, useState } from 'react';
9+
import { useCallback, useContext, useMemo, useState } from 'react';
1010
import { isEmpty } from '../../../common/string/string.utils.js';
11+
import { GameContext } from '../../context/game.jsx';
1112
import { useCommandHistory } from '../../hooks/commands.jsx';
1213
import { runInBackground } from '../../lib/async/run-in-background.js';
1314

1415
export const GameCommandInput: React.FC = (): ReactNode => {
16+
const { isConnected } = useContext(GameContext);
1517
const { input, handleKeyDown, handleOnChange } = useCommandHistory();
1618
const [lastCommand, setLastCommand] = useState<string>();
1719

@@ -80,12 +82,13 @@ export const GameCommandInput: React.FC = (): ReactNode => {
8082
autoComplete="off"
8183
prepend={commandIcon}
8284
tabIndex={0}
85+
disabled={!isConnected}
8386
onKeyDown={onKeyDown}
8487
onChange={onChange}
8588
/>
8689
</div>
8790
);
88-
}, [input, commandIcon, onKeyDown, onChange]);
91+
}, [isConnected, input, commandIcon, onKeyDown, onChange]);
8992

9093
return commandInput;
9194
};

0 commit comments

Comments
 (0)