@@ -10,16 +10,30 @@ const NewFileOverlay = require('./overlays/new-file');
1010const DownloadOverlay = require ( './overlays/download' ) ;
1111const DeleteConfirmOverlay = require ( './overlays/delete-confirm' ) ;
1212
13+ const styles = require ( './styles' ) ;
14+
1315const FileOperations = React . createClass ( {
16+ handleError : function ( err ) {
17+ const toast = this . props . toast ;
18+
19+ toast . show ( err . message , { style : styles . errorToast } ) ;
20+ } ,
21+ handleSuccess : function ( msg ) {
22+ const toast = this . props . toast ;
23+
24+ toast . show ( msg , { style : styles . successToast , timeout : 5000 } ) ;
25+ } ,
1426 saveFile : function ( evt ) {
1527 evt . preventDefault ( ) ;
1628
1729 const space = this . props . workspace ;
1830
31+ const name = space . filename . deref ( ) ;
32+
1933 // TODO: these should transparently accept cursors for all non-function params
20- space . saveFile ( space . filename . deref ( ) , space . current , function ( err ) {
21- console . log ( 'saved' , err ) ;
22- } ) ;
34+ space . saveFile ( name , space . current )
35+ . tap ( ( ) => this . handleSuccess ( `' ${ name } ' saved successfully` ) )
36+ . catch ( this . handleError ) ;
2337 } ,
2438 createFile : function ( name ) {
2539 const space = this . props . workspace ;
@@ -32,7 +46,10 @@ const FileOperations = React.createClass({
3246 space . filename . update ( ( ) => name ) ;
3347 space . current . update ( ( ) => '' ) ;
3448 // TODO: these should transparently accept cursors for all non-function params
35- space . saveFile ( space . filename . deref ( ) , space . current , overlay . hide ) ;
49+ space . saveFile ( space . filename . deref ( ) , space . current )
50+ . tap ( ( ) => this . handleSuccess ( `'${ name } ' created successfully` ) )
51+ . catch ( this . handleError )
52+ . finally ( overlay . hide ) ;
3653 } ,
3754 deleteFile : function ( name ) {
3855 const space = this . props . workspace ;
@@ -42,12 +59,17 @@ const FileOperations = React.createClass({
4259 return ;
4360 }
4461
45- space . deleteFile ( space . filename , overlay . hide ) ;
62+ space . deleteFile ( space . filename )
63+ . tap ( ( ) => this . handleSuccess ( `'${ name } ' deleted successfully` ) )
64+ . catch ( this . handleError )
65+ . finally ( overlay . hide ) ;
4666 } ,
4767 download : function ( devicePath ) {
68+ const toast = this . props . toast ;
4869 const space = this . props . workspace ;
4970 const overlay = this . props . overlay ;
5071 const programmer = this . props . programmer ;
72+ const name = space . filename . deref ( ) ;
5173
5274 if ( ! devicePath ) {
5375 return ;
@@ -65,13 +87,10 @@ const FileOperations = React.createClass({
6587
6688 return programmer . bootload ( options ) ;
6789 } )
68- . tap ( function ( ) {
69- console . log ( 'Success!' ) ;
70- overlay . hide ( ) ;
71- } )
72- . catch ( function ( err ) {
73- console . log ( 'Failed: ' , err ) ;
74- } ) ;
90+ . tap ( ( ) => toast . clear ( ) )
91+ . tap ( ( ) => this . handleSuccess ( `'${ name } ' downloaded successfully` ) )
92+ . catch ( this . handleError )
93+ . finally ( overlay . hide ) ;
7594 } ,
7695 renderOverlay : function ( component ) {
7796 const overlay = this . props . overlay ;
@@ -102,9 +121,15 @@ const FileOperations = React.createClass({
102121
103122 const space = this . props . workspace ;
104123
124+ const name = space . filename . deref ( ) ;
125+
126+ if ( ! name ) {
127+ return ;
128+ }
129+
105130 const component = (
106131 < DeleteConfirmOverlay
107- name = { space . filename . deref ( ) }
132+ name = { name }
108133 onAccept = { this . deleteFile }
109134 onCancel = { this . hideOverlay } />
110135 ) ;
0 commit comments