From e7b973954a5c7220139fe6172effa404a2678a76 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 12 Nov 2024 11:06:48 +0100 Subject: [PATCH] get config from server --- web/src/components/SearchBox.vue | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/web/src/components/SearchBox.vue b/web/src/components/SearchBox.vue index 20f721a6..56078b29 100644 --- a/web/src/components/SearchBox.vue +++ b/web/src/components/SearchBox.vue @@ -106,11 +106,14 @@ import { onMounted, onBeforeUnmount, watch, + onBeforeMount, + reactive, } from "vue"; import { useRoute, useRouter } from "vue-router/composables"; import { useRootStore } from "@/stores"; import { tagNameForURI } from "@/filters"; import { VTextField } from "vuetify/lib"; +import { isClientConfig } from "@/apiClient.guard"; const store = useRootStore(); const route = useRoute(); @@ -188,10 +191,12 @@ const searchBoxFieldRect = computed(() => { EventBus.on("setSearchTerm", setSearchTerm); +const reactiveStore = reactive(store); + watch( - [route,searchBoxFieldRect], + [route,searchBoxField,reactiveStore], () => { - if (!route.query.q) { + if (route && searchBoxField && reactiveStore.clientConfig && !route.query.q) { var input = searchBoxField.value?.$el.querySelector("input"); setSearchBox(" ltime:-1h:"); input?.focus(); @@ -230,13 +235,16 @@ watch( { immediate: true }, ); -onMounted(() => { +onBeforeMount(() => { store.getClientConfig().catch((err: string) => { - EventBus.emit("showError", `Failed to get clientconfig: ${err}`); + EventBus.emit("showError", `Failed to update converters: ${err}`); }); store.updateConverters().catch((err: string) => { EventBus.emit("showError", `Failed to update converters: ${err}`); }); +}); + +onMounted(() => { const keyListener = (e: KeyboardEvent) => { if (e.target === null || !(e.target instanceof Element)) return; if (["input", "textarea"].includes(e.target.tagName.toLowerCase())) return;