only allow to start game when image and tiles are given

This commit is contained in:
Zutatensuppe 2021-05-05 22:22:34 +02:00
parent 46ba272226
commit 7eb942e773

View file

@ -47,7 +47,7 @@ export default {
</tr> </tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<span class="btn" :class="" @click="onNewGameClick">Start new game</span> <button class="btn" :disabled="!canStartNewGame" :class="" @click="onNewGameClick">Start new game</button>
</td> </td>
</tr> </tr>
</table> </table>
@ -80,6 +80,20 @@ export default {
this.gamesFinished = json.gamesFinished this.gamesFinished = json.gamesFinished
this.images = json.images this.images = json.images
}, },
computed: {
scoreModeInt () {
return parseInt(this.scoreMode, 10)
},
tilesInt () {
return parseInt(this.tiles, 10)
},
canStartNewGame () {
if (!this.tilesInt || !this.image || ![0, 1].includes(this.scoreModeInt)) {
return false
}
return true
},
},
methods: { methods: {
time(start, end) { time(start, end) {
const icon = end ? '🏁' : '⏳' const icon = end ? '🏁' : '⏳'
@ -99,9 +113,9 @@ export default {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify({
tiles: this.tiles, tiles: this.tilesInt,
image: this.image, image: this.image,
scoreMode: parseInt(this.scoreMode, 10), scoreMode: this.scoreModeInt,
}), }),
}) })
if (res.status === 200) { if (res.status === 200) {