diff --git a/asc/src/App.js b/asc/src/App.js index f06a689..7f60fac 100644 --- a/asc/src/App.js +++ b/asc/src/App.js @@ -1,17 +1,77 @@ -// File: src/App.js -import React from 'react'; -import { ScoreProvider } from './context/ScoreContext'; -import AppRouter from './AppRouter'; -import { ThemeProvider } from './context/ThemeContext'; +import React, { useState, useMemo, useEffect } from 'react'; +import { CssBaseline, Container, IconButton } from '@mui/material'; +import { ThemeProvider, createTheme } from '@mui/material/styles'; // <-- Import createTheme +import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; +import { ScoreProvider } from './context/ScoreContext'; // <-- Import ScoreProvider + +import MainMenu from './components/MainMenu'; +import GameSetup from './components/GameSetup'; +import ScoreTracker from './components/ScoreTracker'; +import GameSummary from './components/GameSummary'; +import { Brightness7, Brightness4 } from '@mui/icons-material'; function App() { + const [mode, setMode] = useState(() => { + try { + const savedMode = localStorage.getItem('themeMode'); + return savedMode || 'light'; + } catch (e) { + return 'light'; + } + }); + + // Save theme preference to localStorage + useEffect(() => { + localStorage.setItem('themeMode', mode); + }, [mode]); + + const theme = useMemo( + () => + createTheme({ + palette: { + mode, + }, + }), + [mode], + ); + + const toggleTheme = () => { + setMode((prevMode) => (prevMode === 'light' ? 'dark' : 'light')); + }; + return ( - + - + + + + {mode === 'dark' ? : } + + + + } /> {/* MainMenu as the default page */} + } /> + } /> + } /> + + + ); } export default App; + diff --git a/asc/src/components/GameSetup.js b/asc/src/components/GameSetup.js index 6b3d568..be0f4e1 100644 --- a/asc/src/components/GameSetup.js +++ b/asc/src/components/GameSetup.js @@ -1,4 +1,3 @@ -// src/components/GameSetup.js import React from 'react'; import { Button, @@ -15,8 +14,8 @@ const GameSetup = ({ onGameStart }) => { const startGame = (gameType) => { dispatch({ - type: ACTIONS.START_NEW_ROUND, - payload: { gameType } + type: ACTIONS.START_GAME, + payload: { gameType, isLeague: false } }); onGameStart(); }; diff --git a/asc/src/components/MainMenu.js b/asc/src/components/MainMenu.js index ea15976..7d456eb 100644 --- a/asc/src/components/MainMenu.js +++ b/asc/src/components/MainMenu.js @@ -7,16 +7,18 @@ const MainMenu = () => { const navigate = useNavigate(); const { dispatch } = useScore(); - const handleGameStart = (gameType, isLeague) => { - dispatch({ - type: ACTIONS.START_GAME, - payload: { - gameType: gameType, - isLeague: isLeague - } - }); - navigate('/game'); - }; + // Start the game and navigate directly to the score tracker +const handleGameStart = (gameType, isLeague) => { + dispatch({ + type: ACTIONS.START_NEW_ROUND, + payload: { + gameType, + isLeague // Pass the league or practice mode + }, + }); + navigate('/score-tracker'); // Jump to score tracker +}; + return ( { + + - - {/* ... rest of your JSX ... */} + + + {gameType} Round - Round {state.currentGame.rounds.length + 1} + + + {isLeague ? 'League Game' : 'Practice Game'} {/* Display whether it's a league or practice game */} + - + + {/* Score input section */} + + + {Array.from({ length: maxArrowsPerRound }).map((_, index) => ( + handleScoreChange(index, e.target.value)} + placeholder="0" + size="small" + sx={{ + width: '60px', + '& .MuiInputBase-input': { + padding: '8px', + textAlign: 'center' + } + }} + inputProps={{ + maxLength: 1, + style: { textAlign: 'center' } + }} + /> + ))} + + + + {/* Score buttons */} + + + {Array.from({ length: maxScore + 1 }).map((_, i) => ( + + ))} + + + + + {/* Control buttons */} + + + + + + + + {/* Scores display */} + + + Total Score: {state.currentGame.totalScore} | + Bullseyes: {state.currentGame.totalBullseyes} + + + + {/* Round history */} + + + {state.currentGame.rounds.length > 0 ? ( + state.currentGame.rounds.map((round, roundIndex) => ( + + Round {roundIndex + 1}: {round.arrows.map(arrow => arrow.score).join(', ')} + (Total: {round.total}, Bullseyes: {round.bullseyes}) + + )) + ) : ( + + No rounds played yet. + + )} + + + ); }; export default ScoreTracker; + diff --git a/asc/src/context/ScoreContext.js b/asc/src/context/ScoreContext.js index 57c4779..f76a545 100644 --- a/asc/src/context/ScoreContext.js +++ b/asc/src/context/ScoreContext.js @@ -22,22 +22,24 @@ const initialState = { const scoreReducer = (state, action) => { switch (action.type) { - case ACTIONS.START_GAME: + case ACTIONS.START_NEW_ROUND: return { ...state, currentGame: { - ...initialState.currentGame, gameType: action.payload.gameType, isLeague: action.payload.isLeague, - date: new Date().toISOString() - } + rounds: [], + totalScore: 0, + totalBullseyes: 0, + dateStarted: new Date().toISOString(), + }, }; - + case ACTIONS.ADD_ROUND: const updatedRounds = [...state.currentGame.rounds]; updatedRounds[action.payload.roundIndex] = { arrows: action.payload.arrows, - total: action.payload.arrows.reduce((sum, arrow) => sum + arrow.score, 0), + total: action.payload.total, bullseyes: action.payload.arrows.filter(arrow => arrow.isBullseye).length }; @@ -51,7 +53,7 @@ const scoreReducer = (state, action) => { rounds: updatedRounds, totalScore, totalBullseyes - } + }, }; case ACTIONS.SAVE_GAME: