1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Fix linter errors

This commit is contained in:
Daniel Barber 2018-02-28 11:00:33 -05:00
parent 059b45d40d
commit d982d19713
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
8 changed files with 59 additions and 63 deletions

View File

@ -111,7 +111,7 @@
], ],
"array-bracket-spacing": [ "array-bracket-spacing": [
2, 2,
"always" "never"
], ],
"indent": [ "indent": [
2, 2,

View File

@ -4,25 +4,25 @@ exports.config = {
javascripts: { javascripts: {
joinTo: { joinTo: {
"js/app.js": /^js/, "js/app.js": /^js/,
"js/vendor.js": /^(?!js)/ "js/vendor.js": /^(?!js)/,
} },
}, },
stylesheets: { stylesheets: {
joinTo: "css/app.css", joinTo: "css/app.css",
order: { order: {
after: ["web/static/css/app.css"] // concat app.css last after: ["web/static/css/app.css"], // concat app.css last
} },
}, },
templates: { templates: {
joinTo: "js/app.js" joinTo: "js/app.js",
} },
}, },
conventions: { conventions: {
// This option sets where we should place non-css and non-js assets in. // This option sets where we should place non-css and non-js assets in.
// By default, we set this to "/assets/static". Files in this directory // By default, we set this to "/assets/static". Files in this directory
// will be copied to `paths.public`, which is "priv/static" by default. // will be copied to `paths.public`, which is "priv/static" by default.
assets: /^(static)/ assets: /^(static)/,
}, },
// Phoenix paths configuration // Phoenix paths configuration
@ -31,40 +31,40 @@ exports.config = {
watched: ["static", "css", "js", "vendor"], watched: ["static", "css", "js", "vendor"],
// Where to compile files to // Where to compile files to
public: "../priv/static" public: "../priv/static",
}, },
// Configure your plugins // Configure your plugins
plugins: { plugins: {
sass: { sass: {
mode: 'native' mode: "native",
}, },
babel: { babel: {
plugins: [ plugins: [
'transform-object-rest-spread', "transform-object-rest-spread",
'transform-class-properties', "transform-class-properties",
], ],
presets: [ presets: [
[ [
'env', { "env", {
'browsers': [ '> 5% in US' ], "browsers": ["> 5% in US"],
'useBuiltIns': true, "useBuiltIns": true,
}, },
], ],
'es2015', "es2015",
'react', "react",
], ],
ignore: [ /vendor/ ], ignore: [/vendor/],
}, },
}, },
modules: { modules: {
autoRequire: { autoRequire: {
"js/app.js": ["js/app"] "js/app.js": ["js/app"],
} },
}, },
npm: { npm: {
enabled: true enabled: true,
} },
}; };

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
import "babel-polyfill"; import "babel-polyfill";
import "phoenix_html" import "phoenix_html";
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";

View File

