Fix state when deleting frontend screens
This commit is contained in:
parent
06d83c7ad5
commit
536074c97f
|
@ -1,4 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
|
import { goto } from "@sveltech/routify"
|
||||||
import { store } from "builderStore"
|
import { store } from "builderStore"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
@ -16,19 +17,27 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteScreen = () => {
|
const deleteScreen = () => {
|
||||||
store.update(s => {
|
store.update(state => {
|
||||||
const screens = s.screens.filter(c => c.name !== screen.name)
|
// Remove screen from screens
|
||||||
s.screens = screens
|
const screens = state.screens.filter(c => c.name !== screen.name)
|
||||||
if (s.currentPreviewItem.name === screen.name) {
|
state.screens = screens
|
||||||
s.currentPreviewItem = s.pages[s.currentPageName]
|
|
||||||
s.currentFrontEndType = "page"
|
// Remove screen from current page as well
|
||||||
|
const pageScreens = state.pages[state.currentPageName]._screens.filter(
|
||||||
|
scr => scr.name !== screen.name
|
||||||
|
)
|
||||||
|
state.pages[state.currentPageName]._screens = pageScreens
|
||||||
|
|
||||||
|
if (state.currentPreviewItem.name === screen.name) {
|
||||||
|
store.setCurrentPage($store.currentPageName)
|
||||||
|
$goto(`./:page/page-layout`)
|
||||||
}
|
}
|
||||||
|
|
||||||
api.delete(
|
api.delete(
|
||||||
`/_builder/api/pages/${s.currentPageName}/screens/${screen.name}`
|
`/_builder/api/pages/${state.currentPageName}/screens/${screen.name}`
|
||||||
)
|
)
|
||||||
|
|
||||||
return s
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue