From bd0c4e4abd728d17262f5a4aca6acc61e39c8fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Sat, 4 Nov 2023 15:58:31 +0000 Subject: [PATCH 1/3] improve vue app lifecycle --- ui/src/App.vue | 4 ---- ui/src/main.ts | 4 ++++ ui/src/plugins/advent22.ts | 4 +--- ui/src/plugins/store.ts | 21 +++++++++++++-------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/ui/src/App.vue b/ui/src/App.vue index dda4ded..b975ac3 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -51,10 +51,6 @@ import UserView from "./components/UserView.vue"; }) export default class extends Vue { public readonly store = advent22Store(); - - public mounted(): void { - this.store.init(); - } } diff --git a/ui/src/main.ts b/ui/src/main.ts index 87f611e..6e719e6 100644 --- a/ui/src/main.ts +++ b/ui/src/main.ts @@ -1,5 +1,6 @@ import { Advent22Plugin } from "@/plugins/advent22"; import { FontAwesomePlugin } from "@/plugins/fontawesome"; +import { advent22Store } from "@/plugins/store"; import { createPinia } from "pinia"; import { createApp } from "vue"; import App from "./App.vue"; @@ -11,4 +12,7 @@ app.use(Advent22Plugin); app.use(FontAwesomePlugin); app.use(createPinia()); +const store = advent22Store(); +store.init(app.config.globalProperties.$advent22); + app.mount("#app"); diff --git a/ui/src/plugins/advent22.ts b/ui/src/plugins/advent22.ts index d9d3152..a3aba49 100644 --- a/ui/src/plugins/advent22.ts +++ b/ui/src/plugins/advent22.ts @@ -156,10 +156,8 @@ export class Advent22 { } } -export const ADVENT22 = new Advent22(); - export const Advent22Plugin: Plugin = { install(app: App) { - app.config.globalProperties.$advent22 = ADVENT22; + app.config.globalProperties.$advent22 = new Advent22(); }, }; diff --git a/ui/src/plugins/store.ts b/ui/src/plugins/store.ts index 6d4b347..0cba139 100644 --- a/ui/src/plugins/store.ts +++ b/ui/src/plugins/store.ts @@ -1,5 +1,5 @@ import { Credentials, DoorsSaved, SiteConfigModel } from "@/lib/api"; -import { ADVENT22 } from "@/plugins/advent22"; +import { Advent22 } from "@/plugins/advent22"; import { AxiosBasicCredentials } from "axios"; import { acceptHMRUpdate, defineStore } from "pinia"; @@ -10,6 +10,7 @@ export const advent22Store = defineStore({ id: "advent22", state: () => ({ + advent22: {} as Advent22, api_creds: empty_creds(), is_touch_device: check_touch_device(), is_admin: false, @@ -31,8 +32,11 @@ export const advent22Store = defineStore({ }, actions: { - init(): void { - ADVENT22.api_get_blob("user/favicon") + init(advent22: Advent22): void { + this.advent22 = advent22; + + advent22 + .api_get_blob("user/favicon") .then((favicon_src) => { const link: HTMLLinkElement = document.querySelector("link[rel*='icon']") || @@ -47,9 +51,9 @@ export const advent22Store = defineStore({ .catch(() => {}); Promise.all([ - ADVENT22.api_get("user/site_config"), - ADVENT22.api_get("user/doors"), - ADVENT22.api_get("user/next_door"), + advent22.api_get("user/site_config"), + advent22.api_get("user/doors"), + advent22.api_get("user/next_door"), ]) .then(([site_config, user_doors, next_door]) => { document.title = site_config.title; @@ -63,14 +67,15 @@ export const advent22Store = defineStore({ if (next_door !== null) this.next_door_target = Date.now() + next_door; }) - .catch(ADVENT22.alert_user_error); + .catch(advent22.alert_user_error); }, login(creds: Credentials = empty_creds()): Promise { this.api_creds = creds; return new Promise((resolve, reject) => { - ADVENT22.api_get("admin/is_admin") + this.advent22 + .api_get("admin/is_admin") .then((is_admin) => { this.is_admin = is_admin; resolve(is_admin); From 9b34b9de8cbb8263643f9ffe2ced6de957161bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Sat, 4 Nov 2023 16:01:58 +0000 Subject: [PATCH 2/3] preliminary app name and noscript message --- ui/public/index.html | 2 +- ui/src/plugins/store.ts | 4 ++-- ui/vue.config.js | 15 +++++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ui/public/index.html b/ui/public/index.html index 3e5a139..1f246a5 100644 --- a/ui/public/index.html +++ b/ui/public/index.html @@ -9,7 +9,7 @@
diff --git a/ui/src/plugins/store.ts b/ui/src/plugins/store.ts index 0cba139..891223a 100644 --- a/ui/src/plugins/store.ts +++ b/ui/src/plugins/store.ts @@ -15,8 +15,8 @@ export const advent22Store = defineStore({ is_touch_device: check_touch_device(), is_admin: false, site_config: { - title: "Adventskalender", - subtitle: "Lorem Ipsum", + title: document.title, + subtitle: "", content: "", footer: "", } as SiteConfigModel, diff --git a/ui/vue.config.js b/ui/vue.config.js index 0b8c429..75ec838 100644 --- a/ui/vue.config.js +++ b/ui/vue.config.js @@ -1,7 +1,14 @@ -const { defineConfig } = require('@vue/cli-service') +const { defineConfig } = require("@vue/cli-service"); + module.exports = defineConfig({ transpileDependencies: true, devServer: { - host: 'localhost', - } -}) + host: "localhost", + }, + pages: { + index: { + entry: "src/main.ts", + title: "Kalender-Gewinnspiel", + }, + }, +}); From 11cb3fef38eee2ce35d8f7970dfc9b8f357e55d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Sat, 4 Nov 2023 16:12:45 +0000 Subject: [PATCH 3/3] UserView layout improvement --- ui/src/components/UserView.vue | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ui/src/components/UserView.vue b/ui/src/components/UserView.vue index 4ca9138..3b99d47 100644 --- a/ui/src/components/UserView.vue +++ b/ui/src/components/UserView.vue @@ -1,11 +1,19 @@