Skip to content

Commit

Permalink
Merge pull request #1064 from yosmoc/importfiletoemptyfolder
Browse files Browse the repository at this point in the history
enable importing file to empty folder
  • Loading branch information
asmsuechan authored Nov 7, 2017
2 parents 4be1eb7 + 8fb8c7a commit e94b45a
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions browser/main/NoteList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,7 @@ class NoteList extends React.Component {
// Add notes to the current folder
addNotesFromFiles (filepaths) {
const { dispatch, location } = this.props

const targetIndex = this.getTargetIndex()

const storageKey = this.notes[targetIndex].storage
const folderKey = this.notes[targetIndex].folder
const { storage, folder } = this.resolveTargetFolder()

if (filepaths === undefined) return
filepaths.forEach((filepath) => {
Expand All @@ -446,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',
Expand All @@ -473,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'
Expand Down

0 comments on commit e94b45a

Please sign in to comment.