Update screen settings to use patches

This commit is contained in:
Andrew Kingston 2022-07-15 08:39:31 +01:00
parent edfb0fa50d
commit 66126531e3
2 changed files with 13 additions and 19 deletions

View File

@ -309,13 +309,17 @@ export const getFrontendStore = () => {
) )
}) })
if (existingHomeScreen) { if (existingHomeScreen) {
const patch = screen => (screen.routing.homeScreen = false) const patch = screen => {
screen.routing.homeScreen = false
}
await store.actions.screens.patch(patch, existingHomeScreen._id) await store.actions.screens.patch(patch, existingHomeScreen._id)
} }
} }
// Update the passed in screen // 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) await store.actions.screens.patch(patch, screen._id)
}, },
removeCustomLayout: async screen => { removeCustomLayout: async screen => {

View File

@ -42,7 +42,7 @@
) )
} }
const setScreenSetting = (setting, value) => { const setScreenSetting = async (setting, value) => {
const { key, parser, validate } = setting const { key, parser, validate } = setting
// Parse value if required // Parse value if required
@ -69,26 +69,16 @@
// Home screen changes need to be handled manually // Home screen changes need to be handled manually
if (key === "routing.homeScreen") { if (key === "routing.homeScreen") {
store.actions.screens.updateHomeScreen(get(selectedScreen), value) console.log(value)
await store.actions.screens.updateHomeScreen(get(selectedScreen), value)
return return
} }
// Update screen object in store // Update screen setting
// 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
try { try {
store.actions.screens.save(screen) await store.actions.screens.patch(screen => {
setWith(screen, key.split("."), value, Object)
})
} catch (error) { } catch (error) {
notifications.error("Error saving screen settings") notifications.error("Error saving screen settings")
} }