1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Move note between folders

This commit is contained in:
Sosuke Suzuki
2017-04-01 02:36:48 +09:00
parent 6904c192e4
commit 720f07f62c
5 changed files with 71 additions and 7 deletions

View File

@@ -40,9 +40,10 @@ const TagElementList = (tags) => {
* @param {Object} note
* @param {Function} handleNoteClick
* @param {Function} handleNoteContextMenu
* @param {Function} handleDragStart
* @param {string} dateDisplay
*/
const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteContextMenu }) => (
const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteContextMenu, handleDragStart}) => (
<div styleName={isActive
? 'item--active'
: 'item'
@@ -50,6 +51,8 @@ const NoteItem = ({ isActive, note, dateDisplay, handleNoteClick, handleNoteCont
key={`${note.storage}-${note.key}`}
onClick={e => handleNoteClick(e, `${note.storage}-${note.key}`)}
onContextMenu={e => handleNoteContextMenu(e, `${note.storage}-${note.key}`)}
onDragStart={e => handleDragStart(e, note)}
draggable="true"
>
<div styleName='item-wrapper'>
<div styleName='item-bottom-time'>{dateDisplay}</div>
@@ -94,7 +97,9 @@ NoteItem.propTypes = {
isStarred: PropTypes.bool.isRequired
}),
handleNoteClick: PropTypes.func.isRequired,
handleNoteContextMenu: PropTypes.func.isRequired
handleNoteContextMenu: PropTypes.func.isRequired,
handleDragStart: PropTypes.func.isRequired,
handleDragEnd: PropTypes.func.isRequired
}
export default CSSModules(NoteItem, styles)

View File

@@ -11,8 +11,9 @@ import styles from './NoteItemSimple.styl'
* @param {Object} note
* @param {Function} handleNoteClick
* @param {Function} handleNoteContextMenu
* @param {Function} handleDragStart
*/
const NoteItemSimple = ({ isActive, note, handleNoteClick, handleNoteContextMenu }) => (
const NoteItemSimple = ({ isActive, note, handleNoteClick, handleNoteContextMenum, handleDragStart }) => (
<div styleName={isActive
? 'item-simple--active'
: 'item-simple'
@@ -20,6 +21,8 @@ const NoteItemSimple = ({ isActive, note, handleNoteClick, handleNoteContextMenu
key={`${note.storage}-${note.key}`}
onClick={e => handleNoteClick(e, `${note.storage}-${note.key}`)}
onContextMenu={e => handleNoteContextMenu(e, `${note.storage}-${note.key}`)}
onDragStart={e => handleDragStart(e, note)}
draggable="true"
>
<div styleName='item-simple-title'>
{note.type === 'SNIPPET_NOTE'
@@ -43,7 +46,8 @@ NoteItemSimple.propTypes = {
title: PropTypes.string.isrequired
}),
handleNoteClick: PropTypes.func.isRequired,
handleNoteContextMenu: PropTypes.func.isRequired
handleNoteContextMenu: PropTypes.func.isRequired,
handleDragStart: PropTypes.func.isRequired
}
export default CSSModules(NoteItemSimple, styles)

View File

@@ -14,11 +14,12 @@ import { isNumber } from 'lodash'
* @param {string} folderColor
* @param {boolean} isFolded
* @param {number} noteCount
* @param {Function} handleDrop
* @return {React.Component}
*/
const StorageItem = ({
isActive, handleButtonClick, handleContextMenu, folderName,
folderColor, isFolded, noteCount
folderColor, isFolded, noteCount, handleDrop
}) => (
<button styleName={isActive
? 'folderList-item--active'
@@ -26,6 +27,7 @@ const StorageItem = ({
}
onClick={handleButtonClick}
onContextMenu={handleContextMenu}
onDrop={handleDrop}
>
<span styleName={isFolded
? 'folderList-item-name--folded' : 'folderList-item-name'

View File

@@ -349,8 +349,13 @@ class NoteList extends React.Component {
})
}
handleDragStart (e, note) {
const noteData = JSON.stringify(note)
e.dataTransfer.setData("note", noteData)
}
render () {
let { location, notes, config } = this.props
let { location, notes, config, dispatch } = this.props
let sortFunc = config.sortBy === 'CREATED_AT'
? sortByCreatedAt
: config.sortBy === 'ALPHABETICAL'
@@ -382,6 +387,7 @@ class NoteList extends React.Component {
key={key}
handleNoteClick={this.handleNoteClick.bind(this)}
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
handleDragStart={this.handleDragStart.bind(this)}
/>
)
}
@@ -393,6 +399,7 @@ class NoteList extends React.Component {
key={key}
handleNoteClick={this.handleNoteClick.bind(this)}
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
handleDragStart={this.handleDragStart.bind(this)}
/>
)
})

View File

@@ -7,6 +7,7 @@ import CreateFolderModal from 'browser/main/modals/CreateFolderModal'
import RenameFolderModal from 'browser/main/modals/RenameFolderModal'
import dataApi from 'browser/main/lib/dataApi'
import StorageItemChild from 'browser/components/StorageItem'
import ee from 'browser/main/lib/eventEmitter'
const { remote } = require('electron')
const { Menu, MenuItem, dialog } = remote
@@ -131,8 +132,52 @@ class StorageItem extends React.Component {
}
}
handleDrop (e, storage, folder, dispatch, location) {
const noteData = JSON.parse(e.dataTransfer.getData("note"))
if (folder.key !== noteData.folder) {
dataApi
.createNote(storage.key, {
content: noteData.content,
createdAt: noteData.createdAt,
folder: folder.key,
isStarred: noteData.isStarred,
storage: storage,
title: noteData.title,
tags: noteData.tags,
type: noteData.type,
updatedAt: noteData.updatedAt,
description: noteData.description,
snippets: noteData.snippets
})
.then((note) => {
dispatch({
type: 'UPDATE_NOTE',
note: note
})
hashHistory.push({
pathname: location.pathname,
query: {key: note.storage + '-' + note.key}
})
})
dataApi
.deleteNote(noteData.storage, noteData.key)
.then((data) => {
let dispatchHandler = () => {
dispatch({
type: 'DELETE_NOTE',
storageKey: data.storageKey,
noteKey: data.noteKey
})
}
ee.once('list:moved', dispatchHandler)
ee.emit('list:next')
})
}
}
render () {
let { storage, location, isFolded, data } = this.props
let { storage, location, isFolded, data, dispatch } = this.props
let { folderNoteMap } = data
let folderList = storage.folders.map((folder) => {
let isActive = !!(location.pathname.match(new RegExp('\/storages\/' + storage.key + '\/folders\/' + folder.key)))
@@ -151,6 +196,7 @@ class StorageItem extends React.Component {
folderColor={folder.color}
isFolded={isFolded}
noteCount={noteCount}
handleDrop={(e) => this.handleDrop(e, storage, folder, dispatch, location)}
/>
)
})