Apply dirty tracking to Drafts button prompt

Only show the save/discard prompt when pressing the Drafts button if
the composer has unsaved changes (isDirty). If the content is unchanged
from a loaded draft or was just saved, go directly to the drafts list.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-01-13 17:57:11 +02:00
parent 4cccaf5d8e
commit ec554210dc
2 changed files with 10 additions and 4 deletions
+5 -1
View File
@@ -832,7 +832,8 @@ export const ComposePost = ({
onSelectDraft={handleSelectDraft} onSelectDraft={handleSelectDraft}
onSaveDraft={saveCurrentDraft} onSaveDraft={saveCurrentDraft}
onDiscard={handleClearComposer} onDiscard={handleClearComposer}
isEmpty={isComposerEmpty}> isEmpty={isComposerEmpty}
isDirty={composerState.isDirty}>
{missingAltError && <AltTextReminder error={missingAltError} />} {missingAltError && <AltTextReminder error={missingAltError} />}
<ErrorBanner <ErrorBanner
error={error} error={error}
@@ -1124,6 +1125,7 @@ function ComposerTopBar({
onSaveDraft, onSaveDraft,
onDiscard, onDiscard,
isEmpty, isEmpty,
isDirty,
topBarAnimatedStyle, topBarAnimatedStyle,
children, children,
}: { }: {
@@ -1139,6 +1141,7 @@ function ComposerTopBar({
onSaveDraft: () => Promise<void> onSaveDraft: () => Promise<void>
onDiscard: () => void onDiscard: () => void
isEmpty: boolean isEmpty: boolean
isDirty: boolean
topBarAnimatedStyle: StyleProp<ViewStyle> topBarAnimatedStyle: StyleProp<ViewStyle>
children?: React.ReactNode children?: React.ReactNode
}) { }) {
@@ -1170,6 +1173,7 @@ function ComposerTopBar({
onSaveDraft={onSaveDraft} onSaveDraft={onSaveDraft}
onDiscard={onDiscard} onDiscard={onDiscard}
isEmpty={isEmpty} isEmpty={isEmpty}
isDirty={isDirty}
/> />
{isPublishing ? ( {isPublishing ? (
<> <>
@@ -13,11 +13,13 @@ export function DraftsButton({
onSaveDraft, onSaveDraft,
onDiscard, onDiscard,
isEmpty, isEmpty,
isDirty,
}: { }: {
onSelectDraft: (draft: StoredDraft) => void onSelectDraft: (draft: StoredDraft) => void
onSaveDraft: () => Promise<void> onSaveDraft: () => Promise<void>
onDiscard: () => void onDiscard: () => void
isEmpty: boolean isEmpty: boolean
isDirty: boolean
}) { }) {
const {_} = useLingui() const {_} = useLingui()
const draftsDialogControl = Dialog.useDialogControl() const draftsDialogControl = Dialog.useDialogControl()
@@ -25,11 +27,11 @@ export function DraftsButton({
const {isPending: isSaving} = useSaveDraft() const {isPending: isSaving} = useSaveDraft()
const handlePress = () => { const handlePress = () => {
if (isEmpty) { if (isEmpty || !isDirty) {
// Composer is empty, go directly to drafts list // Composer is empty or has no unsaved changes, go directly to drafts list
draftsDialogControl.open() draftsDialogControl.open()
} else { } else {
// Composer has content, ask what to do // Composer has unsaved changes, ask what to do
savePromptControl.open() savePromptControl.open()
} }
} }