Skip to content

Commit

Permalink
add hist data
Browse files Browse the repository at this point in the history
  • Loading branch information
echen831 committed Dec 8, 2020
1 parent 677ffc3 commit b1aff62
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .eslintcache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"/Users/ericchen/Desktop/MB_projects/sj_project/src/index.js":"1","/Users/ericchen/Desktop/MB_projects/sj_project/src/App.js":"2","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/input.jsx":"3","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/states.js":"4","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/buttons.jsx":"5","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/today.jsx":"6","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/history.jsx":"7"},{"size":199,"mtime":1607224861875,"results":"8","hashOfConfig":"9"},{"size":1095,"mtime":1607365764140,"results":"10","hashOfConfig":"9"},{"size":766,"mtime":1607227340486,"results":"11","hashOfConfig":"9"},{"size":5659,"mtime":1607320414068,"results":"12","hashOfConfig":"9"},{"size":777,"mtime":1607365843006,"results":"13","hashOfConfig":"9"},{"size":2131,"mtime":1607325725948,"results":"14","hashOfConfig":"9"},{"size":462,"mtime":1607365950746,"results":"15","hashOfConfig":"9"},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"18"},"150614y",{"filePath":"19","messages":"20","errorCount":0,"warningCount":3,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"21","messages":"22","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":"23","usedDeprecatedRules":"24"},{"filePath":"25","messages":"26","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"18"},{"filePath":"27","messages":"28","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"29","messages":"30","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"18"},{"filePath":"31","messages":"32","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/ericchen/Desktop/MB_projects/sj_project/src/index.js",[],["33","34"],"/Users/ericchen/Desktop/MB_projects/sj_project/src/App.js",["35","36","37"],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/input.jsx",["38","39"],"import React, { useState, useRef } from 'react';\n\nexport const Input = ({ add }) => {\n const [name, setName] = useState('');\n\n const nameInput = useRef();\n const addressInput = useRef();\n\n const handleSubmit = (e) => {\n e.preventDefault();\n add({ name: nameInput.current.value, address: addressInput.current.value })\n nameInput.current.value = '';\n addressInput.current.value = '';\n }\n\n return (\n <div>\n <form action=\"\" onSubmit={handleSubmit}>\n <input type=\"text\" placeholder='Your name here...' ref={nameInput}/>\n <input type=\"text\" placeholder='Your address here...'ref={addressInput}/>\n <button>Submit</button>\n </form>\n </div>\n )\n}",["40","41"],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/states.js",[],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/buttons.jsx",["42","43"],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/today.jsx",[],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/history.jsx",[],{"ruleId":"44","replacedBy":"45"},{"ruleId":"46","replacedBy":"47"},{"ruleId":"48","severity":1,"message":"49","line":12,"column":10,"nodeType":"50","messageId":"51","endLine":12,"endColumn":18},{"ruleId":"48","severity":1,"message":"52","line":13,"column":10,"nodeType":"50","messageId":"51","endLine":13,"endColumn":15},{"ruleId":"53","severity":1,"message":"54","line":17,"column":48,"nodeType":"55","endLine":17,"endColumn":50,"suggestions":"56"},{"ruleId":"48","severity":1,"message":"57","line":4,"column":12,"nodeType":"50","messageId":"51","endLine":4,"endColumn":16},{"ruleId":"48","severity":1,"message":"58","line":4,"column":18,"nodeType":"50","messageId":"51","endLine":4,"endColumn":25},{"ruleId":"44","replacedBy":"59"},{"ruleId":"46","replacedBy":"60"},{"ruleId":"48","severity":1,"message":"61","line":1,"column":16,"nodeType":"50","messageId":"51","endLine":1,"endColumn":24},{"ruleId":"48","severity":1,"message":"62","line":1,"column":26,"nodeType":"50","messageId":"51","endLine":1,"endColumn":35},"no-native-reassign",["63"],"no-negated-in-lhs",["64"],"no-unused-vars","'isLoaded' is assigned a value but never used.","Identifier","unusedVar","'error' is assigned a value but never used.","react-hooks/exhaustive-deps","React Hook useEffect has a missing dependency: 'currState'. Either include it or remove the dependency array.","ArrayExpression",["65"],"'name' is assigned a value but never used.","'setName' is assigned a value but never used.",["63"],["64"],"'useState' is defined but never used.","'useEffect' is defined but never used.","no-global-assign","no-unsafe-negation",{"desc":"66","fix":"67"},"Update the dependencies array to be: [currState]",{"range":"68","text":"69"},[479,481],"[currState]"]
[{"/Users/ericchen/Desktop/MB_projects/sj_project/src/index.js":"1","/Users/ericchen/Desktop/MB_projects/sj_project/src/App.js":"2","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/input.jsx":"3","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/states.js":"4","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/buttons.jsx":"5","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/today.jsx":"6","/Users/ericchen/Desktop/MB_projects/sj_project/src/components/history.jsx":"7"},{"size":199,"mtime":1607224861875,"results":"8","hashOfConfig":"9"},{"size":1193,"mtime":1607386750633,"results":"10","hashOfConfig":"9"},{"size":766,"mtime":1607227340486,"results":"11","hashOfConfig":"9"},{"size":5659,"mtime":1607320414068,"results":"12","hashOfConfig":"9"},{"size":816,"mtime":1607407453938,"results":"13","hashOfConfig":"9"},{"size":2131,"mtime":1607325725948,"results":"14","hashOfConfig":"9"},{"size":716,"mtime":1607406659266,"results":"15","hashOfConfig":"9"},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"18"},"150614y",{"filePath":"19","messages":"20","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"21","messages":"22","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":"23","usedDeprecatedRules":"24"},{"filePath":"25","messages":"26","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"18"},{"filePath":"27","messages":"28","errorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"29","messages":"30","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":"18"},{"filePath":"31","messages":"32","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/ericchen/Desktop/MB_projects/sj_project/src/index.js",[],["33","34"],"/Users/ericchen/Desktop/MB_projects/sj_project/src/App.js",["35"],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/input.jsx",["36","37"],"import React, { useState, useRef } from 'react';\n\nexport const Input = ({ add }) => {\n const [name, setName] = useState('');\n\n const nameInput = useRef();\n const addressInput = useRef();\n\n const handleSubmit = (e) => {\n e.preventDefault();\n add({ name: nameInput.current.value, address: addressInput.current.value })\n nameInput.current.value = '';\n addressInput.current.value = '';\n }\n\n return (\n <div>\n <form action=\"\" onSubmit={handleSubmit}>\n <input type=\"text\" placeholder='Your name here...' ref={nameInput}/>\n <input type=\"text\" placeholder='Your address here...'ref={addressInput}/>\n <button>Submit</button>\n </form>\n </div>\n )\n}",["38","39"],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/states.js",[],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/buttons.jsx",["40","41"],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/today.jsx",[],"/Users/ericchen/Desktop/MB_projects/sj_project/src/components/history.jsx",[],{"ruleId":"42","replacedBy":"43"},{"ruleId":"44","replacedBy":"45"},{"ruleId":"46","severity":1,"message":"47","line":17,"column":48,"nodeType":"48","endLine":17,"endColumn":50,"suggestions":"49"},{"ruleId":"50","severity":1,"message":"51","line":4,"column":12,"nodeType":"52","messageId":"53","endLine":4,"endColumn":16},{"ruleId":"50","severity":1,"message":"54","line":4,"column":18,"nodeType":"52","messageId":"53","endLine":4,"endColumn":25},{"ruleId":"42","replacedBy":"55"},{"ruleId":"44","replacedBy":"56"},{"ruleId":"50","severity":1,"message":"57","line":1,"column":16,"nodeType":"52","messageId":"53","endLine":1,"endColumn":24},{"ruleId":"50","severity":1,"message":"58","line":1,"column":26,"nodeType":"52","messageId":"53","endLine":1,"endColumn":35},"no-native-reassign",["59"],"no-negated-in-lhs",["60"],"react-hooks/exhaustive-deps","React Hook useEffect has a missing dependency: 'currState'. Either include it or remove the dependency array.","ArrayExpression",["61"],"no-unused-vars","'name' is assigned a value but never used.","Identifier","unusedVar","'setName' is assigned a value but never used.",["59"],["60"],"'useState' is defined but never used.","'useEffect' is defined but never used.","no-global-assign","no-unsafe-negation",{"desc":"62","fix":"63"},"Update the dependencies array to be: [currState]",{"range":"64","text":"65"},[495,497],"[currState]"]
13 changes: 7 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ import { Buttons } from './components/buttons';
const App = () => {

const [currState, setCurrState] = useState('CA');
const [isLoaded, setIsLoaded] = useState(false);
const [error, setError] = useState(null);
const [isHistLoaded, setHistIsLoaded] = useState(false);
const [histError, setHistError] = useState(null);
const [histData, setHistdata] = useState([]);


useEffect(() => { fetchHistData(currState)}, [])

const fetchHistData = (state) => {
setHistIsLoaded(false);
fetch(`https://api.covidtracking.com/v1/states/${state}/daily.json`)
.then(res => res.json())
.then((result) => {
setIsLoaded(true);
setHistIsLoaded(true);
setHistdata(result);
},
(error) => {
setIsLoaded(true);
setError(error)
setHistIsLoaded(true);
setHistError(error)
}
)
}
Expand All @@ -36,7 +37,7 @@ const App = () => {
MB Social Justice Hackathon
<Buttons currState={currState} setCurrState={setCurrState} fetchHistData={fetchHistData}/>
<Today currState={currState}/>
<History data={histData}/>
<History data={histData} isLoaded={isHistLoaded} error={histError}/>
</div>
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ const COLORS = ['red', 'blue', 'green', 'orange', 'purple', 'gold', 'indigo', 'b

export const Buttons = ({ setCurrState, fetchHistData }) => {



return (
<div>
<ul className='button-wrapper'>
{STATES.map((state, idx) => (
<li key={state.abbreviation}
style={{color: 'white', backgroundColor: COLORS[idx % COLORS.length]}}
className='button'
onClick={() => {setCurrState(state.abbreviation); fetchHistData(state.abbreviation.toLowerCase())}}>
onClick={() => {setCurrState(state.abbreviation);
fetchHistData(state.abbreviation.toLowerCase())}}>
{state.abbreviation}</li>
))}
</ul>
Expand Down
39 changes: 23 additions & 16 deletions src/components/history.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import React from 'react';

export const History = ({ data }) => {
export const History = ({ data, isLoaded, error }) => {

return (
<div>
<ul>
{data.map(day => {
return (
<div>
<li>Date: {day.date}</li>
<li>Num Positive: {day.positive}</li>
</div>

)
})}
if (error) {
return <div>Error: {error.message}</div>
} else if (!isLoaded) {
return <div>Loading...</div>
} else {
return (
<div>
Historic data...
<ul>
{data.map(day => {
return (
<div>
<li>Date: {day.date}</li>
<li>Num Positive: {day.positive}</li>
</div>
)
})}

</ul>
</div>
)

</ul>
</div>
)
}
}

0 comments on commit b1aff62

Please sign in to comment.