@@ -3,6 +3,8 @@ import DisplayPanels from "./DisplayPanels";
3
3
import axios from "axios" ;
4
4
import { withStyles } from "@material-ui/styles" ;
5
5
import colors from "../colors" ;
6
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
7
+ import { faSyncAlt } from "@fortawesome/free-solid-svg-icons" ;
6
8
7
9
const styles = {
8
10
root : {
@@ -31,10 +33,46 @@ const styles = {
31
33
outline : "none" ,
32
34
border : "none" ,
33
35
} ,
36
+
34
37
"&:focus" : {
35
38
border : "none" ,
36
39
outline : "none" ,
37
40
} ,
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
+ } ,
38
76
} ,
39
77
} ;
40
78
@@ -45,6 +83,7 @@ class Overview extends Component {
45
83
currentDay : { } ,
46
84
previousDay : { } ,
47
85
dataChanges : { } ,
86
+ isLoading : false ,
48
87
} ;
49
88
this . calculateChange = this . calculateChange . bind ( this ) ;
50
89
this . fetchData = this . fetchData . bind ( this ) ;
@@ -55,6 +94,7 @@ class Overview extends Component {
55
94
}
56
95
57
96
async fetchData ( ) {
97
+ this . setState ( { isLoading : ! this . state . isLoading } ) ;
58
98
const response = await axios . get (
59
99
"https://api.rootnet.in/covid19-in/stats/history"
60
100
) ;
@@ -83,18 +123,28 @@ class Overview extends Component {
83
123
}
84
124
85
125
calculateChange ( ) {
86
- const { previousDay, currentDay } = this . state ;
126
+ const { previousDay, currentDay, isLoading } = this . state ;
87
127
let newObj = Object . keys ( currentDay ) . reduce ( ( a , k ) => {
88
128
a [ k ] = currentDay [ k ] - previousDay [ k ] ;
89
129
return a ;
90
130
} , { } ) ;
91
- this . setState ( { dataChanges : newObj } ) ;
131
+ this . setState ( { dataChanges : newObj , isLoading : ! isLoading } ) ;
92
132
}
93
133
94
134
render ( ) {
95
135
const { confirmed, recovered, deaths, activeCases } = this . state . currentDay ;
96
136
const dataChange = this . state . dataChanges ;
97
137
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
+
98
148
return (
99
149
< div className = { classes . root } >
100
150
< div className = { classes . panels } >
@@ -121,6 +171,7 @@ class Overview extends Component {
121
171
</ div >
122
172
123
173
< button className = { classes . button } onClick = { this . fetchData } >
174
+ { /* <FontAwesomeIcon icon={faSyncAlt} className={classes.refreshIcon} /> */ }
124
175
Update Results
125
176
</ button >
126
177
</ div >
0 commit comments