-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: remove sketch file reference when deleting assets #4161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,14 +27,29 @@ export function getAssets() { | |
| }; | ||
| } | ||
|
|
||
| export function deleteAssetRequest(assetKey) { | ||
| return async (dispatch) => { | ||
| export function deleteAssetRequest(asset) { | ||
| return async (dispatch, getState) => { | ||
| try { | ||
| const path = assetKey.split('/').pop(); | ||
| await apiClient.delete( | ||
| `/S3/delete?objectKey=${encodeURIComponent(path)}` | ||
| ); | ||
| dispatch(deleteAsset(assetKey)); | ||
| if (asset.sketchId) { | ||
| await apiClient.delete( | ||
| `/projects/${asset.sketchId}/files/${asset.fileId}`, | ||
| { params: { parentId: asset.parentId } } | ||
| ); | ||
|
|
||
| const { project } = getState(); | ||
| if (project.id === asset.sketchId) { | ||
| dispatch({ | ||
| type: ActionTypes.DELETE_FILE, | ||
| id: asset.fileId, | ||
| parentId: asset.parentId | ||
| }); | ||
| } | ||
| } else { | ||
| await apiClient.delete('/S3/delete', { | ||
| params: { objectKey: asset.key } | ||
| }); | ||
| } | ||
|
Comment on lines
+38
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can remove this. unlike edit: also
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| dispatch(deleteAsset(asset.key)); | ||
| } catch (error) { | ||
| dispatch({ | ||
| type: ActionTypes.ERROR | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.