Skip to content

Commit 10a44a6

Browse files
Merge pull request #11 from PrinceSumberia/nextFeatures
Next features
2 parents 8f48ae2 + 35367fe commit 10a44a6

File tree

5 files changed

+177
-13
lines changed

5 files changed

+177
-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: 109 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from "react";
2+
import { formatDistance } from "date-fns";
23
import Overview from "./Overview";
34
import { withStyles } from "@material-ui/styles";
45
import colors from "../constants/colors";
@@ -7,14 +8,18 @@ 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";
1419
import stateCodes from "../constants/stateCodes";
1520
import Lottie from "react-lottie";
1621
import * as animationData from "../assets/loading.json";
17-
import FadeIn from "react-fade-in";
22+
// import FadeIn from "react-fade-in";
1823
import Footer from "./Footer";
1924

2025
const defaultOptions = {
@@ -26,6 +31,21 @@ const defaultOptions = {
2631
},
2732
};
2833

34+
const months = {
35+
"01": "Jan",
36+
"02": "Feb",
37+
"03": "Mar",
38+
"04": "Apr",
39+
"05": "May",
40+
"06": "Jun",
41+
"07": "Jul",
42+
"08": "Aug",
43+
"09": "Sep",
44+
"10": "Oct",
45+
"11": "Nov",
46+
"12": "Dec",
47+
};
48+
2949
class CovidApp extends Component {
3050
constructor(props) {
3151
super(props);
@@ -42,6 +62,7 @@ class CovidApp extends Component {
4262
this.formatData = this.formatData.bind(this);
4363
this.findId = this.findId.bind(this);
4464
this.handleFormat = this.handleFormat.bind(this);
65+
this.handleNotification = this.handleNotification.bind(this);
4566
}
4667

4768
componentDidMount() {
@@ -57,12 +78,18 @@ class CovidApp extends Component {
5778
const stateChanges = axios.get(
5879
"https://api.covid19india.org/states_daily.json"
5980
);
81+
const updates = axios.get(
82+
"https://api.covid19india.org/updatelog/log.json"
83+
);
6084

61-
axios.all([countryData, districtLevel, stateChanges]).then(
85+
axios.all([countryData, districtLevel, stateChanges, updates]).then(
6286
axios.spread((...responses) => {
6387
const countryData = responses[0].data;
6488
const districtLevel = responses[1].data;
6589
// const stateChanges = responses[2].data;
90+
const updates = responses[3].data;
91+
92+
// console.log(countryData.statewise[0].lastupdatedtime);
6693

6794
const [todayData] = countryData.statewise.slice(0, 1);
6895
const casesTimeline = countryData.cases_time_series;
@@ -75,6 +102,8 @@ class CovidApp extends Component {
75102
todayData: todayData,
76103
casesTimeline: casesTimeline,
77104
districtLevel: districtLevel,
105+
updates: updates,
106+
expanded: false,
78107
},
79108
this.handleFormat
80109
);
@@ -109,9 +138,29 @@ class CovidApp extends Component {
109138
this.setState({ mapData: newdata });
110139
}
111140

141+
handleNotification() {
142+
this.setState({ expanded: !this.state.expanded });
143+
}
144+
145+
formatDate(date) {
146+
try {
147+
const day = date.slice(0, 2);
148+
const month = date.slice(3, 5);
149+
const time = date.slice(11);
150+
return `${day} ${months[month]}, ${time.slice(0, 5)} IST`;
151+
} catch (err) {}
152+
}
153+
112154
render() {
113155
const { classes, setDarkMode, isDarkMode } = this.props;
114-
const { mapData, isLoading, data, districtLevel } = this.state;
156+
const {
157+
mapData,
158+
isLoading,
159+
data,
160+
districtLevel,
161+
expanded,
162+
updates,
163+
} = this.state;
115164

116165
if (isLoading) {
117166
return (
@@ -120,9 +169,34 @@ class CovidApp extends Component {
120169
</div>
121170
);
122171
}
172+
let displayUpdates;
173+
try {
174+
displayUpdates = updates
175+
.slice(-5)
176+
.reverse()
177+
.map(({ update, timestamp }, i) => {
178+
update = update.replace("\n", "<br/>");
179+
return (
180+
<div className={classes.updateBox} key={i}>
181+
<h5 className={classes.updateHeading}>
182+
{`${formatDistance(
183+
new Date(timestamp * 1000),
184+
new Date()
185+
)} ago`}
186+
</h5>
187+
<h4
188+
className={classes.updateText}
189+
dangerouslySetInnerHTML={{
190+
__html: update,
191+
}}
192+
></h4>
193+
</div>
194+
);
195+
});
196+
} catch (err) {}
123197

124198
return (
125-
<FadeIn>
199+
<>
126200
<div className={classes.header}>
127201
<h1 className={classes.heading}>
128202
<span>Covid-19</span> India Trend
@@ -134,6 +208,28 @@ class CovidApp extends Component {
134208
onClick={this.fetchData}
135209
/>
136210
</div>
211+
<div className={classes.lastUpdatedTime}>
212+
Last Updated:{" "}
213+
{this.formatDate(this.state.todayData.lastupdatedtime)}
214+
</div>
215+
<div className={classes.updates}>
216+
<div className={classes.notification}>
217+
{expanded ? (
218+
<FontAwesomeIcon
219+
icon={faBellSlash}
220+
onClick={this.handleNotification}
221+
/>
222+
) : (
223+
<div className={classes.notificationBell}>
224+
<FontAwesomeIcon
225+
icon={faBell}
226+
onClick={this.handleNotification}
227+
/>
228+
</div>
229+
)}
230+
</div>
231+
{expanded && <div className={classes.update}>{displayUpdates}</div>}
232+
</div>
137233
<div className="darkModeButton">
138234
<label className="switch">
139235
<input
@@ -145,11 +241,13 @@ class CovidApp extends Component {
145241
</label>
146242
</div>
147243
</div>
148-
<Overview
149-
isDarkMode={isDarkMode}
150-
data={this.state.todayData}
151-
loadingStatus={this.loadingStatus}
152-
/>
244+
<div>
245+
<Overview
246+
isDarkMode={isDarkMode}
247+
data={this.state.todayData}
248+
loadingStatus={this.loadingStatus}
249+
/>
250+
</div>
153251
<div className={classes.content}>
154252
<div className={classes.contentArea}>
155253
<div className={classes.mapArea}>
@@ -238,7 +336,7 @@ class CovidApp extends Component {
238336
</div>
239337
</div>
240338
<Footer />
241-
</FadeIn>
339+
</>
242340
);
243341
}
244342
}

src/styles/CovidAppStyles.js

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,70 @@ 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 .4s ease",
43+
44+
"&:hover": {
45+
transform: "scale(1.15)",
46+
color: "#000",
47+
},
48+
},
49+
50+
notificationBell: {
51+
position: "relative",
52+
53+
"&::before": {
54+
content: '""',
55+
position: "absolute",
56+
width: "1rem",
57+
height: "1rem",
58+
backgroundColor: "red",
59+
borderRadius: "10rem",
60+
top: "1rem",
61+
right: 0,
62+
},
63+
},
64+
65+
lastUpdatedTime: {
66+
marginLeft: "1.5rem",
67+
fontSize: "1.5rem",
68+
},
69+
70+
update: {
71+
fontSize: "1.5rem",
72+
display: "block",
73+
position: "absolute",
74+
left: "-25rem",
75+
backgroundColor: "rgba(255,255,255,.95)",
76+
borderRadius: "2rem",
77+
boxShadow: "0 1rem 2rem rgba(0,0,0,.15)",
78+
padding: "3rem",
79+
zIndex: "1",
80+
transition: "all .5s",
81+
},
82+
83+
updateBox: {
84+
marginBottom: "1.5rem",
85+
},
86+
87+
updateHeading: {
88+
textTransform: "capitalize",
89+
},
90+
updateText: {
91+
fontWeight: "400",
92+
},
93+
3494
content: {
3595
backgroundColor: (props) => (props.isDarkMode ? colors.darkPurple : "#fff"),
3696
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)