From 42a9caf5a37415b1016b42a5ea5c5fe51619e929 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 23 Sep 2017 00:28:52 +0900 Subject: [PATCH 1/4] Add file drop on NoteList --- browser/main/NoteList/index.js | 58 +++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 9434f21ad..df4e3e9dc 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -348,6 +348,21 @@ class NoteList extends React.Component { properties: ['openFile', 'multiSelections'] } + dialog.showOpenDialog(remote.getCurrentWindow(), options, (filepaths) => { + this.addNotes(filepaths) + }) + } + + handleDrop (e) { + e.preventDefault() + const filepaths = Array.from(e.dataTransfer.files).map(file => { return file.path }) + this.addNotes(filepaths) + } + + // Add notes in the current folder + addNotes (filepaths) { + const { dispatch, location } = this.props + const targetIndex = _.findIndex(this.notes, (note) => { return note !== null && `${note.storage}-${note.key}` === location.query.key }) @@ -355,28 +370,26 @@ class NoteList extends React.Component { const storageKey = this.notes[targetIndex].storage const folderKey = this.notes[targetIndex].folder - dialog.showOpenDialog(remote.getCurrentWindow(), options, (filepaths) => { - if (filepaths === undefined) return - filepaths.forEach((filepath) => { - fs.readFile(filepath, (err, data) => { - if (err) throw Error('File reading error: ', err) - const content = data.toString() - const newNote = { - content: content, - folder: folderKey, - title: markdown.strip(striptags(findNoteTitle(content))), - type: 'MARKDOWN_NOTE' - } - dataApi.createNote(storageKey, newNote) - .then((note) => { - dispatch({ - type: 'UPDATE_NOTE', - note: note - }) - hashHistory.push({ - pathname: location.pathname, - query: {key: `${note.storage}-${note.key}`} - }) + if (filepaths === undefined) return + filepaths.forEach((filepath) => { + fs.readFile(filepath, (err, data) => { + if (err) throw Error('File reading error: ', err) + const content = data.toString() + const newNote = { + content: content, + folder: folderKey, + title: markdown.strip(findNoteTitle(content)), + type: 'MARKDOWN_NOTE' + } + dataApi.createNote(storageKey, newNote) + .then((note) => { + dispatch({ + type: 'UPDATE_NOTE', + note: note + }) + hashHistory.push({ + pathname: location.pathname, + query: {key: `${note.storage}-${note.key}`} }) }) }) @@ -439,6 +452,7 @@ class NoteList extends React.Component {
this.handleDrop(e)} >
From 6aaf9d9eb2665330a74ac28f553e59cddc555d21 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 12 Aug 2017 11:54:53 +0900 Subject: [PATCH 2/4] Change disable drop on trash --- browser/main/NoteList/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index df4e3e9dc..9a5d35b89 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -355,8 +355,9 @@ class NoteList extends React.Component { handleDrop (e) { e.preventDefault() + const { location } = this.props const filepaths = Array.from(e.dataTransfer.files).map(file => { return file.path }) - this.addNotes(filepaths) + if (!location.pathname.match(/\/trashed/)) this.addNotes(filepaths) } // Add notes in the current folder From 2af2d715402db7b82f6dd2dde3609ca663fe5f31 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 23 Sep 2017 00:27:15 +0900 Subject: [PATCH 3/4] Rename addNotes to addNotesFromFiles --- browser/main/NoteList/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 9a5d35b89..e885bf298 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -349,7 +349,7 @@ class NoteList extends React.Component { } dialog.showOpenDialog(remote.getCurrentWindow(), options, (filepaths) => { - this.addNotes(filepaths) + this.addNotesFromFiles(filepaths) }) } @@ -361,7 +361,7 @@ class NoteList extends React.Component { } // Add notes in the current folder - addNotes (filepaths) { + addNotesFromFiles (filepaths) { const { dispatch, location } = this.props const targetIndex = _.findIndex(this.notes, (note) => { From f8e6a939cafc2ad224856a6fb7bd207b345331a4 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 23 Sep 2017 10:20:23 +0900 Subject: [PATCH 4/4] Fix comment --- browser/main/NoteList/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index e885bf298..9f1c52aff 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -360,7 +360,7 @@ class NoteList extends React.Component { if (!location.pathname.match(/\/trashed/)) this.addNotes(filepaths) } - // Add notes in the current folder + // Add notes to the current folder addNotesFromFiles (filepaths) { const { dispatch, location } = this.props