Skip to content

Commit 713d9b2

Browse files
committed
prettier maybe
1 parent eca8d5e commit 713d9b2

File tree

34 files changed

+257
-320
lines changed

34 files changed

+257
-320
lines changed

demo-app-next/src/components/Board.tsx

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { Component } from "react";
2-
import Row from "./Row";
3-
import { BoardContent, Scoreboard, Player } from "../types/types";
1+
import React, { Component } from 'react';
2+
import Row from './Row';
3+
import { BoardContent, Scoreboard, Player } from '../types/types';
44

55
type BoardState = {
66
board: BoardContent;
@@ -15,17 +15,17 @@ class Board extends Component<{}, BoardState> {
1515
super(props);
1616
this.state = {
1717
board: this.newBoard(),
18-
currentPlayer: "X",
18+
currentPlayer: 'X',
1919
gameOver: false,
20-
message: "",
20+
message: '',
2121
scoreboard: { X: 0, O: 0 },
2222
};
2323

2424
this.resetBoard = this.resetBoard.bind(this);
2525
this.handleBoxClick = this.handleBoxClick.bind(this);
2626
}
2727

28-
componentDidUpdate():void {
28+
componentDidUpdate(): void {
2929
this.checkForWinner();
3030
}
3131

@@ -36,9 +36,9 @@ class Board extends Component<{}, BoardState> {
3636
*/
3737
newBoard(): BoardContent {
3838
return [
39-
["-", "-", "-"],
40-
["-", "-", "-"],
41-
["-", "-", "-"],
39+
['-', '-', '-'],
40+
['-', '-', '-'],
41+
['-', '-', '-'],
4242
];
4343
}
4444

@@ -51,7 +51,7 @@ class Board extends Component<{}, BoardState> {
5151
this.setState({
5252
gameOver: false,
5353
board: this.newBoard(),
54-
message: "",
54+
message: '',
5555
});
5656
}
5757

@@ -65,41 +65,25 @@ class Board extends Component<{}, BoardState> {
6565

6666
const spacesLeft = (): boolean => {
6767
for (let i of board) {
68-
if (i.includes("-")) return true;
68+
if (i.includes('-')) return true;
6969
}
7070
return false;
7171
};
7272

7373
if (!gameOver) {
7474
// win conditions: matching rows, columns, or diagonals, that are not empty('-')
7575
if (
76-
(board[0][0] === board[0][1] &&
77-
board[0][1] === board[0][2] &&
78-
board[0][2] !== "-") ||
79-
(board[1][0] === board[1][1] &&
80-
board[1][1] === board[1][2] &&
81-
board[1][2] !== "-") ||
82-
(board[2][0] === board[2][1] &&
83-
board[2][1] === board[2][2] &&
84-
board[2][2] !== "-") ||
85-
(board[0][0] === board[1][0] &&
86-
board[1][0] === board[2][0] &&
87-
board[2][0] !== "-") ||
88-
(board[0][1] === board[1][1] &&
89-
board[1][1] === board[2][1] &&
90-
board[2][1] !== "-") ||
91-
(board[0][2] === board[1][2] &&
92-
board[1][2] === board[2][2] &&
93-
board[2][2] !== "-") ||
94-
(board[0][0] === board[1][1] &&
95-
board[1][1] === board[2][2] &&
96-
board[2][2] !== "-") ||
97-
(board[2][0] === board[1][1] &&
98-
board[1][1] === board[0][2] &&
99-
board[0][2] !== "-")
76+
(board[0][0] === board[0][1] && board[0][1] === board[0][2] && board[0][2] !== '-') ||
77+
(board[1][0] === board[1][1] && board[1][1] === board[1][2] && board[1][2] !== '-') ||
78+
(board[2][0] === board[2][1] && board[2][1] === board[2][2] && board[2][2] !== '-') ||
79+
(board[0][0] === board[1][0] && board[1][0] === board[2][0] && board[2][0] !== '-') ||
80+
(board[0][1] === board[1][1] && board[1][1] === board[2][1] && board[2][1] !== '-') ||
81+
(board[0][2] === board[1][2] && board[1][2] === board[2][2] && board[2][2] !== '-') ||
82+
(board[0][0] === board[1][1] && board[1][1] === board[2][2] && board[2][2] !== '-') ||
83+
(board[2][0] === board[1][1] && board[1][1] === board[0][2] && board[0][2] !== '-')
10084
) {
10185
// winner is the person who's turn was previous
102-
const winner: Player = currentPlayer === "X" ? "O" : "X";
86+
const winner: Player = currentPlayer === 'X' ? 'O' : 'X';
10387

10488
this.setState({
10589
gameOver: true,
@@ -110,7 +94,7 @@ class Board extends Component<{}, BoardState> {
11094
} else if (!spacesLeft()) {
11195
this.setState({
11296
gameOver: true,
113-
message: "Draw!",
97+
message: 'Draw!',
11498
});
11599
}
116100
}
@@ -123,30 +107,25 @@ class Board extends Component<{}, BoardState> {
123107
[...this.state.board[2]],
124108
];
125109
boardCopy[row][column] = this.state.currentPlayer;
126-
const newPlayer: Player = this.state.currentPlayer === "X" ? "O" : "X";
110+
const newPlayer: Player = this.state.currentPlayer === 'X' ? 'O' : 'X';
127111
this.setState({ board: boardCopy, currentPlayer: newPlayer });
128112
}
129113

130114
render(): JSX.Element {
131115
const rows: Array<JSX.Element> = [];
132116
for (let i = 0; i < 3; i++) {
133117
rows.push(
134-
<Row
135-
key={i}
136-
row={i}
137-
handleBoxClick={this.handleBoxClick}
138-
values={this.state.board[i]}
139-
/>
118+
<Row key={i} row={i} handleBoxClick={this.handleBoxClick} values={this.state.board[i]} />,
140119
);
141120
}
142121
// const { X, O }: Scoreboard = this.state.scoreboard;
143122

144123
return (
145-
<div className="board">
124+
<div className='board'>
146125
<h1>Tic Tac Toe</h1>
147126
{this.state.gameOver && <h4>{this.state.message}</h4>}
148127
{rows}
149-
<button id="reset" onClick={this.resetBoard}>
128+
<button id='reset' onClick={this.resetBoard}>
150129
Reset
151130
</button>
152131
</div>

demo-app-next/src/components/Box.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BoardText } from "../types/types";
1+
import { BoardText } from '../types/types';
22

33
type BoxProps = {
44
value: BoardText;
@@ -9,10 +9,7 @@ type BoxProps = {
99

1010
const Box = (props: BoxProps): JSX.Element => {
1111
return (
12-
<button
13-
className="box"
14-
onClick={(e) => props.handleBoxClick(props.row, props.column)}
15-
>
12+
<button className='box' onClick={(e) => props.handleBoxClick(props.row, props.column)}>
1613
{props.value}
1714
</button>
1815
);

demo-app-next/src/components/Increment.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { useState } from "react";
1+
import React, { useState } from 'react';
22

33
export default function Increment(): JSX.Element {
44
const [count, setCount] = useState(0);
55

66
return (
7-
<button className="increment" onClick={() => setCount(count + 1)}>
7+
<button className='increment' onClick={() => setCount(count + 1)}>
88
You clicked me {count} times.
99
</button>
1010
);

demo-app-next/src/components/Row.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Box from "./Box";
2-
import { BoardText } from "../types/types";
1+
import Box from './Box';
2+
import { BoardText } from '../types/types';
33

44
type RowProps = {
55
handleBoxClick: (row: number, column: number) => void;
@@ -17,11 +17,11 @@ const Row = (props: RowProps) => {
1717
column={i}
1818
handleBoxClick={props.handleBoxClick}
1919
value={props.values[i]}
20-
></Box>
20+
></Box>,
2121
);
2222
}
2323

24-
return <div className="row">{boxes}</div>;
24+
return <div className='row'>{boxes}</div>;
2525
};
2626

2727
export default Row;

demo-app-next/src/pages/_app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import "../../styles/style.css";
2-
import React from "react"
1+
import '../../styles/style.css';
2+
import React from 'react';
33

44
export default function MyApp({ Component, pageProps }): JSX.Element {
55
return <Component {...pageProps} />;

demo-app-next/src/pages/buttons/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Buttons from "../../components/Buttons";
2-
import Navbar from "../../components/navbar";
1+
import Buttons from '../../components/Buttons';
2+
import Navbar from '../../components/navbar';
33

44
export default function ButtonsPage(): JSX.Element {
55
return (

demo-app-next/src/pages/index.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
import Navbar from "../components/navbar";
2-
import React from "react"
1+
import Navbar from '../components/navbar';
2+
import React from 'react';
33

4-
export default function Home():JSX.Element {
4+
export default function Home(): JSX.Element {
55
return (
66
<div>
77
<Navbar />
8-
<div className="about">
8+
<div className='about'>
99
<h1>Lorem Ipsum</h1>
1010
<p>
11-
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
12-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
13-
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
14-
aliquip ex ea commodo consequat. Duis aute irure dolor in
15-
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
16-
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
17-
culpa qui officia deserunt mollit anim id est laborum."
11+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
12+
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
13+
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
14+
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
15+
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
16+
est laborum."
1817
</p>
1918
<p>
20-
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
21-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
22-
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
23-
aliquip ex ea commodo consequat. Duis aute irure dolor in
24-
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
25-
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
26-
culpa qui officia deserunt mollit anim id est laborum."
19+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
20+
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
21+
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
22+
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
23+
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
24+
est laborum."
2725
</p>
2826
</div>
2927
</div>

demo-app-next/src/pages/tictactoe/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Board from '../../components/Board';
22
import Navbar from '../../components/navbar';
33

4-
export default function BoardPage():JSX.Element {
4+
export default function BoardPage(): JSX.Element {
55
return (
66
<div>
77
<Navbar />

demo-app-next/src/types/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ export type Scoreboard = {
33
O: number;
44
};
55

6-
export type Player = "X" | "O";
6+
export type Player = 'X' | 'O';
77

8-
export type BoardText = "X" | "O" | "-";
8+
export type BoardText = 'X' | 'O' | '-';
99

1010
export type BoardContent = Array<Array<BoardText>>;

demo-app-remix/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/** @type {import('eslint').Linter.Config} */
22
module.exports = {
3-
extends: ["@remix-run/eslint-config", "@remix-run/eslint-config/node"],
3+
extends: ['@remix-run/eslint-config', '@remix-run/eslint-config/node'],
44
};

0 commit comments

Comments
 (0)