From 3da3f7f63947a92ade6a1bc3662957431728c0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 9 Nov 2023 18:19:48 +0000 Subject: [PATCH] put store.api_creds into localStorage - don't need beforeunload in AdminView anymore --- ui/package.json | 1 + ui/src/components/admin/AdminView.vue | 13 +----------- ui/src/plugins/store.ts | 13 ++++++++---- ui/yarn.lock | 29 ++++++++++++++++++++++++++- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/ui/package.json b/ui/package.json index 55d0d8c..c16c5b0 100644 --- a/ui/package.json +++ b/ui/package.json @@ -26,6 +26,7 @@ "@vue/cli-service": "~5.0.0", "@vue/eslint-config-typescript": "^12.0.0", "@vue/test-utils": "^2.4.1", + "@vueuse/core": "^10.5.0", "axios": "^1.5.0", "bulma": "^0.9.4", "bulma-prefers-dark": "^0.1.0-beta.1", diff --git a/ui/src/components/admin/AdminView.vue b/ui/src/components/admin/AdminView.vue index f417c08..5c771c9 100644 --- a/ui/src/components/admin/AdminView.vue +++ b/ui/src/components/admin/AdminView.vue @@ -18,16 +18,5 @@ import DoorMapEditor from "./DoorMapEditor.vue"; DoorMapEditor, }, }) -export default class extends Vue { - private old_handler = window.onbeforeunload; - private confirm_handler = () => ""; - - public mounted(): void { - window.onbeforeunload = this.confirm_handler; - } - - public beforeUnmount(): void { - window.onbeforeunload = this.old_handler; - } -} +export default class extends Vue {} diff --git a/ui/src/plugins/store.ts b/ui/src/plugins/store.ts index 5a35f09..9b88924 100644 --- a/ui/src/plugins/store.ts +++ b/ui/src/plugins/store.ts @@ -1,5 +1,6 @@ import { Credentials, DoorsSaved, SiteConfigModel } from "@/lib/api"; import { Advent22 } from "@/plugins/advent22"; +import { useLocalStorage } from "@vueuse/core"; import { AxiosBasicCredentials } from "axios"; import { acceptHMRUpdate, defineStore } from "pinia"; @@ -14,7 +15,7 @@ export const advent22Store = defineStore({ state: () => ({ advent22: {} as Advent22, - api_creds: ["", ""] as Credentials, + api_creds: useLocalStorage("advent22/auth", ["", ""]), is_touch_device: window.matchMedia("(any-hover: none)").matches || "ontouchstart" in window || @@ -42,6 +43,7 @@ export const advent22Store = defineStore({ actions: { init(advent22: Advent22): void { this.advent22 = advent22; + this.update_is_admin(); advent22 .api_get_blob("user/favicon") @@ -78,9 +80,7 @@ export const advent22Store = defineStore({ .catch(advent22.alert_user_error); }, - login(creds: Credentials): Promise { - this.api_creds = creds; - + update_is_admin(): Promise { return new Promise((resolve, reject) => { this.advent22 .api_get("admin/is_admin") @@ -92,6 +92,11 @@ export const advent22Store = defineStore({ }); }, + login(creds: Credentials): Promise { + this.api_creds = creds; + return this.update_is_admin(); + }, + logout(): Promise { return this.login(["", ""]); }, diff --git a/ui/yarn.lock b/ui/yarn.lock index 1503306..c32e29f 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -1427,6 +1427,11 @@ dependencies: "@types/node" "*" +"@types/web-bluetooth@^0.0.18": + version "0.0.18" + resolved "https://registry.yarnpkg.com/@types/web-bluetooth/-/web-bluetooth-0.0.18.tgz#74bd1c8fd3a2058cb6fc76b188fcded50a83d866" + integrity sha512-v/ZHEj9xh82usl8LMR3GarzFY1IrbXJw5L4QfQhokjRV91q+SelFqxQWSep1ucXEZ22+dSTwLFkXeur25sPIbw== + "@types/webpack-env@^1.15.2": version "1.18.1" resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.1.tgz#49699bb508961e14a3bfb68c78cd87b296889d1d" @@ -1940,6 +1945,28 @@ resolved "https://registry.yarnpkg.com/@vue/web-component-wrapper/-/web-component-wrapper-1.3.0.tgz#b6b40a7625429d2bd7c2281ddba601ed05dc7f1a" integrity sha512-Iu8Tbg3f+emIIMmI2ycSI8QcEuAUgPTgHwesDU1eKMLE4YC/c/sFbGc70QgMq31ijRftV0R7vCm9co6rldCeOA== +"@vueuse/core@^10.5.0": + version "10.5.0" + resolved "https://registry.yarnpkg.com/@vueuse/core/-/core-10.5.0.tgz#04d1e6d26592bb997bb755a4830ea7583c3e8612" + integrity sha512-z/tI2eSvxwLRjOhDm0h/SXAjNm8N5ld6/SC/JQs6o6kpJ6Ya50LnEL8g5hoYu005i28L0zqB5L5yAl8Jl26K3A== + dependencies: + "@types/web-bluetooth" "^0.0.18" + "@vueuse/metadata" "10.5.0" + "@vueuse/shared" "10.5.0" + vue-demi ">=0.14.6" + +"@vueuse/metadata@10.5.0": + version "10.5.0" + resolved "https://registry.yarnpkg.com/@vueuse/metadata/-/metadata-10.5.0.tgz#7501a88cf5cbf7a515a03f0b8bbe3cecf30cad11" + integrity sha512-fEbElR+MaIYyCkeM0SzWkdoMtOpIwO72x8WsZHRE7IggiOlILttqttM69AS13nrDxosnDBYdyy3C5mR1LCxHsw== + +"@vueuse/shared@10.5.0": + version "10.5.0" + resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-10.5.0.tgz#b3ac8c190a5dae41db5e1b60fe304a9b4247393c" + integrity sha512-18iyxbbHYLst9MqU1X1QNdMHIjks6wC7XTVf0KNOv5es/Ms6gjVFCAAWTVP2JStuGqydg3DT+ExpFORUEi9yhg== + dependencies: + vue-demi ">=0.14.6" + "@webassemblyjs/ast@1.11.6", "@webassemblyjs/ast@^1.11.5": version "1.11.6" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24" @@ -6848,7 +6875,7 @@ vue-component-type-helpers@1.8.4: resolved "https://registry.yarnpkg.com/vue-component-type-helpers/-/vue-component-type-helpers-1.8.4.tgz#302d85fac912519cdf0dd2fb51402e5215d85628" integrity sha512-6bnLkn8O0JJyiFSIF0EfCogzeqNXpnjJ0vW/SZzNHfe6sPx30lTtTXlE5TFs2qhJlAtDFybStVNpL73cPe3OMQ== -vue-demi@>=0.14.5: +vue-demi@>=0.14.5, vue-demi@>=0.14.6: version "0.14.6" resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.14.6.tgz#dc706582851dc1cdc17a0054f4fec2eb6df74c92" integrity sha512-8QA7wrYSHKaYgUxDA5ZC24w+eHm3sYCbp0EzcDwKqN3p6HqtTCGR/GVsPyZW92unff4UlcSh++lmqDWN3ZIq4w==