From c5c4559e087ccd29314efdfb501cce12cc7d1cd3 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Fri, 2 Feb 2024 19:39:50 -0600 Subject: [PATCH] really don't explode when watching an undefined game --- site/src/components/GameStatus.vue | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/site/src/components/GameStatus.vue b/site/src/components/GameStatus.vue index 9b5ee9a..090ccb8 100644 --- a/site/src/components/GameStatus.vue +++ b/site/src/components/GameStatus.vue @@ -16,23 +16,24 @@ import { computed, ref, watch } from 'vue'; import type { Game } from '@/lib/game'; export interface Props { - game: Game; + game: Game | undefined; } const props = defineProps(); // TODO(zeph): simplify this condition, this should just come in the game state -const gameOn = computed(() => props.game.round < 3 || props.game.players.every((p) => p.hp > 0)) +const gameOn = computed(() => (props?.game?.round ?? 0 < 3) || (props?.game?.players?.every((p) => p.hp > 0))) const roundChips = computed(() => [ - { text: "I", variant: props.game.round === 1 ? 'elevated' : undefined }, - { text: "II", variant: props.game.round === 2 ? 'elevated' : undefined }, - { text: "III", variant: props.game.round === 3 ? 'elevated' : undefined }, + { text: "I", variant: props?.game?.round === 1 ? 'elevated' : undefined }, + { text: "II", variant: props?.game?.round === 2 ? 'elevated' : undefined }, + { text: "III", variant: props?.game?.round === 3 ? 'elevated' : undefined }, ] as const) // TODO(zeph): this probably should just be handled by the server and sent in the dto +const game = computed(() => props.game); const msg = ref(''); -watch(props.game, (now, was) => { +watch(game, (now, was) => { if (now == null) { return; }