Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ThunderDev1 committed Jan 19, 2020
1 parent 67b2f06 commit 980a595
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 8 additions & 6 deletions client/src/components/Podium/Podium.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ export interface PodiumProps {
className?: string
}

const victoryMusicUrl =
'https://statics.blob.core.windows.net/public/victory.mp3'

const Podium: FC<PodiumProps> = ({ players, currentPlayerId, className }) => {
const classes = classnames(className, 'Podium')

const isWinner = players[0].id === currentPlayerId
useEffect(() => {
if (isWinner)
new Audio(
'https://statics.blob.core.windows.net/public/victory.mp3'
).play()
if (isWinner) new Audio(victoryMusicUrl).play()
}, [currentPlayerId, isWinner])

const { width, height } = useWindowSize()

return (
<div className={classes}>
{isWinner && <Confetti width={width} height={height} />}
<h2>Podium</h2>
<ol>
{players.map((player, index) => (
Expand All @@ -39,7 +38,10 @@ const Podium: FC<PodiumProps> = ({ players, currentPlayerId, className }) => {
))}
</ol>
{isWinner ? (
<span className='VictoryMessage'>Vous avez gagné !</span>
<>
<Confetti width={width} height={height} />
<span className='VictoryMessage'>Vous avez gagné !</span>
</>
) : (
'La partie est terminée'
)}
Expand Down
5 changes: 4 additions & 1 deletion client/src/pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const Game: FC<GameProps> = (props: GameProps) => {
return <Podium players={topPlayers} currentPlayerId={currentPlayerId} />
}

if (!currentPlayerId && game.status === GameStatus.ROUND_IN_PROGRESS)
return <p>La partie est en cours, vous ne pouvez la rejoindre.</p>

if (currentPlayerId && game.players.length && hubConnection) {
// The oldest member of the lobby is the host
const isGameHost = game.players[0].id === currentPlayerId
Expand Down Expand Up @@ -106,7 +109,7 @@ const Game: FC<GameProps> = (props: GameProps) => {
}
}
}
return <>La partie est en cours.</>
return null
}

export default Game

0 comments on commit 980a595

Please sign in to comment.