From 4a810df0a91993ea39b660bd74b11cd42d476942 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 8 Oct 2026 14:55:06 -0400 Subject: [PATCH] DRY pass #2, batch 6, F19: the note menu's shared rows (#5372) TrashedNoteItems, PinItem and ArchiveItem (EditorChrome.kt) are the rows that the editor's overflow and the board's long-press menu each built: a trashed note's restore and delete-forever, and the pin and archive toggles. Each menu keeps its own order and its owner-only rows. Checked with ktlint in the CI image. Co-Authored-By: Claude Opus 5.5 --- .../fabledsword/inkwell/ui/EditorChrome.kt | 51 +++++++++++++++---- .../com/fabledsword/inkwell/ui/NoteCard.kt | 13 ++--- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/inkwell/ui/EditorChrome.kt b/android/app/src/main/java/com/fabledsword/inkwell/ui/EditorChrome.kt index 104e60f..1449a47 100644 --- a/android/app/src/main/java/com/fabledsword/inkwell/ui/EditorChrome.kt +++ b/android/app/src/main/java/com/fabledsword/inkwell/ui/EditorChrome.kt @@ -287,13 +287,9 @@ private fun OverflowMenu( } DropdownMenu(expanded = open, onDismissRequest = close) { if (note.trashed) { - MenuItem(R.string.editor_restore, close) { onAction(EditorAction.Restore) } - MenuItem(R.string.editor_delete_forever, close, onConfirmDelete) + TrashedNoteItems(close, onAction, onConfirmDelete) } else { - MenuItem( - if (note.pinned) R.string.editor_unpin else R.string.editor_pin, - close, - ) { onAction(EditorAction.SetPinned(!note.pinned)) } + PinItem(note, close, onAction) if (owner) { MenuItem(R.string.editor_labels, close) { onPicker(Picker.LABELS) } } @@ -301,10 +297,7 @@ private fun OverflowMenu( if (owner && note.id != DRAFT_ID) { MenuItem(R.string.editor_share, close, onShare) } - MenuItem( - if (note.archived) R.string.editor_unarchive else R.string.editor_archive, - close, - ) { onAction(EditorAction.SetArchived(!note.archived)) } + ArchiveItem(note, close, onAction) if (owner) { MenuItem(R.string.editor_trash, close) { onAction(EditorAction.Trash) } } @@ -313,6 +306,44 @@ private fun OverflowMenu( } } +// The rows a note's menu shares between the editor's overflow and the board's +// long-press menu: two ways to the same acts, worded the same way. + +/** A trashed note's two ways out: back, or gone for good (which asks first). */ +@Composable +internal fun TrashedNoteItems( + close: () -> Unit, + onAction: (EditorAction) -> Unit, + onConfirmDelete: () -> Unit, +) { + MenuItem(R.string.editor_restore, close) { onAction(EditorAction.Restore) } + MenuItem(R.string.editor_delete_forever, close, onConfirmDelete) +} + +@Composable +internal fun PinItem( + note: Note, + close: () -> Unit, + onAction: (EditorAction) -> Unit, +) { + MenuItem( + if (note.pinned) R.string.editor_unpin else R.string.editor_pin, + close, + ) { onAction(EditorAction.SetPinned(!note.pinned)) } +} + +@Composable +internal fun ArchiveItem( + note: Note, + close: () -> Unit, + onAction: (EditorAction) -> Unit, +) { + MenuItem( + if (note.archived) R.string.editor_unarchive else R.string.editor_archive, + close, + ) { onAction(EditorAction.SetArchived(!note.archived)) } +} + /** * The note's labels, each removable. * diff --git a/android/app/src/main/java/com/fabledsword/inkwell/ui/NoteCard.kt b/android/app/src/main/java/com/fabledsword/inkwell/ui/NoteCard.kt index 98b9fa2..abfb246 100644 --- a/android/app/src/main/java/com/fabledsword/inkwell/ui/NoteCard.kt +++ b/android/app/src/main/java/com/fabledsword/inkwell/ui/NoteCard.kt @@ -224,17 +224,10 @@ private fun NoteMenu( val owner = note.access == NoteAccess.OWNER DropdownMenu(expanded = expanded && (owner || !note.trashed), onDismissRequest = onDismiss) { if (note.trashed) { - MenuItem(R.string.editor_restore, onDismiss) { onAction(EditorAction.Restore) } - MenuItem(R.string.editor_delete_forever, onDismiss, onConfirmDelete) + TrashedNoteItems(onDismiss, onAction, onConfirmDelete) } else { - MenuItem( - if (note.pinned) R.string.editor_unpin else R.string.editor_pin, - onDismiss, - ) { onAction(EditorAction.SetPinned(!note.pinned)) } - MenuItem( - if (note.archived) R.string.editor_unarchive else R.string.editor_archive, - onDismiss, - ) { onAction(EditorAction.SetArchived(!note.archived)) } + PinItem(note, onDismiss, onAction) + ArchiveItem(note, onDismiss, onAction) if (owner) { MenuItem(R.string.editor_trash, onDismiss) { onAction(EditorAction.Trash) } }