1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Mobile: Resolves #4701: Improve delete dialog message (#5481)

This commit is contained in:
Helmut K. C. Tessarek 2021-10-03 13:41:32 -04:00 committed by GitHub
parent 3bda77d504
commit 5c7dcf0117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 12 deletions

View File

@ -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')],

View File

@ -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);
}

View File

@ -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<string|null> {
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()]);
}