Skip to content

Commit

Permalink
Switch for hiding cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
ecm85 committed Jun 29, 2024
1 parent 8179178 commit 58b8192
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion SpaceAlertResolver/UI/src/pages/CreateGame.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Skeleton } from '@mui/material';
import { FormControlLabel, FormGroup, Skeleton, Switch } from '@mui/material';
import Typography from '@mui/material/Typography';
import { useCallback, useEffect, useState } from 'react';
import { useStateRef, useWebSocket } from '~/hooks';
Expand All @@ -14,6 +14,7 @@ export function CreateGame() {
const [clients, setClients, clientsRef] = useStateRef<Client[]>([]);
const isLoading = !gameCode;
const { deserialize } = useSendToHostMessaging();
const [hideCards, setHideCards] = useState(true);

const handleMessage = useCallback(
(messageEventData: MessageEventData) => {
Expand Down Expand Up @@ -77,6 +78,12 @@ export function CreateGame() {
</div>
)}
</div>
<FormGroup>
<FormControlLabel
control={<Switch value={hideCards} onChange={() => setHideCards(!hideCards)} />}
label="Hide cards (reveal turn-by-turn)"
/>
</FormGroup>
{clients.length > 0 && (
<div>
<h3>Clients</h3>
Expand All @@ -89,6 +96,7 @@ export function CreateGame() {
<PlayerBoard
scannedCards={client.scannedCards}
playerColor={client.playerColor}
hideCards={hideCards}
/>
)}
</>
Expand Down
11 changes: 9 additions & 2 deletions SpaceAlertResolver/UI/src/pages/InputCards.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Typography } from '@mui/material';
import { Button, FormControlLabel, FormGroup, Switch, Typography } from '@mui/material';
import { MutableRefObject, useCallback, useState } from 'react';
import { BarcodeScanningWorkflow } from '~/components/BarcodeScanningWorkflow';
import { ColorPicker } from '~/components/ColorPicker';
Expand Down Expand Up @@ -27,6 +27,7 @@ export function InputCards({ gameCode, connectionRef }: InputCardsProps) {
const { parseBarcodes } = useScannedCards();
const [playerColor, setPlayerColor] = useState<PlayerColor | null>(null);
const { serialize } = useSendToHostMessaging();
const [hideCards, setHideCards] = useState(true);

const handleBarcodesScanned = (newBarcodes: DetectedBarcode[]) => {
const { scannedCards: newScannedCards, playerColor: newPlayerColor } =
Expand Down Expand Up @@ -96,7 +97,13 @@ export function InputCards({ gameCode, connectionRef }: InputCardsProps) {
{hasAlreadyScanned && (
<div className={styles['already-scanned']}>
<ColorPicker onPickColor={handleColorPicked} value={playerColor} />
<PlayerBoard scannedCards={scannedCards} playerColor={playerColor} />
<FormGroup>
<FormControlLabel
control={<Switch value={hideCards} onChange={() => setHideCards(!hideCards)} />}
label="Hide cards (reveal turn-by-turn)"
/>
</FormGroup>
<PlayerBoard scannedCards={scannedCards} playerColor={playerColor} hideCards />
<div>
{isSubscribed && workflowState === WorkflowState.Scanned && (
<Button onClick={handleSendToServerClicked} variant="contained">
Expand Down

0 comments on commit 58b8192

Please sign in to comment.