11import React , { Component } from "react" ;
2+ import { formatDistance , format } from "date-fns" ;
23import Overview from "./Overview" ;
34import { withStyles } from "@material-ui/styles" ;
45import colors from "../constants/colors" ;
@@ -7,7 +8,11 @@ import DisplayTable from "./DisplayTable";
78import styles from "../styles/CovidAppStyles" ;
89import axios from "axios" ;
910import { 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" ;
1116import "../styles/DarkModeButton.css" ;
1217import MapSection from "./MapSection" ;
1318import 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}
0 commit comments