Fix pasting inside different screens and select new screen when pasting inside different screen

This commit is contained in:
Andrew Kingston 2022-07-15 10:36:53 +01:00
parent be76f9ebfb
commit 210fc143ee
2 changed files with 7 additions and 4 deletions

View File

@ -583,7 +583,7 @@ export const getFrontendStore = () => {
} }
} }
}, },
paste: async (targetComponent, mode) => { paste: async (targetComponent, mode, targetScreen) => {
const state = get(store) const state = get(store)
if (!state.componentToPaste) { if (!state.componentToPaste) {
return return
@ -591,7 +591,7 @@ export const getFrontendStore = () => {
let newComponentId let newComponentId
// Patch screen // Patch screen
await store.actions.screens.patch(screen => { const patch = screen => {
// Get up to date ref to target // Get up to date ref to target
targetComponent = findComponent(screen.props, targetComponent._id) targetComponent = findComponent(screen.props, targetComponent._id)
if (!targetComponent) { if (!targetComponent) {
@ -640,13 +640,16 @@ export const getFrontendStore = () => {
const index = mode === "above" ? targetIndex : targetIndex + 1 const index = mode === "above" ? targetIndex : targetIndex + 1
parent._children.splice(index, 0, componentToPaste) parent._children.splice(index, 0, componentToPaste)
} }
}) }
const targetScreenId = targetScreen?._id || state.selectedScreenId
await store.actions.screens.patch(patch, targetScreenId)
store.update(state => { store.update(state => {
// Remove copied component if cutting // Remove copied component if cutting
if (state.componentToPaste.isCut) { if (state.componentToPaste.isCut) {
delete state.componentToPaste delete state.componentToPaste
} }
state.selectedScreenId = targetScreenId
state.selectedComponentId = newComponentId state.selectedComponentId = newComponentId
return state return state
}) })

View File

@ -23,7 +23,7 @@
const pasteComponent = mode => { const pasteComponent = mode => {
try { try {
store.actions.components.paste(screen.props, mode) store.actions.components.paste(screen.props, mode, screen)
} catch (error) { } catch (error) {
notifications.error("Error saving component") notifications.error("Error saving component")
} }