Skip to content

Commit

Permalink
Merge pull request #122 from daithihearn/bugfix/admin-game-stats
Browse files Browse the repository at this point in the history
Handling errors
  • Loading branch information
daithihearn authored Feb 26, 2023
2 parents 233f941 + 37e9473 commit bfec946
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/GameStats/PlayerSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useSnackbar } from "notistack"
import { useCallback, useEffect, useState } from "react"
import {
Dropdown,
Expand All @@ -17,6 +18,7 @@ const PlayerSwitcher: React.FC = () => {
const players = useAppSelector(getPlayerProfiles)
const [showDropdown, setShowDropdown] = useState(false)
const [currentPlayer, setCurrentPlayer] = useState<PlayerProfile>()
const { enqueueSnackbar } = useSnackbar()

const toggleDropdown = useCallback(
() => setShowDropdown(!showDropdown),
Expand All @@ -29,7 +31,14 @@ const PlayerSwitcher: React.FC = () => {
}, [myProfile])

useEffect(() => {
dispatch(StatsService.gameStatsForPlayer(currentPlayer?.id))
if (currentPlayer)
dispatch(StatsService.gameStatsForPlayer(currentPlayer.id)).catch(
e =>
enqueueSnackbar(
`Failed to get game stats for player ${currentPlayer.name}`,
{ variant: "error" },
),
)
}, [currentPlayer])

return (
Expand Down

0 comments on commit bfec946

Please sign in to comment.