Skip to content

Commit

Permalink
feat: add router push /gameresult #190
Browse files Browse the repository at this point in the history
  • Loading branch information
Храмыцких Антон committed Aug 11, 2023
1 parent 385ee39 commit 6617747
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions components/GameField/GameField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Link from 'next/link';
import cn from 'classnames';
import { FinishedGameState } from 'gameApi';
import { GameResult } from 'components/GameResult';
import { useRouter } from 'next/router';
export const GameField: React.FC<GameFieldPropsI> = ({
children,
rivalPlayerAddress,
Expand Down Expand Up @@ -72,14 +73,19 @@ export const GameField: React.FC<GameFieldPropsI> = ({
}

function makeFinishedGameDescription(finishedGameState: FinishedGameState): string | undefined {
const router = useRouter();

if (finishedGameState.isDraw) {
return 'Game end in a draw';
router.push('/game-result');
return undefined;
}
if (finishedGameState.winner) {
if (isOpponentAddress(finishedGameState.winner)) {
return 'Your opponent wins';
router.push('/game-result');
return undefined;
} else {
return 'You win';
router.push('/game-result');
return undefined;
}
}
}
Expand Down

0 comments on commit 6617747

Please sign in to comment.