From 66126531e3c05be647a8be665f5354cfa7b371e1 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 15 Jul 2022 08:39:31 +0100 Subject: [PATCH] Update screen settings to use patches --- .../src/builderStore/store/frontend.js | 8 +++++-- .../_components/ScreenSettingsPanel.svelte | 24 ++++++------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 75cc4cd2cc..71e422f8ae 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -309,13 +309,17 @@ export const getFrontendStore = () => { ) }) if (existingHomeScreen) { - const patch = screen => (screen.routing.homeScreen = false) + const patch = screen => { + screen.routing.homeScreen = false + } await store.actions.screens.patch(patch, existingHomeScreen._id) } } // Update the passed in screen - const patch = screen => (screen.routing.homeScreen = makeHomeScreen) + const patch = screen => { + screen.routing.homeScreen = makeHomeScreen + } await store.actions.screens.patch(patch, screen._id) }, removeCustomLayout: async screen => { diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenSettingsPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenSettingsPanel.svelte index 0d861d1cd8..c30c78d3b6 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenSettingsPanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenSettingsPanel.svelte @@ -42,7 +42,7 @@ ) } - const setScreenSetting = (setting, value) => { + const setScreenSetting = async (setting, value) => { const { key, parser, validate } = setting // Parse value if required @@ -69,26 +69,16 @@ // Home screen changes need to be handled manually if (key === "routing.homeScreen") { - store.actions.screens.updateHomeScreen(get(selectedScreen), value) + console.log(value) + await store.actions.screens.updateHomeScreen(get(selectedScreen), value) return } - // Update screen object in store - // If there are 2 home screens after this change, remove this screen as a - // home screen - const screen = get(selectedScreen) - setWith(screen, key.split("."), value, Object) - const roleId = screen.routing.roleId - const homeScreens = get(store).screens.filter(screen => { - return screen.routing.roleId === roleId && screen.routing.homeScreen - }) - if (homeScreens.length > 1) { - screen.routing.homeScreen = false - } - - // Save new definition + // Update screen setting try { - store.actions.screens.save(screen) + await store.actions.screens.patch(screen => { + setWith(screen, key.split("."), value, Object) + }) } catch (error) { notifications.error("Error saving screen settings") }