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

Add file drop on NoteList

This commit is contained in:
asmsuechan
2017-09-23 00:28:52 +09:00
parent ce7c5f5d40
commit 42a9caf5a3

View File

@@ -348,6 +348,21 @@ class NoteList extends React.Component {
properties: ['openFile', 'multiSelections'] properties: ['openFile', 'multiSelections']
} }
dialog.showOpenDialog(remote.getCurrentWindow(), options, (filepaths) => {
this.addNotes(filepaths)
})
}
handleDrop (e) {
e.preventDefault()
const filepaths = Array.from(e.dataTransfer.files).map(file => { return file.path })
this.addNotes(filepaths)
}
// Add notes in the current folder
addNotes (filepaths) {
const { dispatch, location } = this.props
const targetIndex = _.findIndex(this.notes, (note) => { const targetIndex = _.findIndex(this.notes, (note) => {
return note !== null && `${note.storage}-${note.key}` === location.query.key return note !== null && `${note.storage}-${note.key}` === location.query.key
}) })
@@ -355,7 +370,6 @@ class NoteList extends React.Component {
const storageKey = this.notes[targetIndex].storage const storageKey = this.notes[targetIndex].storage
const folderKey = this.notes[targetIndex].folder const folderKey = this.notes[targetIndex].folder
dialog.showOpenDialog(remote.getCurrentWindow(), options, (filepaths) => {
if (filepaths === undefined) return if (filepaths === undefined) return
filepaths.forEach((filepath) => { filepaths.forEach((filepath) => {
fs.readFile(filepath, (err, data) => { fs.readFile(filepath, (err, data) => {
@@ -364,7 +378,7 @@ class NoteList extends React.Component {
const newNote = { const newNote = {
content: content, content: content,
folder: folderKey, folder: folderKey,
title: markdown.strip(striptags(findNoteTitle(content))), title: markdown.strip(findNoteTitle(content)),
type: 'MARKDOWN_NOTE' type: 'MARKDOWN_NOTE'
} }
dataApi.createNote(storageKey, newNote) dataApi.createNote(storageKey, newNote)
@@ -380,7 +394,6 @@ class NoteList extends React.Component {
}) })
}) })
}) })
})
} }
render () { render () {
@@ -439,6 +452,7 @@ class NoteList extends React.Component {
<div className='NoteList' <div className='NoteList'
styleName='root' styleName='root'
style={this.props.style} style={this.props.style}
onDrop={(e) => this.handleDrop(e)}
> >
<div styleName='control'> <div styleName='control'>
<div styleName='control-sortBy'> <div styleName='control-sortBy'>