1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 18:56:22 +00:00

Merge pull request #793 from asmsuechan/add-drop-on-notelist

Add file drop on NoteList
This commit is contained in:
Kazu Yokomizo
2017-09-23 12:09:55 +09:00
committed by GitHub

View File

@@ -348,6 +348,22 @@ class NoteList extends React.Component {
properties: ['openFile', 'multiSelections'] properties: ['openFile', 'multiSelections']
} }
dialog.showOpenDialog(remote.getCurrentWindow(), options, (filepaths) => {
this.addNotesFromFiles(filepaths)
})
}
handleDrop (e) {
e.preventDefault()
const { location } = this.props
const filepaths = Array.from(e.dataTransfer.files).map(file => { return file.path })
if (!location.pathname.match(/\/trashed/)) this.addNotes(filepaths)
}
// Add notes to the current folder
addNotesFromFiles (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,28 +371,26 @@ 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) => { if (err) throw Error('File reading error: ', err)
if (err) throw Error('File reading error: ', err) const content = data.toString()
const content = data.toString() const newNote = {
const newNote = { content: content,
content: content, folder: folderKey,
folder: folderKey, title: markdown.strip(findNoteTitle(content)),
title: markdown.strip(striptags(findNoteTitle(content))), type: 'MARKDOWN_NOTE'
type: 'MARKDOWN_NOTE' }
} dataApi.createNote(storageKey, newNote)
dataApi.createNote(storageKey, newNote) .then((note) => {
.then((note) => { dispatch({
dispatch({ type: 'UPDATE_NOTE',
type: 'UPDATE_NOTE', note: note
note: note })
}) hashHistory.push({
hashHistory.push({ pathname: location.pathname,
pathname: location.pathname, query: {key: `${note.storage}-${note.key}`}
query: {key: `${note.storage}-${note.key}`}
})
}) })
}) })
}) })
@@ -439,6 +453,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'>