Skip to content

Commit

Permalink
Don't allow negative scores. (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
krazkidd authored Oct 16, 2023
1 parent 18d0691 commit 53e478e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
13 changes: 9 additions & 4 deletions components/scoreboard/ScoreboardTeamTile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ const props = withDefaults(defineProps<{
});
const emit = defineEmits<{
(e: "addRun"): void;
(e: "removeRun"): void;
(e: "incrementScore", payload: number): void;
}>();
function onClick(increment: number) {
if (props.score + increment >= 0) {
emit('incrementScore', increment);
}
}
const cardPassThroughOptions = computed(() => ({
root: {
class: 'accent m-1 w-64',
Expand Down Expand Up @@ -51,7 +56,7 @@ const buttonPassThroughOptions = {
<template #content>
<div class="flex justify-around">
<Button
@click="emit('addRun')"
@click="onClick(1)"
icon="pi pi-caret-up"
severity="success"
rounded
Expand All @@ -62,7 +67,7 @@ const buttonPassThroughOptions = {
/>

<Button
@click="emit('removeRun')"
@click="onClick(-1)"
icon="pi pi-caret-down"
severity="danger"
rounded
Expand Down
4 changes: 2 additions & 2 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ service cloud.firestore {
// only allow writing Scoreboard type
allow write:
if request.resource.data.size() == 2
&& request.resource.data.teamScore is int
&& request.resource.data.otherTeamScore is int;
&& request.resource.data.teamScore is int && request.resource.data.teamScore >= 0
&& request.resource.data.otherTeamScore is int && request.resource.data.otherTeamScore >= 0;
}

match /emotes/{id} {
Expand Down
6 changes: 2 additions & 4 deletions pages/scoreboard/[[id]].vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const fakeTeam = {
:team="team"
:score="scoreboard?.teamScore ?? 0"
:show-buttons="!route.params.id"
@add-run="incrementTeamScore(1)"
@remove-run="incrementTeamScore(-1)"
@increment-score="incrementTeamScore($event)"
class="w-64"
/>

Expand All @@ -56,8 +55,7 @@ const fakeTeam = {
:team="fakeTeam"
:score="scoreboard?.otherTeamScore ?? 0"
:show-buttons="!route.params.id"
@add-run="incrementOtherTeamScore(1)"
@remove-run="incrementOtherTeamScore(-1)"
@increment-score="incrementOtherTeamScore($event)"
class="w-64"
/>
</div>
Expand Down

0 comments on commit 53e478e

Please sign in to comment.