Skip to content

Commit

Permalink
add player's ready notification for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
jajakob committed Jan 6, 2025
1 parent 78c2720 commit 9682b63
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/demo-game/src/pages/admin/games/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
computePeriodStatus,
computeSegmentStatus,
} from '@gbl-uzh/platform/dist/lib/util'
import { useCallback, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import {
ActivateNextPeriodDocument,
ActivateNextSegmentDocument,
Expand Down Expand Up @@ -59,7 +59,7 @@ import {
} from '@uzh-bf/design-system/dist/future'

import { FormikMultiSelectField } from '~/components/fields/FormikMultiSelectField'

import { useToast } from '~/components/ui/use-toast'
import {
DEFAULT_SEED,
GAP_BONDS,
Expand Down Expand Up @@ -123,6 +123,8 @@ function ManageGame() {

const [addCountdown] = useMutation(AddCountdownDocument)

const { toast } = useToast()

const nextPeriod = () =>
activateNextPeriod({
variables: {
Expand All @@ -139,6 +141,19 @@ function ManageGame() {
refetchQueries: [GameDocument],
})

useEffect(() => {
const game = data?.game
if (game?.status !== GameStatus.Running) return

const allPlayersReady = game.players.every((player) => player.isReady)
if (allPlayersReady) {
toast({
title: 'All players are ready!',
description: 'All players are ready to continue.',
})
}
}, [data?.game])

const getButton = useCallback(() => {
const game = data.game
const disabled = game.periods.length === 0
Expand Down

0 comments on commit 9682b63

Please sign in to comment.