From 77b8f8fa8e71e9027ccc605e1ac37987c16ada6d Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 6 Apr 2020 17:06:04 +0100 Subject: [PATCH] show screenslot if there's no screens --- .../components/userInterface/CurrentItemPreview.svelte | 4 +++- packages/client/src/createApp.js | 5 +++-- packages/client/src/render/screenRouter.js | 8 +++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/components/userInterface/CurrentItemPreview.svelte b/packages/builder/src/components/userInterface/CurrentItemPreview.svelte index 371f1eaada..1edca1c8d6 100644 --- a/packages/builder/src/components/userInterface/CurrentItemPreview.svelte +++ b/packages/builder/src/components/userInterface/CurrentItemPreview.svelte @@ -29,10 +29,12 @@ [map(s => ``), join("\n")] ) + $: screensExist = $store.currentPreviewItem._screens && $store.currentPreviewItem._screens.length > 0 + $: frontendDefinition = { componentLibraries: $store.loadLibraryUrls($store.currentPageName), page: $store.currentPreviewItem, - screens: [{ + screens: screensExist ? $store.currentPreviewItem._screens : [{ name: "Screen Placeholder", route: "*", props: { diff --git a/packages/client/src/createApp.js b/packages/client/src/createApp.js index f43a6d4c34..07aca3de8f 100644 --- a/packages/client/src/createApp.js +++ b/packages/client/src/createApp.js @@ -34,9 +34,9 @@ export const createApp = ( routeTo, appRootPath: frontendDefinition.appRootPath, }) - const getAttchChildrenParams = attachChildrenParams(stateManager) + const getAttachChildrenParams = attachChildrenParams(stateManager) screenSlotNode.props._children = [screen.props] - const initialiseChildParams = getAttchChildrenParams(screenSlotNode) + const initialiseChildParams = getAttachChildrenParams(screenSlotNode) attachChildren(initialiseChildParams)(screenSlotNode.rootElement, { hydrate: true, force: true, @@ -102,6 +102,7 @@ export const createApp = ( return rootTreeNode } + return { initialisePage, screenStore: () => screenStateManager.store, diff --git a/packages/client/src/render/screenRouter.js b/packages/client/src/render/screenRouter.js index 992b4e2ff3..472ad8a039 100644 --- a/packages/client/src/render/screenRouter.js +++ b/packages/client/src/render/screenRouter.js @@ -44,11 +44,9 @@ export const screenRouter = (screens, onScreenSelected, appRootPath) => { storeInitial["##routeParams"] = params const store = writable(storeInitial) - if (current !== -1) { - onScreenSelected(screens[current], store, _url) - } else { - onScreenSelected(screens[fallback], store, _url) - } + const screenIndex = current !== -1 ? current : fallback; + + onScreenSelected(screens[screenIndex], store, _url) try { !url.state && history.pushState(_url, null, _url)