@ -15,20 +15,18 @@ class ChessBoardSquare extends React.Component {
} }
selectSquare() { selectSquare() {
var { piece, store } = this.props; let { piece, store } = this.props;
var { gameId, selectedSquare, player } = store.getState(); let { gameId, selectedSquare, player } = store.getState();
if (selectedSquare != null && this.moveIsValid()) { if (selectedSquare != null && this.moveIsValid()) {
$.ajax({ $.ajax({
method: "PATCH", method: "PATCH",
url: "/api/games/" + gameId, url: "/api/games/" + gameId,
data: { move: { from: selectedSquare, to: this.squareCoords() } } data: { move: { from: selectedSquare, to: this.squareCoords() } },
}).then((data) => store.dispatch(setGame(data))); }).then((data) => store.dispatch(setGame(data)));
} } else if (selectedSquare != null) {
else if (selectedSquare != null) {
store.dispatch(selectPiece(null)); store.dispatch(selectPiece(null));
} } else if (this.playerCanSelectPiece(player, piece)) {
else if (this.playerCanSelectPiece(player, piece)) {
store.dispatch(selectPiece(this.squareCoords())); store.dispatch(selectPiece(this.squareCoords()));
} }
} }
@ -38,8 +36,8 @@ class ChessBoardSquare extends React.Component {
} }
playerCanSelectPiece(player, piece) { playerCanSelectPiece(player, piece) {
var { store } = this.props; let { store } = this.props;
var { turn } = store.getState(); let { turn } = store.getState();
return piece !== undefined && return piece !== undefined &&
piece.colour == player && piece.colour == player &&
@ -47,12 +45,11 @@ class ChessBoardSquare extends React.Component {
} }
isSelectedSquare() { isSelectedSquare() {
var { store } = this.props; let { store } = this.props;
if (store.getState().selectedSquare == null) { if (store.getState().selectedSquare == null) {
return false; return false;
} } else {
else {
return _.isEqual(this.squareCoords(), store.getState().selectedSquare); return _.isEqual(this.squareCoords(), store.getState().selectedSquare);
} }
} }
@ -64,8 +61,7 @@ class ChessBoardSquare extends React.Component {
squareClass() { squareClass() {
if (this.props.piece == undefined) { if (this.props.piece == undefined) {
return "board-square"; return "board-square";
} } else {
else {
return classNames( return classNames(
"board-square", "board-square",
this.props.piece.type, this.props.piece.type,
@ -80,7 +76,7 @@ class ChessBoardSquare extends React.Component {
id={this.squareId()} id={this.squareId()}
className={this.squareClass()} className={this.squareClass()}
onClick={this.selectSquare.bind(this)} onClick={this.selectSquare.bind(this)}
/> />;
} }
} }

View File

@ -17,14 +17,16 @@ class ChessBoard extends React.Component {
store.dispatch(setGameId(gameId)); store.dispatch(setGameId(gameId));
$.ajax({ method: "GET", url: `/api/games/${gameId}` }) $.ajax({ method: "GET", url: `/api/games/${gameId}` })
.then((data) => { .then(data => {
store.dispatch(setPlayer(data.player)); store.dispatch(setPlayer(data.player));
store.dispatch(setGame(data)); store.dispatch(setGame(data));
}); });
this.channel = socket.channel("game:" + gameId, {}); this.channel = socket.channel("game:" + gameId, {});
this.channel.join() this.channel.join()
.receive("error", resp => { console.log("Unable to join", resp); }); .receive("error", resp => {
console.log("Unable to join", resp);
});
this.channel.on("game_update", data => { this.channel.on("game_update", data => {
store.dispatch(setGame(data)); store.dispatch(setGame(data));
@ -50,7 +52,7 @@ class ChessBoard extends React.Component {
const { store } = this.props; const { store } = this.props;
const rank = this.getBoard()[rankId]; const rank = this.getBoard()[rankId];
return _.map(this.files(rank), (fileId) => { return _.map(this.files(rank), fileId => {
return ( return (
<ChessBoardSquare <ChessBoardSquare
file={fileId} file={fileId}
@ -66,7 +68,7 @@ class ChessBoard extends React.Component {
renderRanks() { renderRanks() {
const board = this.getBoard(); const board = this.getBoard();
return _.map(this.ranks(), (rankId) => { return _.map(this.ranks(), rankId => {
return ( return (
<div className="board-rank" key={rankId}> <div className="board-rank" key={rankId}>
{this.renderFiles(rankId)} {this.renderFiles(rankId)}
@ -79,10 +81,12 @@ class ChessBoard extends React.Component {
const player = this.getPlayer(); const player = this.getPlayer();
switch (player) { switch (player) {
case 'white': case "white":
return Object.keys(rank).sort(); return Object.keys(rank).sort();
case 'black': case "black":
return Object.keys(rank).sort().reverse(); return Object.keys(rank)
.sort()
.reverse();
} }
} }
@ -91,9 +95,9 @@ class ChessBoard extends React.Component {
const player = this.getPlayer(); const player = this.getPlayer();
switch (player) { switch (player) {
case 'white': case "white":
return Object.keys(board).reverse(); return Object.keys(board).reverse();
case 'black': case "black":
return Object.keys(board); return Object.keys(board);
} }
} }
@ -102,26 +106,22 @@ class ChessBoard extends React.Component {
const turn = this.getTurn(); const turn = this.getTurn();
const player = this.getPlayer(); const player = this.getPlayer();
return classNames( return classNames("board", turn + "-to-move", "player-is-" + player);
"board",
turn + "-to-move",
"player-is-" + player
);
} }
render() { render() {
return ( return (
<div className={this.boardClass()}> <div className={this.boardClass()}>
<div className="board-header"> <div className="board-header">
<div className="board-border-top"></div> <div className="board-border-top" />
</div> </div>
<div className="board-body"> <div className="board-body">
<div className="board-border-left"></div> <div className="board-border-left" />
<div className="board-ranks">{this.renderRanks()}</div> <div className="board-ranks">{this.renderRanks()}</div>
<div className="board-border-right"></div> <div className="board-border-right" />
</div> </div>
<div className="board-footer"> <div className="board-footer">
<div className="board-border-bottom"></div> <div className="board-border-bottom" />
</div> </div>
</div> </div>
); );
@ -131,8 +131,8 @@ class ChessBoard extends React.Component {
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
board: state.board, board: state.board,
selectedSquare: state.selectedSquare selectedSquare: state.selectedSquare,
} };
} }
export default connect(mapStateToProps)(ChessBoard); export default connect(mapStateToProps)(ChessBoard);

View File

@ -29,6 +29,6 @@ const chessBoardReducer = (state = defaultState, action) => {
default: default:
return state; return state;
} }
} };
export default chessBoardReducer; export default chessBoardReducer;

View File

@ -6,7 +6,7 @@ const SELECT_PIECE = "SELECT_PIECE";
export const setPlayer = (player) => { export const setPlayer = (player) => {
return { return {
type: SET_PLAYER, type: SET_PLAYER,
player: player, player,
}; };
}; };
@ -21,13 +21,13 @@ export const setGame = (data) => {
export const setGameId = (gameId) => { export const setGameId = (gameId) => {
return { return {
type: SET_GAME_ID, type: SET_GAME_ID,
gameId: gameId, gameId,
}; };
}; };
export const selectPiece = (coords) => { export const selectPiece = (coords) => {
return { return {
type: SELECT_PIECE, type: SELECT_PIECE,
coords: coords, coords,
}; };
}; };

View File

@ -13,7 +13,7 @@ const defaultState = {
3: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null }, 3: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
2: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null }, 2: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
1: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null }, 1: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
} },
}; };
export default defaultState; export default defaultState;