Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Main extends React.Component {
codeStyle: "darcula"
},
justSaved: false,
saving: false,
justLoaded: false,
error: null
};
Expand Down Expand Up @@ -83,17 +84,19 @@ class Main extends React.Component {
evt.preventDefault();
const { preferences } = this.state;
if (preferences) {
this.setState({ saving: true });
let cid;
try {
cid = await savePreferences(preferences);
} catch (error) {
this.setState({ error: error.toString() });
this.setState({ error: error.toString(), saving: false });
return;
}
localStorage.setItem("preferenceCID", cid);
this.setState({
cid,
justSaved: true,
saving: false,
ipfsLoaded: true
});
}
Expand All @@ -119,6 +122,7 @@ class Main extends React.Component {
cid={this.state.cid}
preferences={this.state.preferences}
justSaved={this.state.justSaved}
saving={this.state.saving}
justLoaded={this.state.justLoaded}
onCIDChange={this.handleCIDChange}
onPrefChange={this.handlePrefChange}
Expand Down
5 changes: 4 additions & 1 deletion src/components/PreferenceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PreferenceForm extends React.Component {
};

render() {
const { preferences, justSaved, justLoaded, classes } = this.props;
const { preferences, justSaved, saving, justLoaded, classes } = this.props;

return (
<Paper className={classes.root}>
Expand Down Expand Up @@ -97,8 +97,10 @@ class PreferenceForm extends React.Component {
<SubmitButton
textNormal="Save"
textSubmitted="Saved"
textActive="Saving..."
icon={<SaveIcon />}
submitted={justSaved}
active={saving}
/>
</form>
</Paper>
Expand All @@ -110,6 +112,7 @@ PreferenceForm.propTypes = {
cid: PropTypes.string.isRequired,
preferences: PrefPropType.isRequired,
justSaved: PropTypes.bool.isRequired,
saving: PropTypes.bool.isRequired,
justLoaded: PropTypes.bool.isRequired,
onCIDChange: PropTypes.func.isRequired,
onPrefChange: PropTypes.func.isRequired,
Expand Down
16 changes: 13 additions & 3 deletions src/components/SubmitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ import Button from "@material-ui/core/Button";
import CheckIcon from "@material-ui/icons/Check";

const SubmitButton = props => {
const { submitted, textNormal, textSubmitted } = props;
const text = submitted ? textSubmitted : textNormal;
const icon = submitted ? <CheckIcon /> : props.icon;
const { submitted, active, textNormal, textSubmitted, textActive } = props;
let text, icon;
if (active) {
text = textActive;
} else if (submitted) {
text = textSubmitted;
icon = <CheckIcon />;
} else {
text = textNormal;
icon = props.icon;
}

return (
<Button
Expand All @@ -26,8 +34,10 @@ const SubmitButton = props => {
SubmitButton.propTypes = {
textNormal: PropTypes.string.isRequired,
textSubmitted: PropTypes.string.isRequired,
textActive: PropTypes.string,
icon: PropTypes.element,
submitted: PropTypes.bool,
active: PropTypes.bool,
classes: PropTypes.objectOf(PropTypes.string)
};

Expand Down