From 5c7dcf0117ffb534e22d62b0ccf370803967a638 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Sun, 3 Oct 2021 13:41:32 -0400 Subject: [PATCH] Mobile: Resolves #4701: Improve delete dialog message (#5481) --- packages/app-desktop/gui/utils/NoteListUtils.ts | 11 ++--------- packages/app-mobile/components/screen-header.js | 8 ++++++-- packages/lib/models/Note.ts | 14 +++++++++++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/app-desktop/gui/utils/NoteListUtils.ts b/packages/app-desktop/gui/utils/NoteListUtils.ts index 3622153e8..9fccb0a86 100644 --- a/packages/app-desktop/gui/utils/NoteListUtils.ts +++ b/packages/app-desktop/gui/utils/NoteListUtils.ts @@ -13,7 +13,6 @@ const Menu = bridge().Menu; const MenuItem = bridge().MenuItem; import Note from '@joplin/lib/models/Note'; import Setting from '@joplin/lib/models/Setting'; -const { substrWithEllipsis } = require('@joplin/lib/string-utils'); interface ContextMenuProps { notes: any[]; @@ -204,14 +203,8 @@ export default class NoteListUtils { static async confirmDeleteNotes(noteIds: string[]) { if (!noteIds.length) return; - let msg = ''; - if (noteIds.length === 1) { - const note = await Note.load(noteIds[0]); - if (!note) return; - msg = _('Delete note "%s"?', substrWithEllipsis(note.title, 0, 32)); - } else { - msg = _('Delete these %d notes?', noteIds.length); - } + const msg = await Note.deleteMessage(noteIds); + if (!msg) return; const ok = bridge().showConfirmMessageBox(msg, { buttons: [_('Delete'), _('Cancel')], diff --git a/packages/app-mobile/components/screen-header.js b/packages/app-mobile/components/screen-header.js index 1edea3d4c..9a71373fc 100644 --- a/packages/app-mobile/components/screen-header.js +++ b/packages/app-mobile/components/screen-header.js @@ -184,10 +184,14 @@ class ScreenHeaderComponent extends React.PureComponent { async deleteButton_press() { // Dialog needs to be displayed as a child of the parent component, otherwise // it won't be visible within the header component. - const ok = await dialogs.confirm(this.props.parentComponent, _('Delete these notes?')); + const noteIds = this.props.selectedNoteIds; + + const msg = await Note.deleteMessage(noteIds); + if (!msg) return; + + const ok = await dialogs.confirm(this.props.parentComponent, msg); if (!ok) return; - const noteIds = this.props.selectedNoteIds; this.props.dispatch({ type: 'NOTE_SELECTION_END' }); await Note.batchDelete(noteIds); } diff --git a/packages/lib/models/Note.ts b/packages/lib/models/Note.ts index a04492865..639be8649 100644 --- a/packages/lib/models/Note.ts +++ b/packages/lib/models/Note.ts @@ -10,7 +10,7 @@ import Tag from './Tag'; const { sprintf } = require('sprintf-js'); import Resource from './Resource'; -const { pregQuote } = require('../string-utils.js'); +const { pregQuote, substrWithEllipsis } = require('../string-utils.js'); const { _ } = require('../locale'); const ArrayUtils = require('../ArrayUtils.js'); const lodash = require('lodash'); @@ -731,6 +731,18 @@ export default class Note extends BaseItem { } } + static async deleteMessage(noteIds: string[]): Promise { + let msg = ''; + if (noteIds.length === 1) { + const note = await Note.load(noteIds[0]); + if (!note) return null; + msg = _('Delete note "%s"?', substrWithEllipsis(note.title, 0, 32)); + } else { + msg = _('Delete these %d notes?', noteIds.length); + } + return msg; + } + static dueNotes() { return this.modelSelectAll('SELECT id, title, body, is_todo, todo_due, todo_completed, is_conflict FROM notes WHERE is_conflict = 0 AND is_todo = 1 AND todo_completed = 0 AND todo_due > ?', [time.unixMs()]); }