Reimplement config as single object in global store
authorAdam Dullage <redacted>
Thu, 12 Sep 2024 19:17:42 +0000 (20:17 +0100)
committerAdam Dullage <redacted>
Thu, 12 Sep 2024 19:17:42 +0000 (20:17 +0100)
client/App.vue
client/globalStore.js
client/partials/NavBar.vue
client/views/Home.vue
client/views/LogIn.vue
client/views/Note.vue

index 1d986715ec30e8cadeb1ccbc707935296e4ae5d9..601e2a179184e1bb1cdae33d322aa0bce4b7fce8 100644 (file)
@@ -48,8 +48,7 @@ Mousetrap.bind("/", () => {
 \r
 getConfig()\r
   .then((data) => {\r
-    globalStore.authType = data.authType;\r
-    globalStore.hideRecentlyModified = data.hideRecentlyModified;\r
+    globalStore.config = data;\r
     loadingIndicator.value.setLoaded();\r
   })\r
   .catch((error) => {\r
index 23d030329e2a3287db35b7b4064fb357ee7afcd2..f58a752c20e56554d7271220bdb9422af4298786 100644 (file)
@@ -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 };
 });
index 9fdc5cd88b5cd20d410d5eadbaa0d65be41dce15..ed7f0980be3ab5a814e005eebb7820eaad90a5cd 100644 (file)
@@ -87,7 +87,7 @@ const menuItems = [
 ];\r
 \r
 const showNewButton = computed(() => {\r
-  return globalStore.authType !== authTypes.readOnly;\r
+  return globalStore.config.authType !== authTypes.readOnly;\r
 });\r
 \r
 function logOut() {\r
@@ -100,6 +100,6 @@ function toggleMenu(event) {
 }\r
 \r
 function showLogOutButton() {\r
-  return ![authTypes.none, authTypes.readOnly].includes(globalStore.authType);\r
+  return ![authTypes.none, authTypes.readOnly].includes(globalStore.config.authType);\r
 }\r
 </script>\r
index 2a00b2c42a54b5b2e670615edd8f8c1a16d0219e..8b82aaee4c8b7f0b194741c8cb15cde6d18b9887 100644 (file)
@@ -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);
 </script>
index 3a709f35221a3e18b607b92f0e4a3a4ca42f1868..605aebb1a7b0a7622d77ea995ae9de818a4fe963 100644 (file)
@@ -20,7 +20,7 @@
         required
       />
       <TextInput
-        v-if="globalStore.authType == authTypes.totp"
+        v-if="globalStore.config.authType == authTypes.totp"
         v-model="totp"
         id="one-time-code"
         placeholder="2FA Code"
@@ -98,14 +98,7 @@ function logIn() {
 }
 
 // Redirect to home if authentication is disabled.
-// Implemented as a watch to allow for delayed config load.
-watch(
-  () => globalStore.authType,
-  () => {
-    if (globalStore.authType === authTypes.none) {
-      router.push({ name: "home" });
-    }
-  },
-  { immediate: true },
-);
+if (globalStore.config.authType === authTypes.none) {
+  router.push({ name: "home" });
+}
 </script>
index b4907bab9e8080af3e31dd0c725ba4f374d51fcb..ff3b206c0b49531119b965bcf02e9d6168b4bc59 100644 (file)
@@ -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();
git clone https://git.99rst.org/PROJECT