Skip to content

Commit 36ab944

Browse files
Add refresh Icon
1 parent bec385f commit 36ab944

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@fortawesome/fontawesome-svg-core": "^1.2.28",
7+
"@fortawesome/free-solid-svg-icons": "^5.13.0",
8+
"@fortawesome/react-fontawesome": "^0.1.9",
69
"@material-ui/styles": "^4.9.10",
710
"@testing-library/jest-dom": "^4.2.4",
811
"@testing-library/react": "^9.5.0",

src/components/CovidApp.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Overview from "./Overview";
33
import Navbar from "./Navbar";
44
import { withStyles } from "@material-ui/styles";
55
import colors from "../colors";
6+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
7+
import { faSyncAlt } from "@fortawesome/free-solid-svg-icons";
68

79
const styles = {
810
root: {
@@ -41,6 +43,7 @@ class CovidApp extends Component {
4143

4244
render() {
4345
const { classes } = this.props;
46+
4447
return (
4548
<div className={classes.root}>
4649
<div className={classes.navBar}>

src/components/Overview.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import DisplayPanels from "./DisplayPanels";
33
import axios from "axios";
44
import { withStyles } from "@material-ui/styles";
55
import colors from "../colors";
6+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
7+
import { faSyncAlt } from "@fortawesome/free-solid-svg-icons";
68

79
const styles = {
810
root: {
@@ -31,10 +33,46 @@ const styles = {
3133
outline: "none",
3234
border: "none",
3335
},
36+
3437
"&:focus": {
3538
border: "none",
3639
outline: "none",
3740
},
41+
42+
"&:hover svg": {
43+
animationName: "$rotation",
44+
animationDuration: "1s",
45+
animationTimingFunction: "linear",
46+
animationIterationCount: "infinite",
47+
},
48+
},
49+
50+
// refreshIcon: {
51+
// marginRight: "1rem",
52+
// },
53+
54+
refreshIcon: {
55+
fontSize: "10rem",
56+
animationName: "$rotation",
57+
animationDuration: "1s",
58+
animationTimingFunction: "linear",
59+
animationIterationCount: "infinite",
60+
},
61+
62+
loadingIcon: {
63+
height: "50vh",
64+
display: "flex",
65+
justifyContent: "center",
66+
alignItems: "center",
67+
},
68+
69+
"@keyframes rotation": {
70+
from: {
71+
transform: "rotate(0deg)",
72+
},
73+
to: {
74+
transform: "rotate(359deg)",
75+
},
3876
},
3977
};
4078

@@ -45,6 +83,7 @@ class Overview extends Component {
4583
currentDay: {},
4684
previousDay: {},
4785
dataChanges: {},
86+
isLoading: false,
4887
};
4988
this.calculateChange = this.calculateChange.bind(this);
5089
this.fetchData = this.fetchData.bind(this);
@@ -55,6 +94,7 @@ class Overview extends Component {
5594
}
5695

5796
async fetchData() {
97+
this.setState({ isLoading: !this.state.isLoading });
5898
const response = await axios.get(
5999
"https://api.rootnet.in/covid19-in/stats/history"
60100
);
@@ -83,18 +123,28 @@ class Overview extends Component {
83123
}
84124

85125
calculateChange() {
86-
const { previousDay, currentDay } = this.state;
126+
const { previousDay, currentDay, isLoading } = this.state;
87127
let newObj = Object.keys(currentDay).reduce((a, k) => {
88128
a[k] = currentDay[k] - previousDay[k];
89129
return a;
90130
}, {});
91-
this.setState({ dataChanges: newObj });
131+
this.setState({ dataChanges: newObj, isLoading: !isLoading });
92132
}
93133

94134
render() {
95135
const { confirmed, recovered, deaths, activeCases } = this.state.currentDay;
96136
const dataChange = this.state.dataChanges;
97137
const { classes } = this.props;
138+
const { isLoading } = this.state;
139+
140+
if (isLoading) {
141+
return (
142+
<div className={classes.loadingIcon}>
143+
<FontAwesomeIcon icon={faSyncAlt} className={classes.refreshIcon} />
144+
</div>
145+
);
146+
}
147+
98148
return (
99149
<div className={classes.root}>
100150
<div className={classes.panels}>
@@ -121,6 +171,7 @@ class Overview extends Component {
121171
</div>
122172

123173
<button className={classes.button} onClick={this.fetchData}>
174+
{/* <FontAwesomeIcon icon={faSyncAlt} className={classes.refreshIcon} /> */}
124175
Update Results
125176
</button>
126177
</div>

0 commit comments

Comments
 (0)