1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Merge pull request #1064 from yosmoc/importfiletoemptyfolder

enable importing file to empty folder
This commit is contained in:
SuenagaRyota
2017-11-07 14:42:35 +09:00
committed by GitHub

View File

@@ -433,11 +433,7 @@ class NoteList extends React.Component {
// Add notes to the current folder // Add notes to the current folder
addNotesFromFiles (filepaths) { addNotesFromFiles (filepaths) {
const { dispatch, location } = this.props const { dispatch, location } = this.props
const { storage, folder } = this.resolveTargetFolder()
const targetIndex = this.getTargetIndex()
const storageKey = this.notes[targetIndex].storage
const folderKey = this.notes[targetIndex].folder
if (filepaths === undefined) return if (filepaths === undefined) return
filepaths.forEach((filepath) => { filepaths.forEach((filepath) => {
@@ -446,11 +442,11 @@ class NoteList extends React.Component {
const content = data.toString() const content = data.toString()
const newNote = { const newNote = {
content: content, content: content,
folder: folderKey, folder: folder.key,
title: markdown.strip(findNoteTitle(content)), title: markdown.strip(findNoteTitle(content)),
type: 'MARKDOWN_NOTE' type: 'MARKDOWN_NOTE'
} }
dataApi.createNote(storageKey, newNote) dataApi.createNote(storage.key, newNote)
.then((note) => { .then((note) => {
dispatch({ dispatch({
type: 'UPDATE_NOTE', type: 'UPDATE_NOTE',
@@ -473,6 +469,36 @@ class NoteList extends React.Component {
return targetIndex 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 () { render () {
let { location, notes, config, dispatch } = this.props let { location, notes, config, dispatch } = this.props
let sortFunc = config.sortBy === 'CREATED_AT' let sortFunc = config.sortBy === 'CREATED_AT'