Skip to content

Commit 4c19a09

Browse files
committed
Merge pull request #61 from parallaxinc/toasts
Toasts
2 parents ec96c59 + 3a4bdfe commit 4c19a09

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react-mfb-iceddev": "^0.1.0",
1818
"react-select": "^0.4.0",
1919
"react-style": "^0.4.0",
20-
"skrim": "0.0.2",
20+
"skrim": "0.0.3",
2121
"snacks": "^0.2.0",
2222
"when": "^3.7.2"
2323
},

plugins/sidebar/file-operations.js

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,30 @@ const NewFileOverlay = require('./overlays/new-file');
1010
const DownloadOverlay = require('./overlays/download');
1111
const DeleteConfirmOverlay = require('./overlays/delete-confirm');
1212

13+
const styles = require('./styles');
14+
1315
const 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
);

plugins/sidebar/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const ProjectOperations = require('./project-operations');
1212
function sidebar(app, opts, done){
1313

1414
const space = app.workspace;
15+
const toast = app.toast;
1516
const overlay = app.overlay;
1617
const userConfig = app.userConfig;
1718
const programmer = app.bs2serial;
@@ -27,7 +28,7 @@ function sidebar(app, opts, done){
2728
<ListItem icon="folder" disableRipple>{space.cwd.deref()}</ListItem>
2829
{directory.map((file) => <File key={file.get('name')} workspace={space} filename={file.get('name')} temp={file.get('temp')} />)}
2930
</FileList>
30-
<FileOperations workspace={space} overlay={overlay} programmer={programmer} />
31+
<FileOperations workspace={space} overlay={overlay} toast={toast} programmer={programmer} />
3132
</Sidebar>
3233
);
3334

plugins/sidebar/styles.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const StyleSheet = require('react-style');
44

5+
const red = '#da2100';
6+
const green = '#159600';
7+
58
const styles = {
69
card: StyleSheet.create({
710
margin: 0,
@@ -63,15 +66,21 @@ const styles = {
6366
marginTop: 10
6467
}),
6568
fileTempIndicator: {
66-
backgroundColor: '#159600',
69+
backgroundColor: green,
6770
height: 10,
6871
width: 10,
6972
borderRadius: '100%',
7073
marginRight: 5,
7174
display: 'inline-block'
7275
},
7376
fileHasTemp: {
74-
backgroundColor: '#da2100'
77+
backgroundColor: red
78+
},
79+
errorToast: {
80+
backgroundColor: red
81+
},
82+
successToast: {
83+
backgroundColor: green
7584
}
7685
};
7786

0 commit comments

Comments
 (0)