mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
fix: revert the move in the file tree on error
GitOrigin-RevId: 580241cd771671ae8cfd93910f2e231e0e1b5148
This commit is contained in:
parent
117928f58e
commit
485fc64bcc
1 changed files with 20 additions and 9 deletions
|
@ -231,18 +231,29 @@ export function FileTreeActionableProvider({ children }) {
|
||||||
return dispatch({ type: ACTION_TYPES.ERROR, error: validationError })
|
return dispatch({ type: ACTION_TYPES.ERROR, error: validationError })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keep track of old parent folder ids so we can revert entities if sync fails
|
||||||
|
const oldParentFolderIds = {}
|
||||||
|
let isMoveFailed = false
|
||||||
|
|
||||||
// dispatch moves immediately
|
// dispatch moves immediately
|
||||||
founds.forEach(found => dispatchMove(found.entity._id, toFolderId))
|
founds.forEach(found => {
|
||||||
|
oldParentFolderIds[found.entity._id] = found.parentFolderId
|
||||||
|
dispatchMove(found.entity._id, toFolderId)
|
||||||
|
})
|
||||||
|
|
||||||
// sync dispatched moves after
|
// sync dispatched moves after
|
||||||
return mapSeries(founds, found =>
|
return mapSeries(founds, async found => {
|
||||||
syncMove(projectId, found.type, found.entity._id, toFolderId)
|
try {
|
||||||
)
|
await syncMove(projectId, found.type, found.entity._id, toFolderId)
|
||||||
.then(() => {
|
} catch (error) {
|
||||||
dispatch({ type: ACTION_TYPES.CLEAR })
|
isMoveFailed = true
|
||||||
})
|
dispatchMove(found.entity._id, oldParentFolderIds[found.entity._id])
|
||||||
.catch(error => {
|
|
||||||
dispatch({ type: ACTION_TYPES.ERROR, error })
|
dispatch({ type: ACTION_TYPES.ERROR, error })
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
if (!isMoveFailed) {
|
||||||
|
dispatch({ type: ACTION_TYPES.CLEAR })
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[dispatchMove, fileTreeData, projectId]
|
[dispatchMove, fileTreeData, projectId]
|
||||||
|
|
Loading…
Reference in a new issue