Fix re-saving drafts with existing media
When re-saving a draft, the code was trying to copy media files that were already in drafts storage to new locations, causing copy errors. Changes: - Add extractLocalIdFromPath() to detect if a path is already in drafts - Track loadedMediaMap in ComposerState for identifying reusable media - Only delete old media that wasn't reused during re-save - Pass loadedMediaMap when saving to enable media reuse detection - Disable pointer events on draft media preview Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -353,6 +353,7 @@ export const ComposePost = ({
|
||||
composerState,
|
||||
replyTo,
|
||||
existingDraftId: composerState.draftId,
|
||||
loadedMediaMap: composerState.loadedMediaMap,
|
||||
})
|
||||
composerDispatch({type: 'mark_saved', draftId: savedDraft.id})
|
||||
onClose()
|
||||
@@ -368,6 +369,7 @@ export const ComposePost = ({
|
||||
composerState,
|
||||
replyTo,
|
||||
existingDraftId: composerState.draftId,
|
||||
loadedMediaMap: composerState.loadedMediaMap,
|
||||
})
|
||||
composerDispatch({type: 'mark_saved', draftId: savedDraft.id})
|
||||
}, [saveDraft, composerState, replyTo, composerDispatch])
|
||||
|
||||
@@ -266,7 +266,7 @@ function DraftMediaPreview({post}: {post: DraftPostDisplay}) {
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={[a.pt_xs]}>
|
||||
<View style={[a.pt_xs, a.pointer_events_none]}>
|
||||
{/* Images - use real embed components */}
|
||||
{viewImages.length === 1 && (
|
||||
<AutoSizedImage image={viewImages[0]} hideBadge />
|
||||
|
||||
@@ -106,6 +106,8 @@ export type ComposerState = {
|
||||
draftId?: string
|
||||
/** Whether the composer has been modified since loading a draft. */
|
||||
isDirty: boolean
|
||||
/** Map of localId -> loaded media path/URL for the current draft. Used for re-saving without re-copying media. */
|
||||
loadedMediaMap?: Map<string, string>
|
||||
}
|
||||
|
||||
export type ComposerAction =
|
||||
@@ -317,6 +319,7 @@ export function composerReducer(
|
||||
mutableNeedsFocusActive: true,
|
||||
draftId: draft.id,
|
||||
isDirty: false,
|
||||
loadedMediaMap: loadedMedia,
|
||||
thread: {
|
||||
posts,
|
||||
postgate: draft.postgate || state.thread.postgate,
|
||||
@@ -330,6 +333,7 @@ export function composerReducer(
|
||||
mutableNeedsFocusActive: true,
|
||||
draftId: undefined,
|
||||
isDirty: false,
|
||||
loadedMediaMap: undefined,
|
||||
thread: {
|
||||
posts: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user