From e02555234f8444bc0b0b895829d68dc357f0288d Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Sat, 21 Jan 2023 08:03:01 +0100 Subject: [PATCH] Merged changes --- frontend/src/App.vue | 20 ++++++++++++++------ frontend/src/components/Login.vue | 5 ++--- frontend/src/model/Rest.ts | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index baa9b1b..b16c93a 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -10,7 +10,7 @@ - +
@@ -35,6 +35,7 @@ import "bootstrap/dist/css/bootstrap.min.css"; import "bootstrap/dist/js/bootstrap.min.js"; import Login from "@/components/Login.vue"; import {Rest} from "@/model/Rest"; +import {User} from "@/model/User"; export default defineComponent({ name: 'App', @@ -48,25 +49,32 @@ export default defineComponent({ data() { return { userScores: {}, - userId: 1, - user: null, + userId: -1, + user: null as User | null, } }, + + methods: { async fetchFromApi(path: string, method: "GET" | "POST") { let res: Response = await fetch(Rest.URL + path, {method: method,}); return await res.json(); }, async fetchUserScores() { + if (this.userId == -1) return; return await this.fetchFromApi(`/user/${this.userId}/scores`, "GET"); }, async updateUserScores() { this.userScores = await this.fetchUserScores(); }, + async updateUser(user: User) { + if (user) { + this.user = user; + this.userId = user.id ?? -1; + await this.updateUserScores(); + } + } }, - async created() { - await this.updateUserScores(); - } }); diff --git a/frontend/src/components/Login.vue b/frontend/src/components/Login.vue index e08e449..9c935b8 100644 --- a/frontend/src/components/Login.vue +++ b/frontend/src/components/Login.vue @@ -26,9 +26,8 @@ export default { methods: { async setUser() { let user; - try { - user = await User.getByName(this.username); - } catch (e) { + user = await User.getByName(this.username); + if (user.errors) { user = await User.create(this.username); } diff --git a/frontend/src/model/Rest.ts b/frontend/src/model/Rest.ts index 53b902e..04d93cc 100644 --- a/frontend/src/model/Rest.ts +++ b/frontend/src/model/Rest.ts @@ -1,3 +1,3 @@ export class Rest { - static readonly URL = 'http://localhost:3000'; + static readonly URL = 'http://139.144.178.216:3000'; } \ No newline at end of file