From 804ac1aa96ae5974bf5aacc913d8ef3fced21c02 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 15 Jul 2017 12:45:03 +0900 Subject: [PATCH] Remove a dialogbox from onTrashButtonClick --- browser/main/Detail/MarkdownNoteDetail.js | 61 +++++++++++------------ browser/main/Detail/SnippetNoteDetail.js | 61 +++++++++++------------ 2 files changed, 58 insertions(+), 64 deletions(-) diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index aa9c0b29..37d3f71f 100644 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -179,40 +179,37 @@ class MarkdownNoteDetail extends React.Component { let { note } = this.state const { isTrashed } = note - const popupMessage = isTrashed ? 'This work cannot be undone.' : 'Throw it into trashbox.' - - let dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { - type: 'warning', - message: 'Delete a note', - detail: popupMessage, - buttons: ['Confirm', 'Cancel'] - }) - if (dialogueButtonIndex === 0) { - if (!isTrashed) { - note.isTrashed = true - - this.setState({ - note - }, () => { - this.save() + if (isTrashed) { + let dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { + type: 'warning', + message: 'Delete a note', + detail: 'This work cannot be undone.', + buttons: ['Confirm', 'Cancel'] + }) + if (dialogueButtonIndex === 1) return + let { note, dispatch } = this.props + dataApi + .deleteNote(note.storage, note.key) + .then((data) => { + let dispatchHandler = () => { + dispatch({ + type: 'DELETE_NOTE', + storageKey: data.storageKey, + noteKey: data.noteKey + }) + } + ee.once('list:moved', dispatchHandler) }) - } else { - let { note, dispatch } = this.props - dataApi - .deleteNote(note.storage, note.key) - .then((data) => { - let dispatchHandler = () => { - dispatch({ - type: 'DELETE_NOTE', - storageKey: data.storageKey, - noteKey: data.noteKey - }) - } - ee.once('list:moved', dispatchHandler) - }) - } - ee.emit('list:next') + } else { + note.isTrashed = true + + this.setState({ + note + }, () => { + this.save() + }) } + ee.emit('list:next') } handleUndoButtonClick (e) { diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index de88efba..30263297 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -173,40 +173,37 @@ class SnippetNoteDetail extends React.Component { let { note } = this.state const { isTrashed } = note - const popupMessage = isTrashed ? 'This work cannot be undone.' : 'Throw it into trashbox.' - - let dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { - type: 'warning', - message: 'Delete a note', - detail: popupMessage, - buttons: ['Confirm', 'Cancel'] - }) - if (dialogueButtonIndex === 0) { - if (!isTrashed) { - note.isTrashed = true - - this.setState({ - note - }, () => { - this.save() + if (isTrashed) { + let dialogueButtonIndex = dialog.showMessageBox(remote.getCurrentWindow(), { + type: 'warning', + message: 'Delete a note', + detail: 'This work cannot be undone.', + buttons: ['Confirm', 'Cancel'] + }) + if (dialogueButtonIndex === 1) return + let { note, dispatch } = this.props + dataApi + .deleteNote(note.storage, note.key) + .then((data) => { + let dispatchHandler = () => { + dispatch({ + type: 'DELETE_NOTE', + storageKey: data.storageKey, + noteKey: data.noteKey + }) + } + ee.once('list:moved', dispatchHandler) }) - } else { - let { note, dispatch } = this.props - dataApi - .deleteNote(note.storage, note.key) - .then((data) => { - let dispatchHandler = () => { - dispatch({ - type: 'DELETE_NOTE', - storageKey: data.storageKey, - noteKey: data.noteKey - }) - } - ee.once('list:moved', dispatchHandler) - }) - } - ee.emit('list:next') + } else { + note.isTrashed = true + + this.setState({ + note + }, () => { + this.save() + }) } + ee.emit('list:next') } handleUndoButtonClick (e) {