Merged changes
This commit is contained in:
parent
269faca609
commit
e02555234f
3 changed files with 17 additions and 10 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
<Game :class="user ? '' : 'hidden'" v-bind:user-id=this.userId class="col"
|
<Game :class="user ? '' : 'hidden'" v-bind:user-id=this.userId class="col"
|
||||||
@gameFinished="this.updateUserScores()">
|
@gameFinished="this.updateUserScores()">
|
||||||
</Game>
|
</Game>
|
||||||
<Login v-if="!user" @userChange="(event) => {this.user = event; this.userId = this.user.id}">
|
<Login v-if="!user" @userChange="(event) => {this.updateUser(event)}">
|
||||||
</Login>
|
</Login>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -35,6 +35,7 @@ import "bootstrap/dist/css/bootstrap.min.css";
|
||||||
import "bootstrap/dist/js/bootstrap.min.js";
|
import "bootstrap/dist/js/bootstrap.min.js";
|
||||||
import Login from "@/components/Login.vue";
|
import Login from "@/components/Login.vue";
|
||||||
import {Rest} from "@/model/Rest";
|
import {Rest} from "@/model/Rest";
|
||||||
|
import {User} from "@/model/User";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'App',
|
name: 'App',
|
||||||
|
|
@ -48,25 +49,32 @@ export default defineComponent({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
userScores: {},
|
userScores: {},
|
||||||
userId: 1,
|
userId: -1,
|
||||||
user: null,
|
user: null as User | null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
async fetchFromApi(path: string, method: "GET" | "POST") {
|
async fetchFromApi(path: string, method: "GET" | "POST") {
|
||||||
let res: Response = await fetch(Rest.URL + path, {method: method,});
|
let res: Response = await fetch(Rest.URL + path, {method: method,});
|
||||||
return await res.json();
|
return await res.json();
|
||||||
},
|
},
|
||||||
async fetchUserScores() {
|
async fetchUserScores() {
|
||||||
|
if (this.userId == -1) return;
|
||||||
return await this.fetchFromApi(`/user/${this.userId}/scores`, "GET");
|
return await this.fetchFromApi(`/user/${this.userId}/scores`, "GET");
|
||||||
},
|
},
|
||||||
async updateUserScores() {
|
async updateUserScores() {
|
||||||
this.userScores = await this.fetchUserScores();
|
this.userScores = await this.fetchUserScores();
|
||||||
},
|
},
|
||||||
},
|
async updateUser(user: User) {
|
||||||
async created() {
|
if (user) {
|
||||||
|
this.user = user;
|
||||||
|
this.userId = user.id ?? -1;
|
||||||
await this.updateUserScores();
|
await this.updateUserScores();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,8 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async setUser() {
|
async setUser() {
|
||||||
let user;
|
let user;
|
||||||
try {
|
|
||||||
user = await User.getByName(this.username);
|
user = await User.getByName(this.username);
|
||||||
} catch (e) {
|
if (user.errors) {
|
||||||
user = await User.create(this.username);
|
user = await User.create(this.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export class Rest {
|
export class Rest {
|
||||||
static readonly URL = 'http://localhost:3000';
|
static readonly URL = 'http://139.144.178.216:3000';
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue