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 3 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
25 changes: 25 additions & 0 deletions 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({});
let totalTemp = 0;
const [panelRegion, setPanelRegion] = useState(getRegionFromState(states[0]));
const [currentHoveredRegion, setCurrentHoveredRegion] = useState(
getRegionFromState(states[0])
Expand Down Expand Up @@ -380,12 +382,34 @@ function MapExplorer({

const {name, lastupdatedtime} = currentHoveredRegion;

function getCurrentDate() {
const date = new Date();
let getMonth = String(date.getMonth() + 1);
if (getMonth.length === 1) {
getMonth = '0' + getMonth;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done in a single step using the padStart() in JS, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated the code.

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

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

const totalTMap = testDataFind.map((value) => value.totaltested);
totalTMap.forEach((element) => {
// eslint-disable-next-line
totalTemp += Number(element);
});

setTotal(totalTemp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the extra variable 'totalTemp'. You could use, js reduce function to setTotal. This way you would not be required to disable eslint and code will be more concise and readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my second attempt at React programming.

I knew I was missing state management of some sort.

Thanks for input. I’ll check & update the codebase.

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

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