Skip to content

Commit bac9289

Browse files
Add updates icons and data
1 parent 8f48ae2 commit bac9289

File tree

5 files changed

+114
-13
lines changed

5 files changed

+114
-13
lines changed

package-lock.json

Lines changed: 5 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@testing-library/user-event": "^7.2.1",
1515
"axios": "^0.19.2",
1616
"classnames": "^2.2.6",
17+
"date-fns": "^2.13.0",
1718
"react": "^16.13.1",
1819
"react-content-loader": "^5.0.4",
1920
"react-dom": "^16.13.1",

src/components/CovidApp.js

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from "react";
2+
import { formatDistance, format } from "date-fns";
23
import Overview from "./Overview";
34
import { withStyles } from "@material-ui/styles";
45
import colors from "../constants/colors";
@@ -7,7 +8,11 @@ import DisplayTable from "./DisplayTable";
78
import styles from "../styles/CovidAppStyles";
89
import axios from "axios";
910
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
10-
import { faSyncAlt } from "@fortawesome/free-solid-svg-icons";
11+
import {
12+
faSyncAlt,
13+
faBell,
14+
faBellSlash,
15+
} from "@fortawesome/free-solid-svg-icons";
1116
import "../styles/DarkModeButton.css";
1217
import MapSection from "./MapSection";
1318
import Barchart from "./Barchart";
@@ -42,6 +47,7 @@ class CovidApp extends Component {
4247
this.formatData = this.formatData.bind(this);
4348
this.findId = this.findId.bind(this);
4449
this.handleFormat = this.handleFormat.bind(this);
50+
this.handleNotification = this.handleNotification.bind(this);
4551
}
4652

4753
componentDidMount() {
@@ -57,12 +63,16 @@ class CovidApp extends Component {
5763
const stateChanges = axios.get(
5864
"https://api.covid19india.org/states_daily.json"
5965
);
66+
const updates = axios.get(
67+
"https://api.covid19india.org/updatelog/log.json"
68+
);
6069

61-
axios.all([countryData, districtLevel, stateChanges]).then(
70+
axios.all([countryData, districtLevel, stateChanges, updates]).then(
6271
axios.spread((...responses) => {
6372
const countryData = responses[0].data;
6473
const districtLevel = responses[1].data;
6574
// const stateChanges = responses[2].data;
75+
const updates = responses[3].data;
6676

6777
const [todayData] = countryData.statewise.slice(0, 1);
6878
const casesTimeline = countryData.cases_time_series;
@@ -75,6 +85,8 @@ class CovidApp extends Component {
7585
todayData: todayData,
7686
casesTimeline: casesTimeline,
7787
districtLevel: districtLevel,
88+
updates: updates,
89+
expanded: false,
7890
},
7991
this.handleFormat
8092
);
@@ -109,9 +121,20 @@ class CovidApp extends Component {
109121
this.setState({ mapData: newdata });
110122
}
111123

124+
handleNotification() {
125+
this.setState({ expanded: !this.state.expanded });
126+
}
127+
112128
render() {
113129
const { classes, setDarkMode, isDarkMode } = this.props;
114-
const { mapData, isLoading, data, districtLevel } = this.state;
130+
const {
131+
mapData,
132+
isLoading,
133+
data,
134+
districtLevel,
135+
expanded,
136+
updates,
137+
} = this.state;
115138

116139
if (isLoading) {
117140
return (
@@ -120,10 +143,34 @@ class CovidApp extends Component {
120143
</div>
121144
);
122145
}
146+
let displayUpdates;
147+
try {
148+
displayUpdates = updates
149+
.slice(-5)
150+
.reverse()
151+
.map(({ update, timestamp }, i) => {
152+
update = update.replace("\n", "<br/>");
153+
return (
154+
<React.Fragment key={i}>
155+
<h5>
156+
{`${formatDistance(
157+
new Date(timestamp * 1000),
158+
new Date()
159+
)} ago`}
160+
</h5>
161+
<h4
162+
dangerouslySetInnerHTML={{
163+
__html: update,
164+
}}
165+
></h4>
166+
</React.Fragment>
167+
);
168+
});
169+
} catch (err) {}
123170

124171
return (
125-
<FadeIn>
126-
<div className={classes.header}>
172+
<>
173+
<div className={classes.header} style={{ zIndex: "999" }}>
127174
<h1 className={classes.heading}>
128175
<span>Covid-19</span> India Trend
129176
</h1>
@@ -134,6 +181,22 @@ class CovidApp extends Component {
134181
onClick={this.fetchData}
135182
/>
136183
</div>
184+
<div className={classes.updates}>
185+
<div className={classes.notification}>
186+
{expanded ? (
187+
<FontAwesomeIcon
188+
icon={faBellSlash}
189+
onClick={this.handleNotification}
190+
/>
191+
) : (
192+
<FontAwesomeIcon
193+
icon={faBell}
194+
onClick={this.handleNotification}
195+
/>
196+
)}
197+
</div>
198+
<div className={classes.update}>{expanded && displayUpdates}</div>
199+
</div>
137200
<div className="darkModeButton">
138201
<label className="switch">
139202
<input
@@ -145,11 +208,13 @@ class CovidApp extends Component {
145208
</label>
146209
</div>
147210
</div>
148-
<Overview
149-
isDarkMode={isDarkMode}
150-
data={this.state.todayData}
151-
loadingStatus={this.loadingStatus}
152-
/>
211+
<div style={{ position: "relative", zIndex: "-1" }}>
212+
<Overview
213+
isDarkMode={isDarkMode}
214+
data={this.state.todayData}
215+
loadingStatus={this.loadingStatus}
216+
/>
217+
</div>
153218
<div className={classes.content}>
154219
<div className={classes.contentArea}>
155220
<div className={classes.mapArea}>
@@ -238,7 +303,7 @@ class CovidApp extends Component {
238303
</div>
239304
</div>
240305
<Footer />
241-
</FadeIn>
306+
</>
242307
);
243308
}
244309
}

src/styles/CovidAppStyles.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,40 @@ export default {
2727
[sizes.down("xs")]: {
2828
fontSize: "2rem",
2929
padding: "3rem",
30-
// paddingBottom: "1.5rem",
3130
},
3231
},
3332

33+
updates: {
34+
marginLeft: "auto",
35+
position: "relative",
36+
},
37+
38+
notification: {
39+
fontSize: "3rem",
40+
color: colors.darkPurple,
41+
position: "relative",
42+
transition: "all .5s ease",
43+
44+
"&::before": {
45+
content: '""',
46+
position: "absolute",
47+
width: "1rem",
48+
height: "1rem",
49+
backgroundColor: "red",
50+
borderRadius: "10rem",
51+
top: "1rem",
52+
right: 0,
53+
},
54+
},
55+
56+
update: {
57+
display: "block",
58+
position: "absolute",
59+
left: "-25rem",
60+
backgroundColor: "red",
61+
zIndex: "99999999",
62+
},
63+
3464
content: {
3565
backgroundColor: (props) => (props.isDarkMode ? colors.darkPurple : "#fff"),
3666
borderRadius: "2rem",

src/styles/DarkModeButton.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77

88
.darkModeButton {
9-
margin-left: auto;
9+
margin-left: 2rem;
1010
}
1111

1212
/* Hide default HTML checkbox */

0 commit comments

Comments
 (0)