Skip to content

Commit dc8c119

Browse files
Merge pull request #307 from oslabs-beta/main
Merging Reactime v18 into OS Labs main, initial
2 parents 4ff74dd + 50364bf commit dc8c119

File tree

180 files changed

+9952
-15278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+9952
-15278
lines changed

.eslintrc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"extends": [
3-
"airbnb",
3+
"airbnb",
44
"plugin:jest/recommended",
55
"plugin:@typescript-eslint/eslint-recommended",
6-
"plugin:@typescript-eslint/recommended"],
6+
"plugin:@typescript-eslint/recommended"
7+
],
78
"root": true,
89
"plugins": ["jest", "react", "react-hooks", "@typescript-eslint"],
910
"rules": {
@@ -13,7 +14,8 @@
1314
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
1415
"react-hooks/exhaustive-deps": "warn", // Checks effect dependencies
1516
"react/jsx-filename-extension": [0],
16-
"linebreak-style": "off"
17+
"linebreak-style": "off",
18+
"max-len": [{ "ignoreComments": true }]
1719
},
1820
"env": {
1921
"es6": true,
@@ -33,4 +35,4 @@
3335
"ecmaVersion": 2018,
3436
"sourceType": "module"
3537
}
36-
}
38+
}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ node_modules/
55
.DS_Store
66
src/extension/build/bundles
77
package/reactime-*.tgz
8-
tictactoe
98
parents
109
coverage
1110
src/extension/build.zip
@@ -15,4 +14,5 @@ bower_components
1514
sandboxes/manual-tests/NextJS/.next
1615
.vscode
1716
src/app/components/Map.tsx
18-
package-lock.json
17+
package-lock.json
18+
yarn.lock

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "tests/manual-tests/recoilTest"]
22
path = tests/manual-tests/recoilTest
33
url = https://github.com/kevinfey/recoilTest
4+
[submodule "reactime-website"]
5+
path = reactime-website
6+
url = https://github.com/reactimetravel/reactime-website

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"printWidth": 100,
3+
"semi": true,
4+
"singleQuote": true,
5+
"jsxSingleQuote": true,
6+
"tabWidth": 2,
7+
"bracketSpacing": true,
8+
"trailingComma": "all"
9+
}

demo-app-next/.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
21+
# debug
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
# local env files
27+
.env.local
28+
.env.development.local
29+
.env.test.local
30+
.env.production.local

demo-app-next/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a starter template for [Learn Next.js](https://nextjs.org/learn).

demo-app-next/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

demo-app-next/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"dev": "next dev",
5+
"build": "next build",
6+
"start": "next start"
7+
},
8+
"dependencies": {
9+
"next": "latest",
10+
"react": "18.2.0",
11+
"react-dom": "18.2.0"
12+
},
13+
"devDependencies": {
14+
"@types/node": "18.15.0",
15+
"@types/react": "18.0.28",
16+
"typescript": "4.9.5"
17+
}
18+
}

demo-app-next/public/favicon.ico

14.7 KB
Binary file not shown.

