From 3a1d55679169d97c34e208a1f24b4239dff246d4 Mon Sep 17 00:00:00 2001 From: kevmodrome Date: Thu, 2 Apr 2020 16:27:19 +0200 Subject: [PATCH] wip: changes initialise function to getPackage and runs once you select application instead of at run-time. --- packages/builder/src/App.svelte | 2 -- packages/builder/src/builderStore/index.js | 1 - .../builder/src/builderStore/store/index.js | 22 +++++----------- .../src/pages/[application]/_layout.svelte | 25 +++++++++++++++++-- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/builder/src/App.svelte b/packages/builder/src/App.svelte index 7f2279fbd8..355bec2484 100644 --- a/packages/builder/src/App.svelte +++ b/packages/builder/src/App.svelte @@ -7,8 +7,6 @@ showAppNotification, } from "components/common/AppNotification.svelte" - let init = initialise() - function showErrorBanner() { showAppNotification({ status: "danger", diff --git a/packages/builder/src/builderStore/index.js b/packages/builder/src/builderStore/index.js index b3556cff93..065e40466e 100644 --- a/packages/builder/src/builderStore/index.js +++ b/packages/builder/src/builderStore/index.js @@ -10,7 +10,6 @@ export const initialise = async () => { if (process.env.NODE_ENV === "production") { LogRocket.init("knlald/budibase") } - await store.initialise() } catch (err) { console.log(err) } diff --git a/packages/builder/src/builderStore/store/index.js b/packages/builder/src/builderStore/store/index.js index dcd13aab3b..0fc74ff553 100644 --- a/packages/builder/src/builderStore/store/index.js +++ b/packages/builder/src/builderStore/store/index.js @@ -50,7 +50,7 @@ export const getStore = () => { const store = writable(initial) - store.initialise = initialise(store, initial) + store.setPackage = setPackage(store, initial) store.newChildRecord = backendStoreActions.newRecord(store, false) store.newRootRecord = backendStoreActions.newRecord(store, true) @@ -101,22 +101,12 @@ export const getStore = () => { export default getStore -const initialise = (store, initial) => async () => { - if (!appname) { - initial.apps = await api.get(`/_builder/api/apps`).then(r => r.json()) - initial.hasAppPackage = false - store.set(initial) - return initial - } - - const pkg = await api - .get(`/_builder/api/${appname}/appPackage`) - .then(r => r.json()) +const setPackage = (store, initial) => async (pkg) => { const [main_screens, unauth_screens] = await Promise.all([ - api.get(`/_builder/api/${appname}/pages/main/screens`).then(r => r.json()), + api.get(`/_builder/api/${pkg.application.name}/pages/main/screens`).then(r => r.json()), api - .get(`/_builder/api/${appname}/pages/unauthenticated/screens`) + .get(`/_builder/api/${pkg.application.name}/pages/unauthenticated/screens`) .then(r => r.json()), ]) @@ -131,12 +121,12 @@ const initialise = (store, initial) => async () => { }, } - initial.libraries = await loadLibs(appname, pkg) + initial.libraries = await loadLibs(pkg.application.name, pkg) initial.loadLibraryUrls = pageName => { const libs = libUrlsForPreview(pkg, pageName) return libs } - initial.appname = appname + initial.appname = pkg.application.name initial.pages = pkg.pages initial.hasAppPackage = true initial.hierarchy = pkg.appDefinition.hierarchy diff --git a/packages/builder/src/pages/[application]/_layout.svelte b/packages/builder/src/pages/[application]/_layout.svelte index 11f65a8c85..bb119f1082 100644 --- a/packages/builder/src/pages/[application]/_layout.svelte +++ b/packages/builder/src/pages/[application]/_layout.svelte @@ -1,10 +1,27 @@ @@ -48,7 +65,11 @@ - + {#await promise} + should probably load this in a nicer way + {:then} + + {/await}