From: Adam Dullage Date: Thu, 12 Sep 2024 19:17:42 +0000 (+0100) Subject: Reimplement config as single object in global store X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=e2c8e40ccaf4b9ce13c70c401d6fb5f3adfc241d;p=flatnotes.git Reimplement config as single object in global store --- diff --git a/client/App.vue b/client/App.vue index 1d98671..601e2a1 100644 --- a/client/App.vue +++ b/client/App.vue @@ -48,8 +48,7 @@ Mousetrap.bind("/", () => { getConfig() .then((data) => { - globalStore.authType = data.authType; - globalStore.hideRecentlyModified = data.hideRecentlyModified; + globalStore.config = data; loadingIndicator.value.setLoaded(); }) .catch((error) => { diff --git a/client/globalStore.js b/client/globalStore.js index 23d0303..f58a752 100644 --- a/client/globalStore.js +++ b/client/globalStore.js @@ -1,11 +1,8 @@ -import * as constants from "./constants.js"; - import { defineStore } from "pinia"; import { ref } from "vue"; export const useGlobalStore = defineStore("global", () => { - const authType = ref(constants.authTypes.password); - const hideRecentlyModified = ref(true); + const config = ref({}); - return { authType, hideRecentlyModified }; + return { config }; }); diff --git a/client/partials/NavBar.vue b/client/partials/NavBar.vue index 9fdc5cd..ed7f098 100644 --- a/client/partials/NavBar.vue +++ b/client/partials/NavBar.vue @@ -87,7 +87,7 @@ const menuItems = [ ]; const showNewButton = computed(() => { - return globalStore.authType !== authTypes.readOnly; + return globalStore.config.authType !== authTypes.readOnly; }); function logOut() { @@ -100,6 +100,6 @@ function toggleMenu(event) { } function showLogOutButton() { - return ![authTypes.none, authTypes.readOnly].includes(globalStore.authType); + return ![authTypes.none, authTypes.readOnly].includes(globalStore.config.authType); } diff --git a/client/views/Home.vue b/client/views/Home.vue index 2a00b2c..8b82aae 100644 --- a/client/views/Home.vue +++ b/client/views/Home.vue @@ -47,7 +47,7 @@ const notes = ref([]); const toast = useToast(); function init() { - if (globalStore.hideRecentlyModified) { + if (globalStore.config.hideRecentlyModified) { return; } getNotes("*", "lastModified", "desc", 5) @@ -66,6 +66,6 @@ function init() { } // Watch to allow for delayed config load. -watch(() => globalStore.hideRecentlyModified, init); +watch(() => globalStore.config.hideRecentlyModified, init); onMounted(init); diff --git a/client/views/LogIn.vue b/client/views/LogIn.vue index 3a709f3..605aebb 100644 --- a/client/views/LogIn.vue +++ b/client/views/LogIn.vue @@ -20,7 +20,7 @@ required /> globalStore.authType, - () => { - if (globalStore.authType === authTypes.none) { - router.push({ name: "home" }); - } - }, - { immediate: true }, -); +if (globalStore.config.authType === authTypes.none) { + router.push({ name: "home" }); +} diff --git a/client/views/Note.vue b/client/views/Note.vue index b4907ba..ff3b206 100644 --- a/client/views/Note.vue +++ b/client/views/Note.vue @@ -149,7 +149,9 @@ const props = defineProps({ title: String, }); -const canModify = computed(() => globalStore.authType != authTypes.readOnly); +const canModify = computed( + () => globalStore.config.authType != authTypes.readOnly, +); let contentChangedTimeout = null; const editMode = ref(false); const globalStore = useGlobalStore();