├── src ├── index.jsx ├── components │ ├── Table.css │ ├── Table.jsx │ ├── InfoBox.css │ ├── Map.css │ ├── Map.jsx │ ├── InfoBox.jsx │ └── LineGraph.jsx ├── App.css ├── favicon.svg ├── util.jsx └── App.jsx ├── public └── index.html ├── package.json └── README.md /src/index.jsx: -------------------------------------------------------------------------------- 1 | import { StrictMode } from "react"; 2 | import { createRoot } from "react-dom/client"; 3 | import App from "./App"; 4 | 5 | const container = document.getElementById("root"); 6 | 7 | const root = createRoot(container); 8 | 9 | root.render( 10 | 11 | 12 | 13 | ); -------------------------------------------------------------------------------- /src/components/Table.css: -------------------------------------------------------------------------------- 1 | .table { 2 | margin-top: 20px; 3 | overflow: scroll; 4 | color: #6a5d5d; 5 | background-color: white; 6 | height: 400px; 7 | overflow-x: hidden; 8 | } 9 | 10 | .table tr { 11 | display: flex; 12 | justify-content: space-between; 13 | } 14 | 15 | .table td { 16 | padding: 0.5rem; 17 | border: none; 18 | } 19 | 20 | .table tr:nth-of-type(odd) { 21 | background-color: #f3f2f8; 22 | } 23 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | COVID-19 Tracker 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/components/Table.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "./Table.css"; 3 | import numeral from "numeral"; 4 | 5 | function Table({ countries }) { 6 | return ( 7 |
8 | {countries.map((country) => ( 9 | 10 | {country.country} 11 | 12 | {numeral(country.cases).format("0,0")} 13 | 14 | 15 | ))} 16 |
17 | ); 18 | } 19 | 20 | export default Table; 21 | -------------------------------------------------------------------------------- /src/components/InfoBox.css: -------------------------------------------------------------------------------- 1 | .infoBox { 2 | flex: 1; 3 | cursor: pointer; 4 | } 5 | 6 | .infoBox:not(:last-child) { 7 | margin-right: 10px; 8 | } 9 | 10 | .infoBox--selected { 11 | border-top: 10px solid greenyellow; 12 | } 13 | 14 | .infoBox--red { 15 | border-color: red; 16 | } 17 | 18 | .infoBox__cases--green { 19 | color: lightgreen !important; 20 | } 21 | 22 | .infoBox__cases { 23 | color: #cc1034; 24 | font-weight: 600; 25 | font-size: 1.75rem; 26 | margin-bottom: 0.5rem; 27 | } 28 | 29 | .infoBox__total { 30 | color: #6c757d; 31 | font-weight: 700 !important; 32 | font-size: 0.8rem !important; 33 | margin-top: 15px !important; 34 | } 35 | -------------------------------------------------------------------------------- /src/components/Map.css: -------------------------------------------------------------------------------- 1 | .map { 2 | height: 500px; 3 | background-color: white; 4 | padding: 1rem; 5 | border-radius: 20px; 6 | margin-top: 16px; 7 | box-shadow: 0 0 8px -4px rgba(0, 0, 0, 0.5); 8 | } 9 | 10 | .map .leaflet-container { 11 | height: 100%; 12 | border-radius: 12px; 13 | } 14 | 15 | .info-flag img { 16 | width: 100px; 17 | border-radius: 5px; 18 | } 19 | 20 | .info-name { 21 | font-size: 20px; 22 | font-weight: bold; 23 | color: #555; 24 | } 25 | 26 | .info-container { 27 | width: 150px; 28 | } 29 | 30 | .info-flag { 31 | height: 80px; 32 | width: 100%; 33 | background-size: cover; 34 | border-radius: 8px; 35 | } 36 | 37 | .info-confirmed, 38 | .info-recovered, 39 | .info-deaths { 40 | font-size: 16px; 41 | margin-top: 5px; 42 | } -------------------------------------------------------------------------------- /src/components/Map.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | //import { Map as useMap, TileLayer } from "react-leaflet"; 3 | import './Map.css' 4 | import { MapContainer } from 'react-leaflet/MapContainer' 5 | import { TileLayer } from 'react-leaflet/TileLayer' 6 | import { showDataOnMap } from '../util' 7 | //import { useMap } from 'react-leaflet/hooks' 8 | 9 | function Map({ countries, casesType, center, zoom }) { 10 | return ( 11 |
12 | 13 | 17 | {showDataOnMap(countries, casesType)} 18 | 19 |
20 | ); 21 | } 22 | 23 | export default Map; 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reactjs_nix", 3 | "version": "1.0.0", 4 | "description": "ReactJS on Replit, using Vite bundler", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "vite build", 8 | "dev": "vite" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "@material-ui/core": "^4.12.4", 15 | "@types/react": "^18.0.7", 16 | "@types/react-dom": "^18.0.0", 17 | "@vitejs/plugin-legacy": "^1.8.1", 18 | "@vitejs/plugin-react": "^1.3.1", 19 | "@vitejs/plugin-react-refresh": "^1.3.6", 20 | "apexcharts": "^3.35.3", 21 | "chart.js": "^3.8.0", 22 | "leaflet": "^1.8.0", 23 | "numeral": "^2.0.6", 24 | "react": "^18.2.0", 25 | "react-apexcharts": "^1.4.0", 26 | "react-chartjs-2": "^4.3.0", 27 | "react-dom": "^18.2.0", 28 | "react-leaflet": "^4.0.1", 29 | "vite": "^2.9.5" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/components/InfoBox.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import "./InfoBox.css" 3 | import { 4 | Card, 5 | CardContent, 6 | Typography 7 | } from "@material-ui/core"; 8 | 9 | function InfoBox({ title, cases, total, active, isRed, ...props }) { 10 | return ( 11 | 17 | 18 | 19 | {title} 20 | 21 |

