fix: remove sketch file reference when deleting assets#4161
fix: remove sketch file reference when deleting assets#4161yugalkaushik wants to merge 2 commits into
Conversation
|
|
||
| const { project } = getState(); | ||
| if (project.id === asset.sketchId) { | ||
| dispatch(setProjectSavedTime(response.data.project.updatedAt)); | ||
| dispatch({ | ||
| type: ActionTypes.DELETE_FILE, | ||
| id: asset.fileId, | ||
| parentId: asset.parentId | ||
| }); | ||
| } |
There was a problem hiding this comment.
we can remove this. unlike deleteFile, there's no need to reactively update local state here since the user is on a different screen, and returning to the sketch will load the latest data anyway.
edit: also getState() returns the currently open project state, which may not even be the project associated with the asset being deleted.
There was a problem hiding this comment.
Regarding getState, it's still present solely for the DELETE_FILE dispatch, which is guarded by if (project.id === asset.sketchId). This ensures that when a user deletes a referenced asset from the Assets tab while on the same sketch, the file tree sidebar updates immediately without requiring a page refresh. When the user is viewing a different sketch, the guard prevents any action. So getState is safe and necessary for this reactive UI update.
Issue:
Fixes #4160
Asset deletion now uses the same file delete endpoint as the sketch files sidebar, so both the storage object and the project file reference are removed together.
Before
issue-editor.mp4
After
pr-preview.mp4
Changes:
I have verified that this pull request:
npm run lint)npm run test)npm run typecheck)developbranch.Fixes #123