Skip to content

Commit af4019c

Browse files
authored
Spinner (#12)
* added spinner to prevent UI snapping on ipfs load * change where ipfsLoaded is set
1 parent 1791ade commit af4019c

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/components/Loader.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
import { withStyles, createStyles } from "@material-ui/core/styles";
4+
import CircularProgress from "@material-ui/core/CircularProgress";
5+
6+
const Loader = props => {
7+
const { loaded, classes } = props;
8+
if (loaded) {
9+
return props.children;
10+
}
11+
return (
12+
<div className={classes.root}>
13+
<CircularProgress size={100} />
14+
</div>
15+
);
16+
};
17+
18+
Loader.propTypes = {
19+
loaded: PropTypes.bool,
20+
children: PropTypes.element,
21+
classes: PropTypes.objectOf(PropTypes.string)
22+
};
23+
24+
const styles = theme =>
25+
createStyles({
26+
root: {
27+
display: "flex",
28+
justifyContent: "center",
29+
alignItems: "center",
30+
paddingTop: theme.spacing(8)
31+
}
32+
});
33+
34+
export default withStyles(styles)(Loader);

src/components/Main.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import Typography from "@material-ui/core/Typography";
77
import PreferenceForm from "./PreferenceForm";
88
import Preview from "./Preview";
99
import ErrorSnackbar from "./ErrorSnackbar";
10+
import Loader from "./Loader";
1011
import { loadPreferences, savePreferences } from "../ipfs/preferences";
1112

1213
const DEFAULT_CID = "QmYiGo3KpK5Ca928ujpH2MKJgVEkLE981gj1QERYC5h8e8";
1314
class Main extends React.Component {
1415
state = {
16+
ipfsLoaded: false,
1517
cid: "",
1618
preferences: {
1719
username: "",
@@ -61,7 +63,8 @@ class Main extends React.Component {
6163
this.setState({
6264
cid,
6365
preferences,
64-
justLoaded: true
66+
justLoaded: true,
67+
ipfsLoaded: true
6568
});
6669
};
6770

@@ -104,7 +107,6 @@ class Main extends React.Component {
104107
<Typography variant="h4" gutterBottom>
105108
IPFS Portable User Settings
106109
</Typography>
107-
{/* <div className={classes.main}> */}
108110
<Grid container spacing={3}>
109111
<Grid item sm={12} md={6}>
110112
<PreferenceForm
@@ -119,13 +121,14 @@ class Main extends React.Component {
119121
/>
120122
</Grid>
121123
<Grid item sm={12} md={6}>
122-
<Preview
123-
cid={this.state.cid}
124-
preferences={this.state.preferences}
125-
/>
124+
<Loader loaded={this.state.ipfsLoaded}>
125+
<Preview
126+
cid={this.state.cid}
127+
preferences={this.state.preferences}
128+
/>
129+
</Loader>
126130
</Grid>
127131
</Grid>
128-
{/* </div> */}
129132
<ErrorSnackbar
130133
error={this.state.error}
131134
onClose={this.handleErrorClose}

src/components/SubmitButton.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ SubmitButton.propTypes = {
2727
textNormal: PropTypes.string.isRequired,
2828
textSubmitted: PropTypes.string.isRequired,
2929
icon: PropTypes.element,
30-
submitted: PropTypes.bool
30+
submitted: PropTypes.bool,
31+
classes: PropTypes.objectOf(PropTypes.string)
3132
};
3233

3334
const styles = theme =>

0 commit comments

Comments
 (0)