22 | {cases} 23 |

24 | 25 | 26 | {total} Total 27 | 28 |
29 |
30 | ); 31 | } 32 | 33 | export default InfoBox; 34 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | } 4 | 5 | body { 6 | background-color: #f5f6fa; 7 | } 8 | 9 | .app { 10 | display: flex; 11 | justify-content: space-evenly; 12 | background-color: #f5f6fa; 13 | padding: 20px; 14 | } 15 | 16 | .app__dropdown { 17 | background-color: white; 18 | } 19 | 20 | .app__header { 21 | display: flex; 22 | align-items: center; 23 | margin-bottom: 20px; 24 | justify-content: space-between; 25 | } 26 | 27 | .app__header > h1 { 28 | color: #fc3c3c; 29 | font-size: 2rem; 30 | } 31 | 32 | .app__stats { 33 | display: flex; 34 | justify-content: space-between; 35 | } 36 | 37 | .app__left { 38 | flex: 0.9; 39 | } 40 | 41 | .app__information > h3 { 42 | color: #6a5d5d; 43 | font-weight: 400; 44 | font-size: 1.5rem; 45 | margin-bottom: 1rem; 46 | } 47 | 48 | .app__information > h3:last-of-type { 49 | margin-top: 1rem; 50 | } 51 | 52 | @media (max-width: 990px) { 53 | .app { 54 | flex-direction: column; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/util.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import numeral from "numeral"; 3 | import { Circle, Popup } from "react-leaflet"; 4 | 5 | const casesTypeColors = { 6 | cases: { 7 | hex: "#CC1034", 8 | multiplier: 130, 9 | }, 10 | recovered: { 11 | hex: "#7dd71d", 12 | multiplier: 120, 13 | }, 14 | deaths: { 15 | hex: "#fb4443", 16 | multiplier: 1300, 17 | }, 18 | }; 19 | 20 | export const sortData = (data) => { 21 | let sortedData = [...data]; 22 | sortedData.sort((a, b) => { 23 | if (a.cases > b.cases) { 24 | return -1; 25 | } else { 26 | return 1; 27 | } 28 | }); 29 | return sortedData; 30 | }; 31 | 32 | export const prettyPrintStat = (stat) => 33 | stat ? `+${numeral(stat).format("0.0a")}` : "+0"; 34 | 35 | export const showDataOnMap = (data, casesType = "cases") => 36 | data.map((country) => ( 37 | 46 | 47 |
48 |
52 |
{country.country}
53 |
54 | Cases: {numeral(country.cases).format("0,0")} 55 |
56 |
57 | Recovered: {numeral(country.recovered).format("0,0")} 58 |
59 |
60 | Deaths: {numeral(country.deaths).format("0,0")} 61 |
62 |
63 |
64 |
65 | )); 66 | -------------------------------------------------------------------------------- /src/components/LineGraph.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react' 2 | import { Line } from 'react-chartjs-2' 3 | import Chart from 'chart.js/auto'; 4 | import numeral from "numeral"; 5 | 6 | const options = { 7 | legend: { 8 | display: false, 9 | }, 10 | elements: { 11 | point: { 12 | radius: 0, 13 | }, 14 | }, 15 | maintainAspectRatio: false, 16 | tooltips: { 17 | mode: "index", 18 | intersect: false, 19 | callbacks: { 20 | label: function (tooltipItem, data) { 21 | return numeral(tooltipItem.value).format("+0,0"); 22 | }, 23 | }, 24 | }, 25 | scales: { 26 | xAxes: [ 27 | { 28 | type: "time", 29 | time: { 30 | format: "MM/DD/YY", 31 | tooltipFormat: "ll", 32 | }, 33 | }, 34 | ], 35 | yAxes: [ 36 | { 37 | gridLines: { 38 | display: false, 39 | }, 40 | ticks: { 41 | // Include a dollar sign in the ticks 42 | callback: function (value, index, values) { 43 | return numeral(value).format("0a"); 44 | }, 45 | }, 46 | }, 47 | ], 48 | }, 49 | }; 50 | 51 | const buildChargeData = (data, casesType) => { 52 | let chartData = []; 53 | let lastDataPoint; 54 | for (let date in data.cases) { 55 | if (lastDataPoint) { 56 | let newDataPoint = { 57 | x: date, 58 | y: data[casesType][date] - lastDataPoint, 59 | }; 60 | chartData.push(newDataPoint); 61 | } 62 | lastDataPoint = data[casesType][date]; 63 | } 64 | return chartData; 65 | }; 66 | 67 | function LineGraph({ casesType = 'cases', ...props }) { 68 | 69 | const [data, setData] = useState({}); 70 | 71 | useEffect(() => { 72 | const fetchData = async () => { 73 | await fetch("https://disease.sh/v3/covid-19/historical/all?lastdays=120") 74 | .then((response) => { 75 | return response.json(); 76 | }) 77 | .then((data) => { 78 | let chartData = buildChargeData(data, casesType); 79 | setData(chartData); 80 | }); 81 | }; 82 | 83 | fetchData(); 84 | }, [casesType]); 85 | 86 | return ( 87 |
88 | {data?.length > 0 && ( 89 | 101 | )} 102 |
103 | ) 104 | } 105 | 106 | export default LineGraph -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # COVID-19 Tracker with REACT JS 2 | ### 🔴 LIVE DEMO 3 | 4 | #### PREREQUISITES: 5 | - Install Node JS in your computer HERE 6 | 7 |

