Fix bugs around selecting screens and layouts when creating them
This commit is contained in:
parent
b5637dbffc
commit
31f0b51039
|
@ -120,17 +120,13 @@ export const getFrontendStore = () => {
|
||||||
state.screens.splice(foundScreen, 1)
|
state.screens.splice(foundScreen, 1)
|
||||||
}
|
}
|
||||||
state.screens.push(screen)
|
state.screens.push(screen)
|
||||||
|
|
||||||
if (creatingNewScreen) {
|
|
||||||
const safeProps = makePropsSafe(
|
|
||||||
state.components[screen.props._component],
|
|
||||||
screen.props
|
|
||||||
)
|
|
||||||
state.selectedComponentId = safeProps._id
|
|
||||||
screen.props = safeProps
|
|
||||||
}
|
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (creatingNewScreen) {
|
||||||
|
store.actions.screens.select(screen._id)
|
||||||
|
}
|
||||||
|
|
||||||
return screen
|
return screen
|
||||||
},
|
},
|
||||||
delete: async screens => {
|
delete: async screens => {
|
||||||
|
@ -178,28 +174,30 @@ export const getFrontendStore = () => {
|
||||||
},
|
},
|
||||||
save: async layout => {
|
save: async layout => {
|
||||||
const layoutToSave = cloneDeep(layout)
|
const layoutToSave = cloneDeep(layout)
|
||||||
|
const creatingNewLayout = layoutToSave._id === undefined
|
||||||
const response = await api.post(`/api/layouts`, layoutToSave)
|
const response = await api.post(`/api/layouts`, layoutToSave)
|
||||||
|
const savedLayout = await response.json()
|
||||||
const json = await response.json()
|
|
||||||
|
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
const layoutIdx = state.layouts.findIndex(
|
const layoutIdx = state.layouts.findIndex(
|
||||||
stateLayout => stateLayout._id === json._id
|
stateLayout => stateLayout._id === savedLayout._id
|
||||||
)
|
)
|
||||||
|
|
||||||
if (layoutIdx >= 0) {
|
if (layoutIdx >= 0) {
|
||||||
// update existing layout
|
// update existing layout
|
||||||
state.layouts.splice(layoutIdx, 1, json)
|
state.layouts.splice(layoutIdx, 1, savedLayout)
|
||||||
} else {
|
} else {
|
||||||
// save new layout
|
// save new layout
|
||||||
state.layouts.push(json)
|
state.layouts.push(savedLayout)
|
||||||
}
|
}
|
||||||
|
|
||||||
state.currentAssetId = json._id
|
|
||||||
state.selectedComponentId = json.props._id
|
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Select layout if creating a new one
|
||||||
|
if (creatingNewLayout) {
|
||||||
|
store.actions.layouts.select(savedLayout._id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return savedLayout
|
||||||
},
|
},
|
||||||
find: layoutId => {
|
find: layoutId => {
|
||||||
if (!layoutId) {
|
if (!layoutId) {
|
||||||
|
@ -450,7 +448,6 @@ export const getFrontendStore = () => {
|
||||||
|
|
||||||
// Save layout
|
// Save layout
|
||||||
nav._children = [...nav._children, newLink]
|
nav._children = [...nav._children, newLink]
|
||||||
state.currentAssetId = layout._id
|
|
||||||
promises.push(store.actions.layouts.save(layout))
|
promises.push(store.actions.layouts.save(layout))
|
||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
|
|
Loading…
Reference in New Issue