Skip to content

Commit

Permalink
rename props
Browse files Browse the repository at this point in the history
Davi de Medeiros authored and davilima6 committed Sep 20, 2023
1 parent a4bf211 commit 4109f7f
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/components/Challenge/Challenge.tsx
Original file line number Diff line number Diff line change
@@ -7,14 +7,14 @@ import { useChallenge } from './useChallenge';
import './Challenge.css';

type Props = {
disabled: boolean;
isGameOver: boolean;
onHit: () => void;
onMiss: () => void;
onGameOver: () => void;
onTryAgain: () => void;
score: number;
};

function Challenge({ disabled, onHit, onMiss, onGameOver, score }: Props) {
function Challenge({ isGameOver, onHit, onMiss, onTryAgain, score }: Props) {
const { loading, error, value: challenge } = useChallenge();

async function handleAnswer(answer: string): Promise<void> {
@@ -50,10 +50,10 @@ function Challenge({ disabled, onHit, onMiss, onGameOver, score }: Props) {
);
}

if (disabled) {
if (isGameOver) {
return (
<main className="challenge-wrapper">
<GameOver onGameOver={onGameOver} score={score} />
<GameOver onTryAgain={onTryAgain} score={score} />
</main>
);
}
6 changes: 3 additions & 3 deletions src/components/GameOver/GameOver.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import './GameOver.css';

type Props = {
onGameOver: () => void;
onTryAgain: () => void;
score: number;
};

function GameOver({ onGameOver, score }: Props) {
function GameOver({ onTryAgain, score }: Props) {
const compliment = score > 0 ? 'Congratulations' : 'Pity';
const needsPlural = score === 0 || score > 1;

@@ -15,7 +15,7 @@ function GameOver({ onGameOver, score }: Props) {
<p>
{compliment}, you made {score} point{needsPlural ? 's' : ''}!
</p>
<button className="reset" onClick={onGameOver} autoFocus>
<button className="reset" onClick={onTryAgain} autoFocus>
Try again
</button>
</section>
8 changes: 4 additions & 4 deletions src/views/App/App.tsx
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ function App() {
setChancesLeft((prev) => prev - 1);
}

function handleGameOver(): void {
function handleTryAgain(): void {
setScore(INITIAL_SCORE);
setChancesLeft(INITIAL_CHANCES_LEFT);
}
@@ -34,16 +34,16 @@ function App() {
document.body.dataset.theme = theme === 'light' ? 'dark' : 'light';
}

const disabled = chancesLeft === 0;
const isGameOver = chancesLeft === 0;

return (
<div className="app-wrapper">
<ThemeToggler onToggle={handleThemeToggle} />
<Challenge
disabled={disabled}
onGameOver={handleGameOver}
isGameOver={isGameOver}
onHit={handleHit}
onMiss={handleMiss}
onTryAgain={handleTryAgain}
score={score}
/>
<Status chancesLeft={chancesLeft} score={score} />

0 comments on commit 4109f7f

Please sign in to comment.