Counter - for watong for you games
This commit is contained in:
parent
9439186b8a
commit
d8d3406fe1
13
webapp/src/components/Counter.css
Normal file
13
webapp/src/components/Counter.css
Normal file
@ -0,0 +1,13 @@
|
||||
.Counter {
|
||||
display: inline-block;
|
||||
line-height: 0px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.Counter span {
|
||||
display: inline-block;
|
||||
padding-top: 50%;
|
||||
padding-bottom: 50%;
|
||||
margin-left: 2px;
|
||||
margin-right: 2px;
|
||||
}
|
7
webapp/src/components/Counter.jsx
Normal file
7
webapp/src/components/Counter.jsx
Normal file
@ -0,0 +1,7 @@
|
||||
import React from 'react';
|
||||
import './Counter.css';
|
||||
|
||||
export default function Counter({ number }) {
|
||||
if (number !== 0)
|
||||
return <span className="Counter"><span>{number}</span></span>
|
||||
}
|
@ -59,7 +59,12 @@
|
||||
box-shadow: 0 1.5px 0 0 currentColor;
|
||||
}
|
||||
|
||||
|
||||
.ViewSelector .Counter {
|
||||
background-color:palevioletred;
|
||||
margin-right: 1px;
|
||||
font-size: 60%;
|
||||
vertical-align: 7px;
|
||||
}
|
||||
|
||||
.ViewProvider {
|
||||
display: flex;
|
||||
|
@ -17,6 +17,7 @@ import Forward from './games/action/Forward';
|
||||
|
||||
import GameBoard from './games/GameBoard';
|
||||
import Message2Opponent from './games/Message2Opponent';
|
||||
import Counter from '../components/Counter';
|
||||
|
||||
import './Games.css';
|
||||
|
||||
@ -27,7 +28,7 @@ export default function Games({ context: { gamesReducer, gamesApi }, players })
|
||||
<GamesContext.Provider value={games} >
|
||||
<div className='Games'>
|
||||
<div className='left-side'>
|
||||
<ViewSelector />
|
||||
<ViewSelector games={games} />
|
||||
<ViewProvider gamesReducer={gamesReducer} players={players} />
|
||||
</div>
|
||||
<div className='right-side'>
|
||||
@ -43,14 +44,14 @@ export default function Games({ context: { gamesReducer, gamesApi }, players })
|
||||
)
|
||||
};
|
||||
|
||||
function ViewSelector() {
|
||||
// TODO: counter Wating for YOU
|
||||
function ViewSelector({ games }) {
|
||||
const awaiting = countGames(games.gamesList);
|
||||
|
||||
return (
|
||||
<nav className='ViewSelector' >
|
||||
<NavLink to='new'>New</NavLink>
|
||||
<NavLink to='proposal'>Proposal</NavLink>
|
||||
<NavLink to='active'>Active</NavLink>
|
||||
<NavLink to='proposal'>Proposal<Counter number={awaiting.proposals} /></NavLink>
|
||||
<NavLink to='active' >Active<Counter number={awaiting.active} /></NavLink>
|
||||
<NavLink to='archive' >Archive</NavLink>
|
||||
</nav>
|
||||
)
|
||||
@ -103,3 +104,30 @@ function ActionPanel({ players, gamesApi }) {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function countGames(gamesList) {
|
||||
|
||||
var awaiting = {
|
||||
proposals: 0,
|
||||
active: 0
|
||||
};
|
||||
|
||||
if (!gamesList)
|
||||
return awaiting;
|
||||
|
||||
for (const game of gamesList) {
|
||||
switch (game.status) {
|
||||
case 'GAME_PROPOSAL_WAIT_FOR_YOU':
|
||||
awaiting.proposals++;
|
||||
break;
|
||||
case 'GAME_BOARD_WAIT_FOR_YOU':
|
||||
case 'DRAW_REQUEST_WAIT_FOR_YO':
|
||||
awaiting.active++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return awaiting;
|
||||
}
|
||||
|
@ -46,6 +46,10 @@ hr {
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
|
||||
.Separator .Counter {
|
||||
background-color: darkgray;
|
||||
}
|
||||
|
||||
.Selectable .Title {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
@ -4,6 +4,7 @@ import { GamesContext } from '../../../context/games';
|
||||
|
||||
import { Color, Player } from '../../../components/Checkers';
|
||||
import Loading from '../../../components/Loading';
|
||||
import Counter from '../../../components/Counter';
|
||||
|
||||
export default function GameSelector({ yours, opponents, onClick }) {
|
||||
|
||||
@ -49,7 +50,8 @@ function Selectable({ game, onClick }) {
|
||||
function Separator({ counter }) {
|
||||
return (
|
||||
<div className="Separator">
|
||||
waiting for opponent ({counter})
|
||||
waiting for opponent
|
||||
<Counter number={counter} />
|
||||
</div>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user