This repository has been archived by the owner on Nov 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Partial Bugfix #1013 : Missing state management #1022
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
79d8186
(Bug) Total Tested cases
SensehacK 971cf16
(chore) Removed unneccessary code comments.
SensehacK 63c7439
Merge branch 'master' of https://github.com/SensehacK/covid19india-react
SensehacK 65e3208
(refactor)JS reduce: function
SensehacK 6674d89
(refactor)Padding: function
SensehacK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
|
@@ -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; | ||
} | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( | ||
|
@@ -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)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated the code.