-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
199 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import './Matches.less'; | ||
import {Player} from '../player/Player'; | ||
import {TableResponsive} from '../table-responsive/TableResponsive'; | ||
import {reformatDate, getMatchResult} from '../utils'; | ||
|
||
const resultLabels = { | ||
'-2': <>— x —</>, | ||
'-1': <>— <span><sup>V</sup>/<sub>S</sub></span> —</>, | ||
'0': <>thua</>, | ||
'1': <>hòa</>, | ||
'2': <>thắng</>, | ||
}; | ||
|
||
export let Matches = ({ pairs, matchesById, latestMatchDate }) => { | ||
return ( | ||
<div class="Matches"> | ||
<TableResponsive> | ||
<table> | ||
{pairs.map(({firstPlayer, secondPlayer}) => { | ||
let matchId = `${firstPlayer.id}-${secondPlayer.id}`; | ||
let matchOrEmpty = matchesById[matchId]; | ||
let result = getMatchResult(matchOrEmpty); | ||
if (!(firstPlayer.active && secondPlayer.active)) { | ||
result = -2; | ||
} | ||
let resultLabel = resultLabels[result]; | ||
let date; | ||
let resultDetails; | ||
if (matchOrEmpty != null) { | ||
date = matchOrEmpty.date; | ||
let gameResults = []; | ||
let counts = {}; | ||
for (let game of matchOrEmpty.games) { | ||
if (counts[game.result] != null) { | ||
counts[game.result]++; | ||
} else { | ||
counts[game.result] = 1; | ||
gameResults.push(game.result); | ||
} | ||
} | ||
resultDetails = ( | ||
<>{gameResults.map((gameResult) => ( | ||
<> {counts[gameResult]} {resultLabels[gameResult]} </> | ||
))}</> | ||
); | ||
} | ||
|
||
return ( | ||
<tr key={matchId} class={date === latestMatchDate ? 'recent-match' : ''}> | ||
<td align="right"> | ||
<Player player={firstPlayer} align="right" /> | ||
</td> | ||
<td align="center"> | ||
<div class="match-info"> | ||
{date && ( | ||
<div class="date">{reformatDate(date)}</div> | ||
)} | ||
<div class="result" data-result={result}>{resultLabel}</div> | ||
{resultDetails && ( | ||
<div class="result-details">{resultDetails}</div> | ||
)} | ||
</div> | ||
</td> | ||
<td align="left"> | ||
<Player player={secondPlayer} /> | ||
</td> | ||
</tr> | ||
); | ||
})} | ||
</table> | ||
</TableResponsive> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.Matches { | ||
table { | ||
border-collapse: collapse; | ||
|
||
td, th { | ||
padding: 0.5em 0.25em; | ||
} | ||
|
||
td { | ||
border-top: 1px solid lightgray; | ||
} | ||
|
||
tr.recent-match { | ||
background: whitesmoke; | ||
} | ||
|
||
.match-info { | ||
white-space: nowrap; | ||
|
||
> :not(:first-child) { | ||
margin-top: 0.1em; | ||
} | ||
|
||
.date { | ||
font-size: x-small; | ||
color: darkgray; | ||
} | ||
|
||
.result { | ||
&[data-result="-2"] { | ||
color: gray; | ||
} | ||
|
||
&[data-result="-1"] { | ||
color: lightgray; | ||
|
||
span { | ||
font-size: smaller; | ||
font-style: italic; | ||
font-weight: bold; | ||
} | ||
} | ||
|
||
&[data-result="0"] { | ||
color: red; | ||
text-transform: uppercase; | ||
} | ||
|
||
&[data-result="1"] { | ||
color: blue; | ||
text-transform: uppercase; | ||
} | ||
|
||
&[data-result="2"] { | ||
color: green; | ||
text-transform: uppercase; | ||
} | ||
} | ||
|
||
.result-details { | ||
font-size: x-small; | ||
color: darkgray; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.