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

change folder

This commit is contained in:
Dick Choi
2016-07-21 23:44:00 +09:00
parent 3882df41f1
commit a6e3dbd825
6 changed files with 118 additions and 20 deletions

View File

@@ -166,20 +166,20 @@ class FolderSelect extends React.Component {
}
}
handleOptionClick (folderKey) {
handleOptionClick (storageKey, folderKey) {
return (e) => {
e.stopPropagation()
this.setState({
status: 'FOCUS'
}, () => {
this.setValue(folderKey)
this.setValue(storageKey + '-' + folderKey)
this.refs.root.focus()
})
}
}
setValue (folderKey) {
this.value = folderKey
setValue (value) {
this.value = value
this.props.onChange()
}
@@ -208,7 +208,7 @@ class FolderSelect extends React.Component {
: 'search-optionList-item'
}
key={option.storage.key + '-' + option.folder.key}
onClick={(e) => this.handleOptionClick(option.folder.key)(e)}
onClick={(e) => this.handleOptionClick(option.storage.key, option.folder.key)(e)}
>
<span styleName='search-optionList-item-name'
style={{borderColor: option.folder.color}}

View File

@@ -7,6 +7,7 @@ import TagSelect from './TagSelect'
import FolderSelect from './FolderSelect'
import Commander from 'browser/main/lib/Commander'
import dataApi from 'browser/main/lib/dataApi'
import { hashHistory } from 'react-router'
const electron = require('electron')
const { remote } = electron
@@ -20,9 +21,9 @@ class MarkdownNoteDetail extends React.Component {
this.state = {
note: Object.assign({
title: '',
content: ''
}, props.note),
isDispatchQueued: false
content: '',
isMovingNote: false
}, props.note)
}
this.dispatchTimer = null
}
@@ -43,14 +44,9 @@ class MarkdownNoteDetail extends React.Component {
}
componentWillReceiveProps (nextProps) {
if (nextProps.note.key !== this.props.note.key) {
if (this.state.isDispatchQueued) {
this.cancelDispatchQueue()
this.dispatch()
}
if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) {
this.setState({
note: Object.assign({}, nextProps.note),
isDispatchQueued: false
note: Object.assign({}, nextProps.note)
}, () => {
this.refs.content.reload()
this.refs.tags.reset()
@@ -114,7 +110,36 @@ class MarkdownNoteDetail extends React.Component {
}
handleFolderChange (e) {
let { note } = this.state
let value = this.refs.folder.value
let splitted = value.split('-')
let newStorageKey = splitted.shift()
let newFolderKey = splitted.shift()
dataApi
.moveNote(note.storage, note.folder, note.key, newStorageKey, newFolderKey)
.then((newNote) => {
this.setState({
isMovingNote: true,
note: Object.assign({}, newNote)
}, () => {
let { dispatch, location } = this.props
dispatch({
type: 'MOVE_NOTE',
note: note,
newNote: newNote
})
hashHistory.replace({
pathname: location.pathname,
query: {
key: newNote.uniqueKey
}
})
this.setState({
isMovingNote: false
})
})
})
}
handleStarButtonClick (e) {

View File

@@ -8,6 +8,7 @@ import FolderSelect from './FolderSelect'
import Commander from 'browser/main/lib/Commander'
import dataApi from 'browser/main/lib/dataApi'
import modes from 'browser/lib/modes'
import { hashHistory } from 'react-router'
const electron = require('electron')
const { remote } = electron
@@ -118,7 +119,36 @@ class SnippetNoteDetail extends React.Component {
}
handleFolderChange (e) {
let { note } = this.state
let value = this.refs.folder.value
let splitted = value.split('-')
let newStorageKey = splitted.shift()
let newFolderKey = splitted.shift()
dataApi
.moveNote(note.storage, note.folder, note.key, newStorageKey, newFolderKey)
.then((newNote) => {
this.setState({
isMovingNote: true,
note: Object.assign({}, newNote)
}, () => {
let { dispatch, location } = this.props
dispatch({
type: 'MOVE_NOTE',
note: note,
newNote: newNote
})
hashHistory.replace({
pathname: location.pathname,
query: {
key: newNote.uniqueKey
}
})
this.setState({
isMovingNote: false
})
})
})
}
handleStarButtonClick (e) {

View File

@@ -4,6 +4,7 @@ import styles from './Detail.styl'
import _ from 'lodash'
import MarkdownNoteDetail from './MarkdownNoteDetail'
import SnippetNoteDetail from './SnippetNoteDetail'
import dataApi from 'browser/main/lib/dataApi'
const electron = require('electron')
@@ -51,7 +52,8 @@ class Detail extends React.Component {
'dispatch',
'storages',
'style',
'ignorePreviewPointerEvents'
'ignorePreviewPointerEvents',
'location'
])}
/>
)
@@ -65,7 +67,8 @@ class Detail extends React.Component {
'dispatch',
'storages',
'style',
'ignorePreviewPointerEvents'
'ignorePreviewPointerEvents',
'location'
])}
/>
)

View File

@@ -18,12 +18,15 @@ function queueSaveFolder (storageKey, folderKey) {
clearTimeout(task.timer)
})
queuedTasks = queuedTasks.filter((task) => task.storage !== storageKey || task.folder !== folderKey)
let newTimer = setTimeout(() => {
let folderNotes = notes.filter((note) => note.storage === storageKey && note.folder === folderKey)
sander
.writeFile(path.join(storage.cache.path, folderKey, 'data.json'), JSON.stringify({
notes: folderNotes
notes: folderNotes.map((note) => {
let json = note.toJSON()
delete json.storage
return json
})
}))
}, 1500)
@@ -398,6 +401,35 @@ function removeNote (storageKey, folderKey, noteKey, input) {
}
function moveNote (storageKey, folderKey, noteKey, newStorageKey, newFolderKey) {
let note = _.find(notes, {
key: noteKey,
storage: storageKey,
folder: folderKey
})
if (note == null) throw new Error('Note doesn\'t exist.')
let storage = _.find(storages, {key: newStorageKey})
if (storage == null) throw new Error('Storage doesn\'t exist.')
let folder = _.find(storage.data.folders, {key: newFolderKey})
if (folder == null) throw new Error('Folder doesn\'t exist.')
note.storage = storage.key
note.data.storage = storage.key
note.folder = folder.key
note.data.folder = folder.key
let key = note.key
while (notes.some((note) => note.storage === storage.key && note.folder === folder.key && note.key === key)) {
key = keygen()
}
note.key = key
note.data.key = key
note.uniqueKey = `${note.storage}-${note.folder}-${note.key}`
console.log(note.uniqueKey)
queueSaveFolder(storageKey, folderKey)
return note.save()
.then(() => note.toJSON())
}
export default {
init,
addStorage,
@@ -408,5 +440,6 @@ export default {
createMarkdownNote,
createSnippetNote,
updateNote,
removeNote
removeNote,
moveNote
}

View File

@@ -79,6 +79,13 @@ function notes (state = [], action) {
notes.push(action.note)
return notes
}
case 'MOVE_NOTE':
{
let notes = state.slice()
notes = notes.filter((note) => note.key !== action.note.key || note.folder !== action.note.folder || note.storage !== action.note.storage)
notes.push(action.newNote)
return notes
}
}
return state
}