@@ -7,6 +7,7 @@ import TagSelect from './TagSelect'
77import FolderSelect from './FolderSelect'
88import Commander from 'browser/main/lib/Commander'
99import dataApi from 'browser/main/lib/dataApi'
10+ import { hashHistory } from 'react-router'
1011
1112const electron = require ( 'electron' )
1213const { remote } = electron
@@ -20,9 +21,9 @@ class MarkdownNoteDetail extends React.Component {
2021 this . state = {
2122 note : Object . assign ( {
2223 title : '' ,
23- content : ''
24- } , props . note ) ,
25- isDispatchQueued : false
24+ content : '' ,
25+ isMovingNote : false
26+ } , props . note )
2627 }
2728 this . dispatchTimer = null
2829 }
@@ -43,14 +44,9 @@ class MarkdownNoteDetail extends React.Component {
4344 }
4445
4546 componentWillReceiveProps ( nextProps ) {
46- if ( nextProps . note . key !== this . props . note . key ) {
47- if ( this . state . isDispatchQueued ) {
48- this . cancelDispatchQueue ( )
49- this . dispatch ( )
50- }
47+ if ( nextProps . note . key !== this . props . note . key && ! this . isMovingNote ) {
5148 this . setState ( {
52- note : Object . assign ( { } , nextProps . note ) ,
53- isDispatchQueued : false
49+ note : Object . assign ( { } , nextProps . note )
5450 } , ( ) => {
5551 this . refs . content . reload ( )
5652 this . refs . tags . reset ( )
@@ -114,7 +110,36 @@ class MarkdownNoteDetail extends React.Component {
114110 }
115111
116112 handleFolderChange ( e ) {
113+ let { note } = this . state
114+ let value = this . refs . folder . value
115+ let splitted = value . split ( '-' )
116+ let newStorageKey = splitted . shift ( )
117+ let newFolderKey = splitted . shift ( )
117118
119+ dataApi
120+ . moveNote ( note . storage , note . folder , note . key , newStorageKey , newFolderKey )
121+ . then ( ( newNote ) => {
122+ this . setState ( {
123+ isMovingNote : true ,
124+ note : Object . assign ( { } , newNote )
125+ } , ( ) => {
126+ let { dispatch, location } = this . props
127+ dispatch ( {
128+ type : 'MOVE_NOTE' ,
129+ note : note ,
130+ newNote : newNote
131+ } )
132+ hashHistory . replace ( {
133+ pathname : location . pathname ,
134+ query : {
135+ key : newNote . uniqueKey
136+ }
137+ } )
138+ this . setState ( {
139+ isMovingNote : false
140+ } )
141+ } )
142+ } )
118143 }
119144
120145 handleStarButtonClick ( e ) {
0 commit comments