front: GameHeader: add New gameView

- GameActions for each GameView
- activate GameAction per relevan GameView
This commit is contained in:
djmil 2023-10-27 12:34:58 +02:00
parent 1ea6d22286
commit 21dd37521b
11 changed files with 99 additions and 25 deletions

View File

@ -16,6 +16,7 @@ function App() {
<Routes> <Routes>
{/* https://stackoverflow.com/questions/40541994/multiple-path-names-for-a-same-component-in-react-router */} {/* https://stackoverflow.com/questions/40541994/multiple-path-names-for-a-same-component-in-react-router */}
<Route path="/game" element={<Game/>} /> <Route path="/game" element={<Game/>} />
<Route path="/game/new" element={<Game/>} />
<Route path="/game/proposal" element={<Game/>} /> <Route path="/game/proposal" element={<Game/>} />
<Route path="/game/active" element={<Game/>} /> <Route path="/game/active" element={<Game/>} />
<Route path="/game/archive" element={<Game/>} /> <Route path="/game/archive" element={<Game/>} />

View File

@ -1,24 +1,45 @@
import './GameAction.css'; import './GameAction.css';
import React from 'react'; import React from 'react';
import { useLocation, matchPath } from "react-router";
import Create from './GameAction/Create';
import Reject from './GameAction/Reject';
import Cancel from './GameAction/Cancel';
import Accept from './GameAction/Accept';
import DrawReq from './GameAction/DrawReq';
import DrawAcq from './GameAction/DrawAcq';
import Surrender from './GameAction/Surrender';
import Backward from './GameAction/Backward';
import Forward from './GameAction/Forward';
import Create from './GameAction/Create'
import Reject from './GameAction/Reject'
import Cancel from './GameAction/Cancel'
import Accept from './GameAction/Accept'
// import { AppContext } from '../../context/app' // import { AppContext } from '../../context/app'
export default function GameAction() { export default function GameAction() {
// const [ctx, dispatchCtx] = React.useContext(AppContext) // const [ctx, dispatchCtx] = React.useContext(AppContext)
const { pathname } = useLocation();
const isNewGamePath = matchPath("/game/new", pathname);
const isProposalPath = matchPath("/game/proposal/*", pathname);
const isActivelPath = matchPath("/game/active/*", pathname);
const isArchivePath = matchPath("/game/archive/*", pathname);
return ( return (
<div> <div className='action-panel'>
<div className='action-panel'> {isNewGamePath && <Create />}
<Create />
<Reject /> {isProposalPath && <Reject />}
<Cancel /> {isProposalPath && <Cancel />}
<Accept /> {isProposalPath && <Accept />}
</div>
{/* {isProposalPath && <Proposal games={data.games} />} */} {isActivelPath && <DrawReq />}
{isActivelPath && <DrawAcq />}
{isActivelPath && <Surrender />}
{isArchivePath && <Backward />}
{isArchivePath && <Forward />}
</div> </div>
) )
} }

View File

@ -0,0 +1,6 @@
import React from 'react';
export default function Backward() {
return <button className='game-action backward'>Backward</button>
}

View File

@ -0,0 +1,6 @@
import React from 'react';
export default function DrawAcq() {
return <button className='game-action draw-acq'>Draw acquire</button>
}

View File

@ -0,0 +1,6 @@
import React from 'react';
export default function DrawReq() {
return <button className='game-action drawreq'>Draw request</button>
}

View File

@ -0,0 +1,6 @@
import React from 'react';
export default function Forward() {
return <button className='game-action forward'>Forward</button>
}

View File

@ -0,0 +1,6 @@
import React from 'react';
export default function Surrender() {
return <button className='game-action surrender'>Surrender</button>
}

View File

@ -6,6 +6,7 @@ export default function GameHeader() {
return ( return (
<nav className='game-header'> <nav className='game-header'>
<NavLink to="/game/new">New</NavLink>
<NavLink to="/game/proposal">Proposal</NavLink> <NavLink to="/game/proposal">Proposal</NavLink>
<NavLink to="/game/active">Active</NavLink> <NavLink to="/game/active">Active</NavLink>
<NavLink to="/game/archive">Archive</NavLink> <NavLink to="/game/archive">Archive</NavLink>

View File

View File

@ -0,0 +1,21 @@
import './NewGame.css';
import React from 'react';
import { useLocation, matchPath } from "react-router";
// import { AppContext } from '../../context/app'
export default function NewGame() {
// const [ctx, dispatchCtx] = React.useContext(AppContext)
const { pathname } = useLocation();
const isMyPath = matchPath("/game/new", pathname);
if (!isMyPath)
return
return (
<div className='new-game'>
<div>New game TBD</div>
</div>
)
}

View File

@ -4,22 +4,22 @@ import GameHeader from './GameHeader'
import GameSelector from './GameSelector' import GameSelector from './GameSelector'
import GameAction from './GameAction' import GameAction from './GameAction'
import GameBoard from './GameBoard' import GameBoard from './GameBoard'
import NewGame from './NewGame';
// import { AppData } from "../../context/data"
export default function Game() { export default function Game() {
return <div className="split"> return (
<div className="split">
<div className='split left'> <div className='split left'>
<GameHeader /> <GameHeader />
<GameSelector /> <GameSelector />
<NewGame />
</div>
<div className='split right'>
<GameAction />
<GameBoard />
</div>
</div> </div>
)
<div className='split right'>
<GameAction />
<GameBoard />
</div>
</div>
} }