@@ -19,9 +19,12 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
19
19
private _self = this ;
20
20
private _MyFavouritesServiceInstance : MyFavouritesService ;
21
21
private _MyFavouriteItems : IMyFavouriteItem [ ] = [ ] ;
22
+ private _EmptyMessageBarText : string = "" ;
23
+ private _AnimationClass : string = "ms-slideDownIn20" ;
22
24
constructor ( props : IMyFavouritesTopBarProps ) {
23
25
super ( props ) ;
24
26
this . state = {
27
+ loading : true ,
25
28
showPanel : false ,
26
29
showDialog : false ,
27
30
dialogTitle : "" ,
@@ -33,7 +36,8 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
33
36
} ,
34
37
isEdit : false ,
35
38
status : < Spinner size = { SpinnerSize . large } label = "Loading..." /> ,
36
- disableButtons : false
39
+ disableSave : true ,
40
+ disableCancel : false
37
41
} ;
38
42
39
43
this . _MyFavouritesServiceInstance = new MyFavouritesService ( this . props ) ;
@@ -67,23 +71,26 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
67
71
isLightDismiss = { true }
68
72
>
69
73
< div data-id = "menuPanel" >
70
- < TextField placeholder = "Filter favourites..."
71
- iconProps = { { iconName : "Filter" } }
72
- onBeforeChange = { this . _onFilterChanged . bind ( this ) } />
74
+ < TextField placeholder = "Filter favourites..."
75
+ iconProps = { { iconName : "Filter" } }
76
+ onBeforeChange = { this . _onFilterChanged . bind ( this ) } />
73
77
< div >
74
78
{ this . state . status }
75
79
</ div >
76
80
< FocusZone direction = { FocusZoneDirection . vertical } >
77
- { this . state . myFavouriteItems . length > 0 ?
81
+ { this . state . myFavouriteItems . length > 0 ?
78
82
< List
79
83
items = { this . state . myFavouriteItems }
80
84
onRenderCell = { this . _onRenderCell . bind ( this ) }
81
85
/> :
86
+ ! this . state . loading ?
82
87
< MessageBar
88
+ className = { this . _AnimationClass }
83
89
messageBarType = { MessageBarType . warning }
84
90
isMultiline = { false } >
85
- You do not have any favourites.
86
- </ MessageBar >
91
+ { this . _EmptyMessageBarText }
92
+ </ MessageBar > :
93
+ null
87
94
}
88
95
</ FocusZone >
89
96
</ div >
@@ -107,18 +114,19 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
107
114
</ div >
108
115
< TextField label = "Title"
109
116
onChanged = { this . _setTitle . bind ( this ) }
110
- value = { this . state . itemInContext . Title } />
117
+ value = { this . state . itemInContext . Title }
118
+ required = { true } />
111
119
< TextField label = "Description"
112
120
multiline rows = { 4 }
113
121
onChanged = { this . _setDescription . bind ( this ) }
114
122
value = { this . state . itemInContext . Description } />
115
123
< DialogFooter >
116
124
< PrimaryButton onClick = { this . _saveMyFavourite . bind ( this ) }
117
- disabled = { this . state . disableButtons }
125
+ disabled = { this . state . disableSave }
118
126
text = "Save" iconProps = { { iconName : "Save" } }
119
127
className = { styles . ccDialogButton } />
120
128
< DefaultButton onClick = { this . _hideDialog . bind ( this ) }
121
- disabled = { this . state . disableButtons }
129
+ disabled = { this . state . disableCancel }
122
130
text = "Cancel"
123
131
iconProps = { { iconName : "Cancel" } } />
124
132
</ DialogFooter >
@@ -139,23 +147,30 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
139
147
console . log ( favouriteItem ) ;
140
148
let status : JSX . Element = < span > </ span > ;
141
149
let dialogTitle : string = "Edit favourite" ;
142
- this . setState ( { ...this . state , showPanel : false , itemInContext : favouriteItem , isEdit : true , showDialog : true , dialogTitle, status } ) ;
150
+ this . setState ( { ...this . state , showPanel : false , itemInContext : favouriteItem , isEdit : true , showDialog : true , dialogTitle, status, disableSave : false } ) ;
143
151
}
144
152
145
153
private async _getMyFavourites ( ) : Promise < void > {
146
154
let status : JSX . Element = < Spinner size = { SpinnerSize . large } label = 'Loading...' /> ;
147
- this . setState ( { ...this . state , status } ) ;
155
+ let loading : boolean = true ;
156
+ this . setState ( { ...this . state , status, loading } ) ;
148
157
149
158
const myFavouriteItems : IMyFavouriteItem [ ] = await this . _MyFavouritesServiceInstance . getMyFavourites ( true ) ;
150
159
this . _MyFavouriteItems = myFavouriteItems ;
151
160
status = < span > </ span > ;
152
- this . setState ( { ...this . state , myFavouriteItems, status } ) ;
161
+ loading = false ;
162
+ if ( myFavouriteItems . length === 0 ) {
163
+ this . _EmptyMessageBarText = "You do not have any favourites" ;
164
+ }
165
+ this . setState ( { ...this . state , myFavouriteItems, status, loading } ) ;
153
166
}
154
167
155
168
private async _saveMyFavourite ( ) : Promise < void > {
156
- let status : JSX . Element = < Spinner size = { SpinnerSize . large } label = 'Loading...' /> ;
157
- let disableButtons : boolean = true ;
158
- this . setState ( { ...this . state , status, disableButtons } ) ;
169
+ let loadingText : string = this . state . isEdit ? "Updating..." : "Adding..." ;
170
+ let status : JSX . Element = < Spinner size = { SpinnerSize . large } label = { loadingText } /> ;
171
+ let disableSave : boolean = true ;
172
+ let disableCancel : boolean = true ;
173
+ this . setState ( { ...this . state , status, disableSave, disableCancel } ) ;
159
174
let itemToSave : IMyFavouriteItem = {
160
175
Title : this . state . itemInContext . Title ,
161
176
Description : this . state . itemInContext . Description
@@ -175,8 +190,8 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
175
190
There was an error!
176
191
</ MessageBar > ;
177
192
}
178
- disableButtons = false ;
179
- this . setState ( { ...this . state , status, disableButtons } ) ;
193
+ disableSave = disableCancel = false ;
194
+ this . setState ( { ...this . state , status, disableSave , disableCancel } ) ;
180
195
}
181
196
//#endregion
182
197
@@ -199,17 +214,17 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
199
214
let isEdit : boolean = false ;
200
215
let status : JSX . Element = < span > </ span > ;
201
216
let dialogTitle : string = "Add to my favourites" ;
202
- this . setState ( { ...this . state , itemInContext, isEdit, showDialog : true , dialogTitle, status } ) ;
217
+ let disableSave : boolean = true ;
218
+ this . setState ( { ...this . state , itemInContext, isEdit, showDialog : true , dialogTitle, status, disableSave } ) ;
203
219
}
204
220
205
221
private _hideDialog ( ) : void {
206
222
this . setState ( { showDialog : false } ) ;
207
223
}
208
224
209
225
private _onRenderCell ( myFavouriteItem : IMyFavouriteItem , index : number | undefined ) : JSX . Element {
210
- let animationClass : string = `ms-slideDownIn20` ;
211
226
return (
212
- < div className = { `${ animationClass } ${ styles . ccitemCell } ` } data-is-focusable = { true } >
227
+ < div className = { `${ this . _AnimationClass } ${ styles . ccitemCell } ` } data-is-focusable = { true } >
213
228
< MyFavoutiteDisplayItem
214
229
displayItem = { myFavouriteItem }
215
230
deleteFavourite = { this . deleteFavourite . bind ( this ) }
@@ -220,6 +235,7 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
220
235
221
236
private _onFilterChanged ( text : string ) : void {
222
237
let items : IMyFavouriteItem [ ] = this . _MyFavouriteItems ;
238
+ this . _EmptyMessageBarText = "There are no favourites which match the search text." ;
223
239
this . setState ( {
224
240
myFavouriteItems : text ?
225
241
items . filter ( item => item . Title . toLowerCase ( ) . indexOf ( text . toLowerCase ( ) ) >= 0 ) :
@@ -232,7 +248,11 @@ export default class MyFavouritesTopBar extends React.Component<IMyFavouritesTop
232
248
private _setTitle ( value : string ) : void {
233
249
let itemInContext : IMyFavouriteItem = this . state . itemInContext ;
234
250
itemInContext . Title = value ;
235
- this . setState ( { ...this . state , itemInContext } ) ;
251
+ let disableSave : boolean = true ;
252
+ if ( value . length > 0 ) {
253
+ disableSave = false ;
254
+ }
255
+ this . setState ( { ...this . state , itemInContext, disableSave } ) ;
236
256
}
237
257
238
258
private _setDescription ( value : string ) : void {
0 commit comments