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:
@@ -433,9 +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 storageKey = this.props.params.storageKey
|
|
||||||
const folderKey = this.props.params.folderKey
|
|
||||||
|
|
||||||
if (filepaths === undefined) return
|
if (filepaths === undefined) return
|
||||||
filepaths.forEach((filepath) => {
|
filepaths.forEach((filepath) => {
|
||||||
@@ -444,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',
|
||||||
@@ -471,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'
|
||||||
|
|||||||
Reference in New Issue
Block a user