mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
* Forms and board tweaks for small screen sizes * Re-style game status indicators * Re-style viewing/offline indicator * Better eyecons 👁 * Re-organise CSS according to ITCSS principles * Pick new font from Google Fonts * Fix up tests * Move some things into partials
79 lines
1.6 KiB
JavaScript
79 lines
1.6 KiB
JavaScript
import React from "react";
|
|
import _ from "lodash";
|
|
import { connect } from "react-redux";
|
|
import classNames from "classnames";
|
|
|
|
const pieceToNotation = (piece) => {
|
|
const pieces = {
|
|
pawn: "",
|
|
knight: "N",
|
|
bishop: "B",
|
|
rook: "R",
|
|
queen: "Q",
|
|
king: "K",
|
|
};
|
|
|
|
return pieces[piece.type];
|
|
};
|
|
|
|
const moveClass = (move) => {
|
|
return classNames("move-list__move", "move-list__move--" + move.piece.colour);
|
|
};
|
|
|
|
const renderMove = (move) => {
|
|
if (move != undefined) {
|
|
return (
|
|
<td className={moveClass(move)}>
|
|
{pieceToNotation(move.piece)}
|
|
{move.piece_captured ? "x" : ""}
|
|
{move.to}
|
|
</td>
|
|
);
|
|
}
|
|
};
|
|
|
|
const renderMoves = (moves) => {
|
|
let lineNumber = 1;
|
|
|
|
return _.map(moves, (move) => {
|
|
return (
|
|
<tr key={move[0].id}>
|
|
<th scope="row" className="move-list__line-number">{lineNumber++}.</th>
|
|
{renderMove(move[0])}
|
|
{renderMove(move[1])}
|
|
</tr>
|
|
);
|
|
});
|
|
};
|
|
|
|
const MoveList = (props) => {
|
|
return (
|
|
<div className="move-list">
|
|
<table className="table table--condensed">
|
|
<thead>
|
|
<tr>
|
|
<th className="move-list__line-number">
|
|
<span className="visually-hidden">Move no.</span>
|
|
</th>
|
|
|
|
<th className="move-list__header--white">White</th>
|
|
<th className="move-list__header--black">Black</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
{renderMoves(props.moves)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
moves: state.moves,
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(MoveList);
|