puzzle/src/frontend/views/NewGame.vue

46 lines
1 KiB
Vue
Raw Normal View History

2021-05-17 00:27:47 +02:00
<template>
<div>
<new-game-dialog :images="images" @newGame="onNewGame" />
</div>
</template>
2021-05-13 16:58:21 +02:00
2021-05-17 00:27:47 +02:00
<script lang="ts">
import { defineComponent } from 'vue'
2021-05-13 16:58:21 +02:00
2021-05-17 00:27:47 +02:00
// TODO: maybe move dialog back, now that this is a view on its own
import NewGameDialog from './../components/NewGameDialog.vue'
export default defineComponent({
2021-05-13 16:58:21 +02:00
components: {
NewGameDialog,
},
data() {
return {
images: [],
}
},
async created() {
const res = await fetch('/api/newgame-data')
const json = await res.json()
this.images = json.images
},
methods: {
2021-05-17 00:27:47 +02:00
// TODO: ts GameSettings type
async onNewGame(gameSettings: any) {
2021-05-13 16:58:21 +02:00
const res = await fetch('/newgame', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(gameSettings),
})
if (res.status === 200) {
const game = await res.json()
2021-05-15 11:06:37 +02:00
this.$router.push({ name: 'game', params: { id: game.id } })
2021-05-13 16:58:21 +02:00
}
}
}
2021-05-17 00:27:47 +02:00
})
</script>