Add ability to set home screens and fix issue with sorting screens

This commit is contained in:
Andrew Kingston 2022-04-27 11:36:47 +01:00
parent 7bf25d9a7b
commit 893327cd9e
3 changed files with 33 additions and 2 deletions

View File

@ -225,6 +225,31 @@ export const getFrontendStore = () => {
// Refresh routes // Refresh routes
await store.actions.routing.fetch() await store.actions.routing.fetch()
}, },
updateHomeScreen: async (screen, makeHomeScreen = true) => {
let promises = []
// Find any existing home screen for this role so we can remove it,
// if we are setting this to be the new home screen
if (makeHomeScreen) {
const roleId = screen.routing.roleId
let existingHomeScreen = get(store).screens.find(s => {
return (
s.routing.roleId === roleId &&
s.routing.homeScreen &&
s._id !== screen._id
)
})
if (existingHomeScreen) {
existingHomeScreen.routing.homeScreen = false
promises.push(store.actions.screens.save(existingHomeScreen))
}
}
// Update the passed in screen
screen.routing.homeScreen = makeHomeScreen
promises.push(store.actions.screens.save(screen))
return await Promise.all(promises)
},
}, },
preview: { preview: {
saveSelected: async () => { saveSelected: async () => {

View File

@ -34,8 +34,8 @@
return roleA > roleB ? -1 : 1 return roleA > roleB ? -1 : 1
} }
// Then put home screens first // Then put home screens first
const homeA = a.routing.homeScreen const homeA = !!a.routing.homeScreen
const homeB = b.routing.homeScreen const homeB = !!b.routing.homeScreen
if (homeA !== homeB) { if (homeA !== homeB) {
return homeA ? -1 : 1 return homeA ? -1 : 1
} }

View File

@ -61,6 +61,12 @@
} }
} }
// Home screen changes need to be handled manually
if (key === "routing.homeScreen") {
store.actions.screens.updateHomeScreen(get(selectedScreen), value)
return
}
// Update screen object in store // Update screen object in store
store.update(state => { store.update(state => {
setWith(get(selectedScreen), key.split("."), value, Object) setWith(get(selectedScreen), key.split("."), value, Object)