Skip to content

Commit b60f7ed

Browse files
committed
refactor: streamline media deletion logic in useMediaBin hook
1 parent 3cb0427 commit b60f7ed

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

app/hooks/useMediaBin.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,30 +383,26 @@ export const useMediaBin = (handleDeleteScrubbersByMediaBinId: (mediaBinId: stri
383383
const handleDeleteMedia = useCallback(
384384
async (item: MediaBinItem) => {
385385
try {
386+
// For text and grouped scrubbers, which are UI-only constructs, just remove them from the local state.
386387
if (item.mediaType === "text" || item.mediaType === "groupped_scrubber") {
387388
setMediaBinItems((prev) => prev.filter((binItem) => binItem.id !== item.id));
388-
389-
// Also remove any scrubbers from the timeline that use this media
390389
if (handleDeleteScrubbersByMediaBinId) {
391390
handleDeleteScrubbersByMediaBinId(item.id);
392391
}
393-
394-
if (!item.mediaUrlRemote) {
395-
console.error("No remote URL found for media item");
396-
return;
397-
}
392+
return; // Exit early as there's no backend asset to delete.
398393
}
399-
// Call authenticated delete by asset id
394+
395+
// For other media types, call the authenticated delete endpoint.
400396
const assetId = item.id;
401397
const res = await fetch(apiUrl(`/api/assets/${assetId}`, false, true), {
402398
method: "DELETE",
403399
credentials: "include",
404400
});
401+
405402
if (res.ok) {
406403
console.log(`Media deleted: ${item.name}`);
407-
// Remove from media bin state
404+
// On successful backend deletion, remove the item from the UI state.
408405
setMediaBinItems((prev) => prev.filter((binItem) => binItem.id !== item.id));
409-
// Also remove any scrubbers from the timeline that use this media
410406
if (handleDeleteScrubbersByMediaBinId) {
411407
handleDeleteScrubbersByMediaBinId(item.id);
412408
}

0 commit comments

Comments
 (0)