Mark composer as clean after saving draft

Add mark_saved action that resets isDirty to false and updates the
draftId. This is dispatched after successfully saving a draft, allowing
the user to close the composer without a discard prompt since their
changes have been saved.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-01-13 17:54:28 +02:00
parent 794891db1e
commit 4cccaf5d8e
2 changed files with 17 additions and 4 deletions
+6 -4
View File
@@ -349,26 +349,28 @@ export const ComposePost = ({
const handleSaveDraft = React.useCallback(async () => { const handleSaveDraft = React.useCallback(async () => {
try { try {
await saveDraft({ const savedDraft = await saveDraft({
composerState, composerState,
replyTo, replyTo,
existingDraftId: composerState.draftId, existingDraftId: composerState.draftId,
}) })
composerDispatch({type: 'mark_saved', draftId: savedDraft.id})
onClose() onClose()
} catch (e) { } catch (e) {
logger.error('Failed to save draft', {error: e}) logger.error('Failed to save draft', {error: e})
setError(_(msg`Failed to save draft`)) setError(_(msg`Failed to save draft`))
} }
}, [saveDraft, composerState, replyTo, onClose, _]) }, [saveDraft, composerState, replyTo, composerDispatch, onClose, _])
// Save without closing - for use by DraftsButton // Save without closing - for use by DraftsButton
const saveCurrentDraft = React.useCallback(async () => { const saveCurrentDraft = React.useCallback(async () => {
await saveDraft({ const savedDraft = await saveDraft({
composerState, composerState,
replyTo, replyTo,
existingDraftId: composerState.draftId, existingDraftId: composerState.draftId,
}) })
}, [saveDraft, composerState, replyTo]) composerDispatch({type: 'mark_saved', draftId: savedDraft.id})
}, [saveDraft, composerState, replyTo, composerDispatch])
// Check if composer is empty (no content to save) // Check if composer is empty (no content to save)
const isComposerEmpty = React.useMemo(() => { const isComposerEmpty = React.useMemo(() => {
+11
View File
@@ -136,6 +136,10 @@ export type ComposerAction =
| { | {
type: 'clear' type: 'clear'
} }
| {
type: 'mark_saved'
draftId: string
}
export const MAX_IMAGES = 4 export const MAX_IMAGES = 4
@@ -346,6 +350,13 @@ export function composerReducer(
}, },
} }
} }
case 'mark_saved': {
return {
...state,
isDirty: false,
draftId: action.draftId,
}
}
} }
} }