From 91df9e05c258ebae55697138b8a8f36d06b81740 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Tue, 12 Sep 2023 17:11:18 -0700 Subject: [PATCH 1/2] Simplify usage of console variables await the data during load so it's available downstream without needing to await. --- src/lib/pages/domains/wizard/step1.svelte | 11 +---------- src/routes/console/+layout.svelte | 5 +---- src/routes/console/+layout.ts | 11 +++++++---- .../settings/updateConfiguration.svelte | 5 +++-- .../templates/template-[template]/+page.svelte | 6 ++++-- .../settings/updateInstallations.svelte | 7 ++++--- src/routes/console/store.ts | 5 +---- 7 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/lib/pages/domains/wizard/step1.svelte b/src/lib/pages/domains/wizard/step1.svelte index 480a585807..2c8a0e8847 100644 --- a/src/lib/pages/domains/wizard/step1.svelte +++ b/src/lib/pages/domains/wizard/step1.svelte @@ -6,21 +6,12 @@ import { sdk } from '$lib/stores/sdk'; import { isSelfHosted } from '$lib/system'; import { func } from '$routes/console/project-[project]/functions/function-[function]/store'; - import { onMount } from 'svelte'; import { ProxyTypes } from '../index.svelte'; import { domain, typeStore } from './store'; import { consoleVariables } from '$routes/console/store'; let error = null; - let isDomainsEnabled = false; - - onMount(async () => { - if (!isSelfHosted) { - return; - } - - isDomainsEnabled = (await $consoleVariables)?._APP_DOMAIN_ENABLED === true; - }); + const isDomainsEnabled = $consoleVariables?._APP_DOMAIN_ENABLED === true; async function createDomain() { try { diff --git a/src/routes/console/+layout.svelte b/src/routes/console/+layout.svelte index c7e0bda5a4..cb94ecde77 100644 --- a/src/routes/console/+layout.svelte +++ b/src/routes/console/+layout.svelte @@ -33,10 +33,7 @@ .join(' '); } - let isAssistantEnabled = false; - onMount(async () => { - isAssistantEnabled = (await $consoleVariables)?._APP_ASSISTANT_ENABLED === true; - }); + const isAssistantEnabled = $consoleVariables?._APP_ASSISTANT_ENABLED === true; $: isOnSettingsLayout = $project?.$id ? $page.url.pathname.includes(`project-${$project.$id}/settings`) diff --git a/src/routes/console/+layout.ts b/src/routes/console/+layout.ts index 8221f5d43d..fdcdec07fb 100644 --- a/src/routes/console/+layout.ts +++ b/src/routes/console/+layout.ts @@ -8,15 +8,18 @@ export const load: LayoutLoad = async ({ fetch, depends }) => { depends(Dependencies.CONSOLE_VARIABLES); const { endpoint, project } = sdk.forConsole.client.config; - const response = await fetch(`${endpoint}/health/version`, { + const versionPromise = fetch(`${endpoint}/health/version`, { headers: { 'X-Appwrite-Project': project } - }); - const data = await response.json(); + }).then((response) => response.json() as { version?: string }); + + const variablesPromise = sdk.forConsole.console.variables(); + + const [data, variables] = await Promise.all([versionPromise, variablesPromise]); return { - consoleVariables: sdk.forConsole.console.variables(), + consoleVariables: variables, version: data?.version ?? null }; }; diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/updateConfiguration.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/updateConfiguration.svelte index e29904e787..40060a0096 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/updateConfiguration.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/updateConfiguration.svelte @@ -49,9 +49,10 @@ import InputSelectSearch from '$lib/elements/forms/inputSelectSearch.svelte'; import { installations } from '$lib/wizards/functions/store'; import { isSelfHosted } from '$lib/system'; - import { consoleVariables, isVcsEnabled } from '$routes/console/store'; + import { consoleVariables } from '$routes/console/store'; const functionId = $page.params.function; + const isVcsEnabled = $consoleVariables?._APP_VCS_ENABLED === true; let entrypoint: string; let commands: string; @@ -271,7 +272,7 @@ {:else} - {#if isSelfHosted && !isVcsEnabled($consoleVariables)} + {#if isSelfHosted && !isVcsEnabled} Installing Git to a self-hosted instance diff --git a/src/routes/console/project-[project]/functions/templates/template-[template]/+page.svelte b/src/routes/console/project-[project]/functions/templates/template-[template]/+page.svelte index 7a8809820b..f76bbf6c30 100644 --- a/src/routes/console/project-[project]/functions/templates/template-[template]/+page.svelte +++ b/src/routes/console/project-[project]/functions/templates/template-[template]/+page.svelte @@ -6,8 +6,10 @@ import { Container } from '$lib/layout'; import { isSelfHosted } from '$lib/system'; import { connectTemplate } from '$lib/wizards/functions/cover.svelte'; - import { consoleVariables, isVcsEnabled } from '$routes/console/store'; + import { consoleVariables } from '$routes/console/store'; import { template } from './store'; + + const isVcsEnabled = $consoleVariables?._APP_VCS_ENABLED === true; @@ -60,7 +62,7 @@

{$template.tagline}

- {#if isSelfHosted && !isVcsEnabled($consoleVariables)} + {#if isSelfHosted && !isVcsEnabled} Cloning templates to a self-hosted instance diff --git a/src/routes/console/project-[project]/settings/updateInstallations.svelte b/src/routes/console/project-[project]/settings/updateInstallations.svelte index a61bd158b3..a3c6d52731 100644 --- a/src/routes/console/project-[project]/settings/updateInstallations.svelte +++ b/src/routes/console/project-[project]/settings/updateInstallations.svelte @@ -29,7 +29,7 @@ import GitDisconnectModal from './GitDisconnectModal.svelte'; import dayjs from 'dayjs'; import { isSelfHosted } from '$lib/system'; - import { consoleVariables, isVcsEnabled } from '$routes/console/store'; + import { consoleVariables } from '$routes/console/store'; export let total: number; export let limit: number; @@ -40,6 +40,7 @@ let showGitDisconnect = false; let showInstallationDropdown: boolean[] = []; let selectedInstallation: Models.Installation; + const isVcsEnabled = $consoleVariables?._APP_VCS_ENABLED === true; function getInstallationLink(installation: Models.Installation) { switch (installation.provider) { @@ -180,7 +181,7 @@ bind:offset /> {:else} - {#if isSelfHosted && !isVcsEnabled($consoleVariables)} + {#if isSelfHosted && !isVcsEnabled} Installing Git to a self-hosted instance @@ -203,7 +204,7 @@