Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Partial Bugfix #1013 : Missing state management #1022

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/components/mapexplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ function MapExplorer({
onMapHighlightChange,
}) {
const [selectedRegion, setSelectedRegion] = useState({});
const [total, setTotal] = useState({});
const reducer = (accumulator, currentValue) => (accumulator += currentValue);
const [panelRegion, setPanelRegion] = useState(getRegionFromState(states[0]));
const [currentHoveredRegion, setCurrentHoveredRegion] = useState(
getRegionFromState(states[0])
Expand Down Expand Up @@ -380,13 +382,34 @@ function MapExplorer({

const {name, lastupdatedtime} = currentHoveredRegion;

function getCurrentDate() {
const date = new Date();
const getMonth = String(date.getMonth() + 1);

const dateComp =
date.getDate() +
'/' +
getMonth.padStart(2, '0') +
'/' +
date.getFullYear();
return dateComp;
}

useEffect(() => {
const testDataFind = stateTestData.filter(
(obj) => obj.totaltested !== '' && obj.updatedon === getCurrentDate()
);

const totalTMap = testDataFind.map((value) => value.totaltested);
setTotal(totalTMap.map(Number).reduce(reducer));

setTestObj(
stateTestData.find(
(obj) => obj.state === panelRegion.name && obj.totaltested !== ''
)
);
}, [panelRegion, stateTestData, testObj]);
console.log('Total Indians Tested:', total);
}, [panelRegion, stateTestData, testObj, total]);

return (
<div
Expand Down Expand Up @@ -453,6 +476,7 @@ function MapExplorer({
<h5>{window.innerWidth <= 769 ? 'Tested' : 'Tested'}</h5>
<div className="stats-bottom">
<h1>{formatNumber(testObj?.totaltested)}</h1>
{/* <h1>{formatNumber(total)}</h1> */}
</div>
<h6 className="timestamp">
{!isNaN(new Date(testObj?.updatedon))
Expand Down