Skip to content

Commit 0ee0ae6

Browse files
authored
update on file change (#1717)
* update on file change * showing a spinner while uploading file
1 parent 83fb9cb commit 0ee0ae6

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

src/components/FileInput/FileInput.react.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class FileInput extends React.Component {
4949
}
5050
let label = this.renderLabel();
5151
let buttonStyles = [styles.button];
52-
if (this.props.disabled) {
52+
if (this.props.disabled || this.props.uploading) {
5353
buttonStyles.push(styles.disabled);
5454
}
5555
if (label) {
@@ -58,10 +58,14 @@ export default class FileInput extends React.Component {
5858

5959
return (
6060
<div className={styles.input}>
61-
<div className={buttonStyles.join(' ')}>
62-
{label ?
63-
<span>Change file</span> :
64-
<span>Upload a file</span>}
61+
<div className={buttonStyles.join(" ")}>
62+
{this.props.uploading ? (
63+
<div className={styles.spinner}></div>
64+
) : label ? (
65+
<span>Change file</span>
66+
) : (
67+
<span>Upload a file</span>
68+
)}
6569
<input {...inputProps} />
6670
</div>
6771
{label}

src/components/FileInput/FileInput.scss

+17
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949
}
5050
}
5151

52+
.spinner {
53+
display: inline-block;
54+
width: 20px;
55+
height: 20px;
56+
border: .15em solid $blue;
57+
vertical-align: bottom;
58+
border-right-color: transparent;
59+
border-radius: 50%;
60+
@include animation('spinner-border .75s linear infinite');
61+
}
62+
5263
.disabled, .disabled:hover {
5364
background: #e0e0ea;
5465
border-color: #e0e0ea;
@@ -75,4 +86,10 @@
7586

7687
a.label {
7788
color: $blue;
89+
}
90+
91+
@include keyframes(spinner-border) {
92+
100% {
93+
@include transform(rotate(360deg));
94+
}
7895
}

src/dashboard/Data/Browser/AddColumnDialog.react.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export default class AddColumnDialog extends React.Component {
3939
name: '',
4040
required: false,
4141
defaultValue: undefined,
42-
isDefaultValueValid: true
42+
isDefaultValueValid: true,
43+
uploadingFile: false
4344
};
4445
this.renderDefaultValueInput = this.renderDefaultValueInput.bind(this)
4546
this.handleDefaultValueChange = this.handleDefaultValueChange.bind(this)
@@ -77,8 +78,20 @@ export default class AddColumnDialog extends React.Component {
7778
if (file) {
7879
let base64 = await this.getBase64(file);
7980
const parseFile = new Parse.File(file.name, { base64 });
80-
await parseFile.save();
81-
return parseFile
81+
this.setState({
82+
uploadingFile: true
83+
});
84+
try {
85+
await parseFile.save();
86+
return parseFile;
87+
} catch (err) {
88+
this.props.showNote(err.message, true);
89+
return parseFile;
90+
} finally {
91+
this.setState({
92+
uploadingFile: false
93+
});
94+
}
8295
}
8396
}
8497

@@ -167,7 +180,8 @@ export default class AddColumnDialog extends React.Component {
167180
onChange={async (defaultValue) => await this.handleDefaultValueChange(defaultValue)} />
168181
case 'File':
169182
return <FileInput
170-
value={this.defaultValue ? this.defaultValue._name : ''}
183+
value={this.state.defaultValue ? this.state.defaultValue._name : ''}
184+
uploading={this.state.uploadingFile}
171185
onChange={async (defaultValue) => await this.handleDefaultValueChange(defaultValue)} />
172186
}
173187
}

src/dashboard/Data/Browser/Browser.react.js

+1
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ class Browser extends DashboardView {
11181118
classes={this.props.schema.data.get('classes').keySeq().toArray()}
11191119
onCancel={() => this.setState({ showAddColumnDialog: false })}
11201120
onConfirm={this.addColumn}
1121+
showNote={this.showNote}
11211122
parseServerVersion={currentApp.serverInfo && currentApp.serverInfo.parseServerVersion} />
11221123
);
11231124
} else if (this.state.showRemoveColumnDialog) {

0 commit comments

Comments
 (0)