demo-app-next/public/vercel.svg

Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import React, { Component } from "react";
2+
import Row from "./Row";
3+
import { BoardText, BoardContent, Scoreboard, Player } from "../types/types";
4+
5+
type BoardState = {
6+
board: BoardContent;
7+
currentPlayer: Player;
8+
gameOver: boolean;
9+
message: string;
10+
scoreboard: Scoreboard;
11+
};
12+
13+
class Board extends Component<{}, BoardState> {
14+
constructor(props: any) {
15+
super(props);
16+
this.state = {
17+
board: this.newBoard(),
18+
currentPlayer: "X",
19+
gameOver: false,
20+
message: "",
21+
scoreboard: { X: 0, O: 0 },
22+
};
23+
24+
this.resetBoard = this.resetBoard.bind(this);
25+
this.handleBoxClick = this.handleBoxClick.bind(this);
26+
}
27+
28+
componentDidUpdate() {
29+
this.checkForWinner();
30+
}
31+
32+
/**
33+
* @method newBoard
34+
* @description - returns a blank BoardContent array,
35+
* for the start of a new game
36+
*/
37+
newBoard(): BoardContent {
38+
return [
39+
["-", "-", "-"],
40+
["-", "-", "-"],
41+
["-", "-", "-"],
42+
];
43+
}
44+
45+
/**
46+
* @method resetBoard
47+
* @description - sets to board object to be all '-',
48+
* and sets gameOver and message to default state
49+
*/
50+
resetBoard(): void {
51+
this.setState({
52+
gameOver: false,
53+
board: this.newBoard(),
54+
message: "",
55+
});
56+
}
57+
58+
/**
59+
* @method checkForWinner
60+
* @description - checks to see if either player has filled a row
61+
* if so, ends the game and updates the message to declare winner
62+
*/
63+
checkForWinner(): void {
64+
const { board, gameOver, currentPlayer } = this.state;
65+
66+
const spacesLeft = (): boolean => {
67+
for (let i of board) {
68+
if (i.includes("-")) return true;
69+
}
70+
return false;
71+
};
72+
73+
if (!gameOver) {
74+
// win conditions: matching rows, columns, or diagonals, that are not empty('-')
75+
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] !== "-")
100+
) {
101+
// winner is the person who's turn was previous
102+
const winner: Player = currentPlayer === "X" ? "O" : "X";
103+
104+
this.setState({
105+
gameOver: true,
106+
message: `Player ${winner} wins!`,
107+
});
108+
109+
// draw condition: no '-' remaining in board without above win condition triggering
110+
} else if (!spacesLeft()) {
111+
this.setState({
112+
gameOver: true,
113+
message: "Draw!",
114+
});
115+
}
116+
}
117+
}
118+
119+
handleBoxClick(row: number, column: number): void {
120+
const boardCopy: BoardContent = [
121+
[...this.state.board[0]],
122+
[...this.state.board[1]],
123+
[...this.state.board[2]],
124+
];
125+
boardCopy[row][column] = this.state.currentPlayer;
126+
const newPlayer: Player = this.state.currentPlayer === "X" ? "O" : "X";
127+
this.setState({ board: boardCopy, currentPlayer: newPlayer });
128+
}
129+
130+
render() {
131+
const rows: Array<JSX.Element> = [];
132+
for (let i = 0; i < 3; i++) {
133+
rows.push(
134+
<Row
135+
key={i}
136+
row={i}
137+
handleBoxClick={this.handleBoxClick}
138+
values={this.state.board[i]}
139+
/>
140+
);
141+
}
142+
const { X, O }: Scoreboard = this.state.scoreboard;
143+
144+
return (
145+
<div className="board">
146+
<h1>Tic Tac Toe</h1>
147+
{this.state.gameOver && <h4>{this.state.message}</h4>}
148+
{rows}
149+
<button id="reset" onClick={this.resetBoard}>
150+
Reset
151+
</button>
152+
</div>
153+
);
154+
}
155+
}
156+
157+
export default Board;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { BoardText } from "../types/types";
2+
3+
type BoxProps = {
4+
value: BoardText;
5+
row: number;
6+
column: number;
7+
handleBoxClick: (row: number, column: number) => void;
8+
};
9+
10+
const Box = (props: BoxProps) => {
11+
return (
12+
<button
13+
className="box"
14+
onClick={(e) => props.handleBoxClick(props.row, props.column)}
15+
>
16+
{props.value}
17+
</button>
18+
);
19+
};
20+
21+
export default Box;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Increment from './Increment';
2+
3+
export default function Buttons() {
4+
const buttons = [];
5+
for (let i = 0; i < 4; i++) {
6+
buttons.push(<Increment key={i} />);
7+
}
8+
9+
return (
10+
<div className='buttons'>
11+
<h1>Stateful Buttons</h1>
12+
<h4>
13+
These buttons are functional components that each manage their own state with the useState
14+
hook.
15+
</h4>
16+
{buttons}
17+
</div>
18+
);
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React, { useState } from "react";
2+
3+
export default function Increment() {
4+
const [count, setCount] = useState(0);
5+
6+
return (
7+
<button className="increment" onClick={() => setCount(count + 1)}>
8+
You clicked me {count} times.
9+
</button>
10+
);
11+
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Box from "./Box";
2+
import { BoardText } from "../types/types";
3+
4+
type RowProps = {
5+
handleBoxClick: (row: number, column: number) => void;
6+
values: Array<BoardText>;
7+
row: number;
8+
};
9+
10+
const Row = (props: RowProps) => {
11+
const boxes: Array<JSX.Element> = [];
12+
for (let i = 0; i < 3; i++) {
13+
boxes.push(
14+
<Box
15+
key={i}
16+
row={props.row}
17+
column={i}
18+
handleBoxClick={props.handleBoxClick}
19+
value={props.values[i]}
20+
></Box>
21+
);
22+
}
23+
24+
return <div className="row">{boxes}</div>;
25+
};
26+
27+
export default Row;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Link from 'next/link';
2+
3+
export default function Navbar() {
4+
return (
5+
<div className='nav'>
6+
<Link className='link' href='/'>
7+
About
8+
</Link>
9+
<Link id='tictactoe' className='link' href='/tictactoe'>
10+
Tic-Tac-Toe
11+
</Link>
12+
<Link className='link' href='/buttons'>
13+
Counter
14+
</Link>
15+
</div>
16+
);
17+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "../../styles/style.css";
2+
3+
export default function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />;
5+
}

0 commit comments

Comments
 (0)