mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
feat multi drag and drop for changing folder
This commit is contained in:
@@ -400,8 +400,12 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleDragStart (e, note) {
|
handleDragStart (e, note) {
|
||||||
const noteData = JSON.stringify(note)
|
const { selectedNoteKeys } = this.state
|
||||||
|
const notes = this.notes.map((note) => Object.assign({}, note))
|
||||||
|
const selectedNotes = notes.filter((note) => selectedNoteKeys.includes(`${note.storage}-${note.key}`))
|
||||||
|
const noteData = JSON.stringify(selectedNotes)
|
||||||
e.dataTransfer.setData('note', noteData)
|
e.dataTransfer.setData('note', noteData)
|
||||||
|
this.setState({ selectedNoteKeys: [] })
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNoteContextMenu (e, uniqueKey) {
|
handleNoteContextMenu (e, uniqueKey) {
|
||||||
|
|||||||
@@ -142,40 +142,50 @@ class StorageItem extends React.Component {
|
|||||||
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
|
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dropNote (storage, folder, dispatch, location, noteData) {
|
||||||
|
noteData = noteData.filter((note) => folder.key !== note.folder)
|
||||||
|
const newNoteData = noteData.map((note) => Object.assign({}, note, {storage: storage, folder: folder.key}))
|
||||||
|
if (noteData.length === 0) return
|
||||||
|
|
||||||
|
Promise.all(
|
||||||
|
newNoteData.map((note) => dataApi.createNote(storage.key, note))
|
||||||
|
)
|
||||||
|
.then((createdNoteData) => {
|
||||||
|
createdNoteData.forEach((note) => {
|
||||||
|
dispatch({
|
||||||
|
type: 'UPDATE_NOTE',
|
||||||
|
note: note
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(`error on create notes: ${err}`)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return Promise.all(
|
||||||
|
noteData.map((note) => dataApi.deleteNote(note.storage, note.key))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.then((deletedNoteData) => {
|
||||||
|
console.log(deletedNoteData)
|
||||||
|
deletedNoteData.forEach((note) => {
|
||||||
|
dispatch({
|
||||||
|
type: 'DELETE_NOTE',
|
||||||
|
storageKey: note.storageKey,
|
||||||
|
noteKey: note.noteKey
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(`error on delete notes: ${err}`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
handleDrop (e, storage, folder, dispatch, location) {
|
handleDrop (e, storage, folder, dispatch, location) {
|
||||||
e.target.style.opacity = '1'
|
e.target.style.opacity = '1'
|
||||||
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
|
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
|
||||||
const noteData = JSON.parse(e.dataTransfer.getData('note'))
|
const noteData = JSON.parse(e.dataTransfer.getData('note'))
|
||||||
const newNoteData = Object.assign({}, noteData, {storage: storage, folder: folder.key})
|
this.dropNote(storage, folder, dispatch, location, noteData)
|
||||||
if (folder.key === noteData.folder) return
|
|
||||||
dataApi
|
|
||||||
.createNote(storage.key, newNoteData)
|
|
||||||
.then((note) => {
|
|
||||||
dataApi
|
|
||||||
.deleteNote(noteData.storage, noteData.key)
|
|
||||||
.then((data) => {
|
|
||||||
let dispatchHandler = () => {
|
|
||||||
dispatch({
|
|
||||||
type: 'DELETE_NOTE',
|
|
||||||
storageKey: data.storageKey,
|
|
||||||
noteKey: data.noteKey
|
|
||||||
})
|
|
||||||
}
|
|
||||||
eventEmitter.once('list:moved', dispatchHandler)
|
|
||||||
eventEmitter.emit('list:next')
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err)
|
|
||||||
})
|
|
||||||
dispatch({
|
|
||||||
type: 'UPDATE_NOTE',
|
|
||||||
note: note
|
|
||||||
})
|
|
||||||
hashHistory.push({
|
|
||||||
pathname: location.pathname,
|
|
||||||
query: {key: `${note.storage}-${note.key}`}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|||||||
Reference in New Issue
Block a user