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:
@@ -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(() => {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user