8 | React 9 | js 10 | Cshark 11 | Mysql 12 |
13 |
14 | 15 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 16 | 17 | ## Available Scripts 18 | 19 | ``` 20 | npx create-react-app covid_tracker 21 | ``` 22 | 23 | In the project directory, you can run: 24 | ``` 25 | npm start 26 | ``` 27 | 28 | Runs the app in the development mode.\ 29 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 30 | 31 | The page will reload when you make changes.\ 32 | You may also see any lint errors in the console. 33 | ``` 34 | npm test 35 | ``` 36 | 37 | Launches the test runner in the interactive watch mode.\ 38 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 39 | ``` 40 | npm run build 41 | ``` 42 | 43 | Builds the app for production to the `build` folder.\ 44 | It correctly bundles React in production mode and optimizes the build for the best performance. 45 | 46 | The build is minified and the filenames include the hashes.\ 47 | Your app is ready to be deployed! 48 | 49 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 50 | ``` 51 | npm run eject 52 | ``` 53 | 54 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 55 | 56 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 57 | 58 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 59 | 60 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 61 | 62 | 63 | ## Available MATERIAL-UI Scripts 64 | MATERIAL-UI HERE 65 | ``` 66 | npm install -f @material-ui/core 67 | ``` 68 | ### 💻 Replit 69 | 70 |
71 | 72 | ![image](https://user-images.githubusercontent.com/99184393/178642318-2d0b4453-ea62-4e0b-b2b7-368c925564ba.png) 73 | -------------------------------------------------------------------------------- /src/App.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react'; 2 | import './App.css'; 3 | import { 4 | MenuItem, 5 | FormControl, 6 | Select, 7 | Card, 8 | CardContent, 9 | } from "@material-ui/core"; 10 | import InfoBox from './components/InfoBox'; 11 | import Map from './components/Map'; 12 | import Table from './components/Table'; 13 | import { prettyPrintStat, sortData } from './util'; 14 | import LineGraph from './components/LineGraph'; 15 | import "leaflet/dist/leaflet.css"; 16 | import numeral from "numeral"; 17 | 18 | const App = () => { 19 | const [country, setInputCountry] = useState("worldwide"); 20 | const [countryInfo, setCountryInfo] = useState({}); 21 | const [countries, setCountries] = useState([]); 22 | const [mapCountries, setMapCountries] = useState([]); 23 | const [tableData, setTableData] = useState([]); 24 | const [casesType, setCasesType] = useState("cases"); 25 | const [mapCenter, setMapCenter] = useState({ lat: 34.80746, lng: -40.4796 }); 26 | const [mapZoom, setMapZoom] = useState(3); 27 | 28 | useEffect(() => { 29 | fetch("https://disease.sh/v3/covid-19/all") 30 | .then((response) => response.json()) 31 | .then((data) => { 32 | setCountryInfo(data); 33 | }); 34 | }, []); 35 | 36 | useEffect(() => { 37 | const getCountriesData = async () => { 38 | fetch("https://disease.sh/v3/covid-19/countries") 39 | .then((response) => response.json()) 40 | .then((data) => { 41 | const countries = data.map((country) => ({ 42 | name: country.country, 43 | value: country.countryInfo.iso2, 44 | })); 45 | let sortedData = sortData(data); 46 | setCountries(countries); 47 | setMapCountries(data); 48 | setTableData(sortedData); 49 | }); 50 | }; 51 | 52 | getCountriesData(); 53 | }, []); 54 | 55 | // console.log(casesType); 56 | 57 | const onCountryChange = async (e) => { 58 | const countryCode = e.target.value; 59 | 60 | const url = 61 | countryCode === "worldwide" 62 | ? "https://disease.sh/v3/covid-19/all" 63 | : `https://disease.sh/v3/covid-19/countries/${countryCode}`; 64 | await fetch(url) 65 | .then((response) => response.json()) 66 | .then((data) => { 67 | setInputCountry(countryCode); 68 | setCountryInfo(data); 69 | setMapCenter([data.countryInfo.lat, data.countryInfo.long]); 70 | setMapZoom(4); 71 | }); 72 | }; 73 | 74 | return ( 75 |
76 |
77 |
78 |

COVID-19 Tracker

79 | 80 | 90 | 91 |
92 |
93 | setCasesType("cases")} 95 | title="Coronavirus Cases" 96 | isRed 97 | active={casesType === "cases"} 98 | cases={prettyPrintStat(countryInfo.todayCases)} 99 | total={numeral(countryInfo.cases).format("0.0a")} 100 | /> 101 | setCasesType("recovered")} 103 | title="Recovered" 104 | active={casesType === "recovered"} 105 | cases={prettyPrintStat(countryInfo.todayRecovered)} 106 | total={numeral(countryInfo.recovered).format("0.0a")} 107 | /> 108 | setCasesType("deaths")} 110 | title="Deaths" 111 | isRed 112 | active={casesType === "deaths"} 113 | cases={prettyPrintStat(countryInfo.todayDeaths)} 114 | total={numeral(countryInfo.deaths).format("0.0a")} 115 | /> 116 |
117 | 123 |
124 | 125 | 126 |
127 |

Live Cases by Country

128 | 129 |

World Wild New {casesType}

130 | 131 | 132 | 133 | 134 | 135 | ); 136 | }; 137 | 138 | export default App; 139 | --------------------------------------------------------------------------------