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

importing from file uses the same storage/folder resolve logic as creating new note

It makes less confusing for user.
This commit is contained in:
yosmoc
2017-11-06 00:13:46 +01:00
parent 21220f93b1
commit 8fb8c7a40b

View File

@@ -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'