component params grouping
This commit is contained in:
parent
ac50d92c1a
commit
6b8b75ba7f
@ -26,14 +26,19 @@ export default function App() {
|
|||||||
const gamesApi = useGamesApi(dispatchGames);
|
const gamesApi = useGamesApi(dispatchGames);
|
||||||
gamesApi.list(pollingReducer);
|
gamesApi.list(pollingReducer);
|
||||||
|
|
||||||
|
const players = {
|
||||||
|
leaderboard,
|
||||||
|
isCurrentUser: (playerName) => user?.isCurrentUser(playerName) === true ? true : null
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Header pollingReducer={pollingReducer} />
|
<Header pollingReducer={pollingReducer} />
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path='/' element={<About />} />
|
<Route path='/' element={<About />} />
|
||||||
<Route path='/about' element={<About />} />
|
<Route path='/about' element={<About />} />
|
||||||
<Route path='/games/*' element={<Games games={games} dispatchGames={dispatchGames} gamesApi={gamesApi} />} />
|
<Route path='/games/*' element={<Games context={{ games, dispatchGames, gamesApi }} players={players} />} />
|
||||||
<Route path='/leaderboard' element={<Leaderboard leaderboard={leaderboard} user={user} />} />
|
<Route path='/leaderboard' element={<Leaderboard players={players} />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
)
|
)
|
||||||
|
@ -21,13 +21,13 @@ import GameBoard from './games/GameBoard';
|
|||||||
|
|
||||||
import { GamesContext, GamesDispatchContext, GamesApiContext } from '../context/games';
|
import { GamesContext, GamesDispatchContext, GamesApiContext } from '../context/games';
|
||||||
|
|
||||||
export default function Games({ games, dispatchGames, gamesApi }) {
|
export default function Games({ context }) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="Games">
|
<GamesContext.Provider value={context.games} >
|
||||||
<GamesContext.Provider value={games} >
|
<GamesDispatchContext.Provider value={context.dispatchGames} >
|
||||||
<GamesDispatchContext.Provider value={dispatchGames} >
|
<GamesApiContext.Provider value={context.gamesApi} >
|
||||||
<GamesApiContext.Provider value={gamesApi} >
|
<div className="Games">
|
||||||
<div className='left-side'>
|
<div className='left-side'>
|
||||||
<ViewSelector />
|
<ViewSelector />
|
||||||
<ViewProvider />
|
<ViewProvider />
|
||||||
@ -39,10 +39,10 @@ export default function Games({ games, dispatchGames, gamesApi }) {
|
|||||||
<GameMessage />
|
<GameMessage />
|
||||||
<Message2Opponent /> */}
|
<Message2Opponent /> */}
|
||||||
</div>
|
</div>
|
||||||
</GamesApiContext.Provider>
|
</div >
|
||||||
</GamesDispatchContext.Provider>
|
</GamesApiContext.Provider>
|
||||||
</GamesContext.Provider>
|
</GamesDispatchContext.Provider>
|
||||||
</div >
|
</GamesContext.Provider>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,18 +2,17 @@ import './Leaderboard.css';
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import Loading from '../components/Loading';
|
import Loading from '../components/Loading';
|
||||||
|
|
||||||
export default function Leaderboard({ leaderboard, user }) {
|
export default function Leaderboard({ players }) {
|
||||||
|
|
||||||
|
const leaderboard = players.leaderboard;
|
||||||
|
|
||||||
if (leaderboard == null)
|
if (leaderboard == null)
|
||||||
return <Loading />
|
return <Loading />
|
||||||
|
|
||||||
const isCurrentUser = (playerName) =>
|
|
||||||
user?.isCurrentUser(playerName) === true ? true : null;
|
|
||||||
|
|
||||||
const tableRows = Object.keys(leaderboard).map(playerName => {
|
const tableRows = Object.keys(leaderboard).map(playerName => {
|
||||||
var rank = leaderboard[playerName];
|
var rank = leaderboard[playerName];
|
||||||
|
|
||||||
return <tr key={playerName} className={isCurrentUser(playerName) && 'currentuser'}>
|
return <tr key={playerName} className={players.isCurrentUser(playerName) && 'currentuser'}>
|
||||||
<td>{playerName}</td>
|
<td>{playerName}</td>
|
||||||
<td>{rank.gamesPlayed}</td>
|
<td>{rank.gamesPlayed}</td>
|
||||||
<td>{rank.gamesWon}</td>
|
<td>{rank.gamesWon}</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user