From 21220f93b16c4028a8165ec35d1e48d0eb2ff582 Mon Sep 17 00:00:00 2001 From: yosmoc Date: Sat, 4 Nov 2017 22:32:30 +0100 Subject: [PATCH 1/2] enable importing file to empty folder Current implementation is fetching the import destination storageKey and folderkey from a file in the folder. If no files are in the folder, it cannot fetch these keys. Use prop.params.storageKey / folderKey instead. --- browser/main/NoteList/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index c9e116d7..fd4cb043 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -434,10 +434,8 @@ class NoteList extends React.Component { addNotesFromFiles (filepaths) { const { dispatch, location } = this.props - const targetIndex = this.getTargetIndex() - - const storageKey = this.notes[targetIndex].storage - const folderKey = this.notes[targetIndex].folder + const storageKey = this.props.params.storageKey + const folderKey = this.props.params.folderKey if (filepaths === undefined) return filepaths.forEach((filepath) => { From 8fb8c7a40b49862b52b9a520a524cfafad5989ff Mon Sep 17 00:00:00 2001 From: yosmoc Date: Mon, 6 Nov 2017 00:13:46 +0100 Subject: [PATCH 2/2] importing from file uses the same storage/folder resolve logic as creating new note It makes less confusing for user. --- browser/main/NoteList/index.js | 38 +++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index fd4cb043..6ed0f6ca 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -433,9 +433,7 @@ class NoteList extends React.Component { // Add notes to the current folder addNotesFromFiles (filepaths) { const { dispatch, location } = this.props - - const storageKey = this.props.params.storageKey - const folderKey = this.props.params.folderKey + const { storage, folder } = this.resolveTargetFolder() if (filepaths === undefined) return filepaths.forEach((filepath) => { @@ -444,11 +442,11 @@ class NoteList extends React.Component { const content = data.toString() const newNote = { content: content, - folder: folderKey, + folder: folder.key, title: markdown.strip(findNoteTitle(content)), type: 'MARKDOWN_NOTE' } - dataApi.createNote(storageKey, newNote) + dataApi.createNote(storage.key, newNote) .then((note) => { dispatch({ type: 'UPDATE_NOTE', @@ -471,6 +469,36 @@ class NoteList extends React.Component { return targetIndex } + resolveTargetFolder () { + const { data, params } = this.props + let storage = data.storageMap.get(params.storageKey) + + // Find first storage + if (storage == null) { + for (let kv of data.storageMap) { + storage = kv[1] + break + } + } + + if (storage == null) this.showMessageBox('No storage for importing note(s)') + const folder = _.find(storage.folders, {key: params.folderKey}) || storage.folders[0] + if (folder == null) this.showMessageBox('No folder for importing note(s)') + + return { + storage, + folder + } + } + + showMessageBox (message) { + dialog.showMessageBox(remote.getCurrentWindow(), { + type: 'warning', + message: message, + buttons: ['OK'] + }) + } + render () { let { location, notes, config, dispatch } = this.props let sortFunc = config.sortBy === 'CREATED_AT'