really don't explode when watching an undefined game
This commit is contained in:
parent
0221c7d15d
commit
c5c4559e08
@ -16,23 +16,24 @@ import { computed, ref, watch } from 'vue';
|
|||||||
import type { Game } from '@/lib/game';
|
import type { Game } from '@/lib/game';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
game: Game;
|
game: Game | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
const props = defineProps<Props>();
|
||||||
|
|
||||||
// TODO(zeph): simplify this condition, this should just come in the game state
|
// 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(() => [
|
const roundChips = computed(() => [
|
||||||
{ text: "I", variant: props.game.round === 1 ? 'elevated' : undefined },
|
{ text: "I", variant: props?.game?.round === 1 ? 'elevated' : undefined },
|
||||||
{ text: "II", variant: props.game.round === 2 ? 'elevated' : undefined },
|
{ text: "II", variant: props?.game?.round === 2 ? 'elevated' : undefined },
|
||||||
{ text: "III", variant: props.game.round === 3 ? 'elevated' : undefined },
|
{ text: "III", variant: props?.game?.round === 3 ? 'elevated' : undefined },
|
||||||
] as const)
|
] as const)
|
||||||
|
|
||||||
// TODO(zeph): this probably should just be handled by the server and sent in the dto
|
// TODO(zeph): this probably should just be handled by the server and sent in the dto
|
||||||
|
const game = computed(() => props.game);
|
||||||
const msg = ref<string>('');
|
const msg = ref<string>('');
|
||||||
watch(props.game, (now, was) => {
|
watch(game, (now, was) => {
|
||||||
if (now == null) {
|
if (now == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user