From af0129b5988d199cec35bff008bd845c421659ba Mon Sep 17 00:00:00 2001 From: wvffle Date: Wed, 20 Jul 2022 15:28:48 +0000 Subject: [PATCH] Simplify SetInstanceModal logic --- front/src/components/SetInstanceModal.vue | 178 ++++++++-------------- front/src/store/instance.ts | 9 +- 2 files changed, 69 insertions(+), 118 deletions(-) diff --git a/front/src/components/SetInstanceModal.vue b/front/src/components/SetInstanceModal.vue index 7114e4551..fb2647cac 100644 --- a/front/src/components/SetInstanceModal.vue +++ b/front/src/components/SetInstanceModal.vue @@ -1,6 +1,67 @@ + + - - diff --git a/front/src/store/instance.ts b/front/src/store/instance.ts index 7ac0da73a..519a8c6af 100644 --- a/front/src/store/instance.ts +++ b/front/src/store/instance.ts @@ -53,13 +53,12 @@ const logger = useLogger() // 1. use the url provided in settings.json, if any // 2. use the url specified when building via VUE_APP_INSTANCE_URL // 3. use the current url -const instanceUrl = import.meta.env.VUE_APP_INSTANCE_URL as string || location.origin +const instanceUrl = import.meta.env.VUE_APP_INSTANCE_URL as string ?? location.origin const store: Module = { namespaced: true, state: { frontSettings: { - // TODO (wvffle): Remove all checks if the variable exists defaultServerUrl: instanceUrl, additionalStylesheets: [] }, @@ -143,10 +142,10 @@ const store: Module = { relativeUrl = relativeUrl.slice(1) } - const instanceUrl = state.instanceUrl ?? location.origin - return instanceUrl + relativeUrl + return (state.instanceUrl ?? instanceUrl) + relativeUrl }, - domain: (state) => new URL(state.instanceUrl ?? location.origin).hostname + domain: (state) => new URL(state.instanceUrl ?? instanceUrl).hostname, + defaultInstance: () => instanceUrl }, actions: { setUrl ({ commit }, url) {