corda-checkers/webapp/src/components/Game/GameSelector.jsx

42 lines
1.3 KiB
React
Raw Normal View History

2023-10-25 18:18:56 +02:00
import './GameSelector.css';
import React from 'react';
import { useLocation, matchPath } from "react-router";
import { AppData } from "../../context/data"
import { AppContext } from "../../context/app"
2023-10-25 18:18:56 +02:00
import Proposal from './GameSelector/GameProposal';
export default function GameSelector() {
2023-10-25 18:18:56 +02:00
const [data] = React.useContext(AppData)
const [ctx, dispatchCtx] = React.useContext(AppContext)
2023-10-25 18:18:56 +02:00
const { pathname } = useLocation();
const isProposalPath = matchPath("/game/proposal/*", pathname);
const isActivelPath = matchPath("/game/active/*", pathname);
const isArchivePath = matchPath("/game/archive/*", pathname);
console.log("GameSelector appCtx", ctx)
const onClick_proposal = (selectedGame) => {
dispatchCtx({ component: "game-selector", selectedGameProposal: selectedGame })
}
const onClick_active = (selectedGame) => {
dispatchCtx({ component: "game-selector", selectedActiveGame: selectedGame })
}
const onClick_archive = (selectedGame) => {
dispatchCtx({ component: "game-selector", selectedArchiveGame: selectedGame })
}
2023-10-25 18:18:56 +02:00
if (!data.games)
return <div>Loading..</div>
return (
<div className='game-selector'>
{isProposalPath && <Proposal games={data.games} onClick={onClick_proposal} />}
{isActivelPath && <div>TBD #1</div>}
{isArchivePath && <div>TBD #2</div>}
2023-10-25 18:18:56 +02:00
</div>
)
}