@@ -9,6 +9,7 @@ interface User {
9
9
} ;
10
10
11
11
interface State {
12
+ noteState : 'LOADING' | 'OPEN' ,
12
13
currentNoteId : string ,
13
14
editorContent : string ,
14
15
} ;
@@ -30,6 +31,7 @@ export default class WebClientController{
30
31
categories : { }
31
32
} ;
32
33
this . _state = {
34
+ noteState : 'LOADING' ,
33
35
currentNoteId : '' ,
34
36
editorContent : '' ,
35
37
} ;
@@ -62,6 +64,10 @@ export default class WebClientController{
62
64
63
65
// 切换笔记
64
66
app . $on ( 'note.switchActive' , async ( data : any ) => {
67
+ this . _state . noteState = 'LOADING' ;
68
+ this . _view . setData ( 'editor' , {
69
+ content : ''
70
+ } ) ;
65
71
const note = ( await this . _model . Note . find ( data . id ) ) . data . data ;
66
72
this . _view . setData ( 'editor' , {
67
73
content : note . content
@@ -71,16 +77,17 @@ export default class WebClientController{
71
77
72
78
// 笔记内容发生变化
73
79
app . $on ( 'editor.change' , async ( data : any ) => {
74
- // console.log('currentNoteId', this._state.currentNoteId);
75
- // console.log('content', data.content);
76
- // todo: 第一次变更不需要保存
77
- // todo: 内容与id必须得对应,要不然会串
78
- if ( ! this . _state . currentNoteId ) return ;
79
- if ( ! data . content ) return ;
80
+ console . log ( 'editor.change' , this . _state . currentNoteId , data . content , this . _state . noteState ) ;
81
+ if ( this . _state . noteState === 'LOADING' ) {
82
+ if ( this . _state . currentNoteId && data . content ) {
83
+ this . _state . noteState = 'OPEN' ;
84
+ }
85
+ return ;
86
+ }
87
+ // if(!data.content) return;
80
88
await this . _model . Note . update ( this . _state . currentNoteId , {
81
89
content : data . content
82
90
} ) ;
83
- // console.log('content change saved.');
84
91
} ) ;
85
92
}
86
93
0 commit comments