Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter Errors Correction Feature #2

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"regenerator-runtime": "^0.14.1"
Expand Down
1 change: 1 addition & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-syntax */
import { useState } from 'react';
import Player from './components/Player';
import GameBoard from './components/GameBoard';
Expand Down
11 changes: 11 additions & 0 deletions src/components/GameBoard.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable react/no-array-index-key */
import PropTypes from 'prop-types';

const GameBoard = ({ onSelectSquare, board }) => (
<ol id="game-board">
{board.map((row, rowIndex) => (
Expand All @@ -6,6 +9,7 @@ const GameBoard = ({ onSelectSquare, board }) => (
{row.map((playerSymbol, colIndex) => (
<li key={colIndex}>
<button
type="button"
onClick={() => onSelectSquare(rowIndex, colIndex)}
disabled={playerSymbol !== null}
>
Expand All @@ -19,4 +23,11 @@ const GameBoard = ({ onSelectSquare, board }) => (
</ol>
);

GameBoard.propTypes = {
onSelectSquare: PropTypes.func.isRequired,
board: PropTypes.arrayOf(
PropTypes.arrayOf(PropTypes.string),
).isRequired,
};

export default GameBoard;
15 changes: 13 additions & 2 deletions src/components/GameOver.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import PropTypes from 'prop-types';

const GameOver = ({ winner, onRestart }) => (
<div id="game-over">
<h2>Game Over!</h2>
Expand All @@ -8,9 +10,18 @@ const GameOver = ({ winner, onRestart }) => (
won!
</p>
)}
{!winner && <p>It's a draw!</p>}
<p><button onClick={onRestart}>Rematch!</button></p>
{!winner && <p>It&apos;s a draw!</p>}
<p><button type="button" onClick={onRestart}>Rematch!</button></p>
</div>
);

GameOver.propTypes = {
winner: PropTypes.string,
onRestart: PropTypes.func.isRequired,
};

GameOver.defaultProps = {
winner: null,
};

export default GameOver;
13 changes: 13 additions & 0 deletions src/components/Log.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';

const Log = ({ turns }) => (
<ol id="log">
Expand All @@ -15,4 +16,16 @@ const Log = ({ turns }) => (
</ol>
);

Log.propTypes = {
turns: PropTypes.arrayOf(
PropTypes.shape({
player: PropTypes.string.isRequired,
square: PropTypes.shape({
row: PropTypes.number.isRequired,
col: PropTypes.number.isRequired,
}).isRequired,
}),
).isRequired,
};

export default Log;
13 changes: 11 additions & 2 deletions src/components/Player.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';

const Player = ({
initialName, symbol, isActive, onChangeName,
Expand All @@ -7,7 +8,8 @@ const Player = ({
const [isEditing, setIsEditing] = useState(false);

const handleEditClick = () => {
setIsEditing((editing) => !editing); // When update state based on old value you pass a function.
setIsEditing((editing) => !editing);
// When update state based on old value you pass a function.
if (isEditing) {
onChangeName(symbol, playerName);
}
Expand Down Expand Up @@ -41,9 +43,16 @@ const Player = ({
)}
<span className="player-symbol">{symbol}</span>
</span>
<button onClick={handleEditClick}>{isEditing ? 'Save' : 'Edit'}</button>
<button type="button" onClick={handleEditClick}>{isEditing ? 'Save' : 'Edit'}</button>
</li>
);
};

Player.propTypes = {
initialName: PropTypes.string.isRequired,
symbol: PropTypes.string.isRequired,
isActive: PropTypes.bool.isRequired,
onChangeName: PropTypes.func.isRequired,
};

export default Player;
3 changes: 1 addition & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ReactDOM from 'react-dom/client';

import App from './App.jsx';
import App from './App';
import './index.css';

ReactDOM.createRoot(document.getElementById('root')).render(<App />);
1 change: 1 addition & 0 deletions src/winnig-combinations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
export const WINNING_COMBINATIONS = [
[
{ row: 0, column: 0 },
Expand Down
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

Expand Down
Loading