├── .babelrc ├── .eslintrc.json ├── .github └── workflows │ └── linters.yml ├── .gitignore ├── .stylelintrc.json ├── LICENSE ├── README.md ├── Screenshot_1.png ├── Screenshot_2.png ├── assetsTransformer.js ├── package-lock.json ├── package.json ├── public └── index.html ├── setupJest.js └── src ├── App.js ├── __test__ ├── Country.test.js └── __snapshots__ │ └── Country.test.js.snap ├── components ├── Country.js ├── Details.js ├── Filter.js ├── Header.js └── Home.js ├── img └── Corona.png ├── index.css ├── index.js ├── redux ├── configureStore.js └── virus │ └── virusInformation.js └── setupTests.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-react", "@babel/preset-env"], 3 | "plugins": ["@babel/plugin-syntax-jsx"], 4 | "env": { 5 | "test": { 6 | "plugins": ["@babel/plugin-transform-runtime"] 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es6": true, 5 | "jest": true 6 | }, 7 | "parser": "@babel/eslint-parser", 8 | "parserOptions": { 9 | "ecmaFeatures": { 10 | "jsx": true 11 | }, 12 | "ecmaVersion": 2018, 13 | "sourceType": "module" 14 | }, 15 | "extends": ["airbnb", "plugin:react/recommended"], 16 | "plugins": ["react"], 17 | "rules": { 18 | "react/jsx-filename-extension": ["warn", { "extensions": [".js", ".jsx"] }], 19 | "react/react-in-jsx-scope": "off", 20 | "import/no-unresolved": "off", 21 | "no-shadow": "off" 22 | }, 23 | "ignorePatterns": [ 24 | "dist/", 25 | "build/" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | name: Linters 2 | 3 | on: pull_request 4 | 5 | env: 6 | FORCE_COLOR: 1 7 | 8 | jobs: 9 | eslint: 10 | name: ESLint 11 | runs-on: ubuntu-18.04 12 | steps: 13 | - uses: actions/checkout@v2 14 | - uses: actions/setup-node@v1 15 | with: 16 | node-version: "12.x" 17 | - name: Setup ESLint 18 | run: | 19 | npm install --save-dev eslint@7.x eslint-config-airbnb@18.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@4.x @babel/eslint-parser@7.x @babel/core@7.x @babel/plugin-syntax-jsx@7.x @babel/preset-react@7.x 20 | [ -f .eslintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/react-redux/.eslintrc.json 21 | [ -f .babelrc ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/react-redux/.babelrc 22 | - name: ESLint Report 23 | run: npx eslint . 24 | stylelint: 25 | name: Stylelint 26 | runs-on: ubuntu-18.04 27 | steps: 28 | - uses: actions/checkout@v2 29 | - uses: actions/setup-node@v1 30 | with: 31 | node-version: "12.x" 32 | - name: Setup Stylelint 33 | run: | 34 | npm install --save-dev stylelint@13.x stylelint-scss@3.x stylelint-config-standard@21.x stylelint-csstree-validator@1.x 35 | [ -f .stylelintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/react-redux/.stylelintrc.json 36 | - name: Stylelint Report 37 | run: npx stylelint "**/*.{css,scss}" 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 106 | 107 | # dependencies 108 | /node_modules 109 | /.pnp 110 | .pnp.js 111 | 112 | # testing 113 | /coverage 114 | 115 | # production 116 | /build 117 | 118 | # misc 119 | .DS_Store 120 | .env.local 121 | .env.development.local 122 | .env.test.local 123 | .env.production.local 124 | 125 | npm-debug.log* 126 | yarn-debug.log* 127 | yarn-error.log* 128 | -------------------------------------------------------------------------------- /.stylelintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["stylelint-config-standard"], 3 | "plugins": ["stylelint-scss", "stylelint-csstree-validator"], 4 | "rules": { 5 | "at-rule-no-unknown": null, 6 | "scss/at-rule-no-unknown": true, 7 | "csstree/validator": true 8 | }, 9 | "ignoreFiles": ["build/**", "dist/**", "**/reset*.css", "**/bootstrap*.css", "**/*.js", "**/*.jsx"] 10 | } 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Laylo Khodjaeva 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Covid-19 data traker 2 | 3 | > SPA web app which is created using React and Redux. This webapp helps to get new information about Covid-19. 4 | 5 | ![Screenshot](Screenshot_1.png) 6 | ![Screenshot](Screenshot_2.png) 7 | 8 | ## Built With 9 | 10 | - Javascript 11 | - React 12 | - Redux 13 | - CSS 14 | 15 | ## Live Demo 16 | 17 | [NETLIFY](https://covid19-tracker-laylo309.netlify.app/#/home) 18 | 19 | ## Live video presentation 20 | [Loom](https://www.loom.com/share/c85a279634ed4a0faea9f51943ba125e) 21 | 22 | ## Getting Started 23 | 24 | **This is an example of how you may give instructions on setting up your project locally.** 25 | **Modify this file to match your project, remove sections that don't apply. For example: delete the testing section if the currect project doesn't require testing.** 26 | 27 | 28 | To get a local copy up and running follow these simple example steps. 29 | 30 | 31 | ## Setup 32 | 33 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 34 | 35 | ### Available Scripts 36 | 37 | In the project directory, you can run: 38 | 39 | #### `npm start` 40 | 41 | Runs the app in the development mode.\ 42 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 43 | 44 | The page will reload if you make edits.\ 45 | You will also see any lint errors in the console. 46 | 47 | #### `npm test` 48 | 49 | Launches the test runner in the interactive watch mode.\ 50 | 51 | #### `npm run build` 52 | 53 | Builds the app for production to the `build` folder.\ 54 | It correctly bundles React in production mode and optimizes the build for the best performance. 55 | 56 | The build is minified and the filenames include the hashes.\ 57 | App is ready to be deployed! 58 | ## Author 59 | 60 | 👤 **Laylo Khodjaeva** 61 | 62 | - GitHub: [@Laylo309](https://github.com/Laylo309) 63 | - Twitter: [@Laylo](https://twitter.com/home?lang=en) 64 | - LinkedIn: [LayloKhodjaeva](https://www.linkedin.com/in/laylo-khodjaeva-05a972207/) 65 | 66 | ## 🤝 Contributing 67 | 68 | Contributions, issues, and feature requests are welcome! 69 | 70 | Feel free to check the [issues page](../../issues/). 71 | 72 | ## Show your support 73 | 74 | Give a ⭐️ if you like this project! 75 | ## 📝 License 76 | 77 | This project is [MIT](./MIT.md) licensed. 78 | **Original design idea by Nelson Sakwa on Behance.** 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /Screenshot_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Laylo309/react_capstone/7add4831e7f745b06b32ac07db27838dff19a06d/Screenshot_1.png -------------------------------------------------------------------------------- /Screenshot_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Laylo309/react_capstone/7add4831e7f745b06b32ac07db27838dff19a06d/Screenshot_2.png -------------------------------------------------------------------------------- /assetsTransformer.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | process(filename) { 5 | return `module.exports = ${JSON.stringify(path.basename(filename))};`; 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react_capstone", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@popperjs/core": "^2.10.2", 7 | "@testing-library/jest-dom": "^5.14.1", 8 | "@testing-library/react": "^11.2.7", 9 | "@testing-library/user-event": "^12.8.3", 10 | "axios": "^0.21.1", 11 | "bootstrap": "^5.1.3", 12 | "jest-fetch-mock": "^3.0.3", 13 | "node-sass": "^6.0.1", 14 | "popper.js": "^1.16.1", 15 | "prop-types": "^15.7.2", 16 | "react": "^17.0.2", 17 | "react-dom": "^17.0.2", 18 | "react-icons": "^4.2.0", 19 | "react-image": "^4.0.3", 20 | "react-redux": "^7.2.4", 21 | "react-router-bootstrap": "^0.25.0", 22 | "react-router-dom": "^5.2.0", 23 | "react-scripts": "4.0.3", 24 | "react-test-renderer": "^17.0.2", 25 | "redux": "^4.1.1", 26 | "redux-logger": "^3.0.6", 27 | "redux-thunk": "^2.3.0", 28 | "regenerator-runtime": "^0.13.9", 29 | "uuid": "^8.3.2", 30 | "web-vitals": "^1.1.2" 31 | }, 32 | "scripts": { 33 | "start": "react-scripts start", 34 | "build": "react-scripts build", 35 | "test": "jest", 36 | "test:watch": "npm test -- --watch", 37 | "eject": "react-scripts eject", 38 | "predeploy": "npm run build", 39 | "deploy": "gh-pages -d build" 40 | }, 41 | "eslintConfig": { 42 | "extends": [ 43 | "react-app", 44 | "react-app/jest" 45 | ] 46 | }, 47 | "browserslist": { 48 | "production": [ 49 | ">0.2%", 50 | "not dead", 51 | "not op_mini all" 52 | ], 53 | "development": [ 54 | "last 1 chrome version", 55 | "last 1 firefox version", 56 | "last 1 safari version" 57 | ] 58 | }, 59 | "devDependencies": { 60 | "@babel/core": "^7.15.0", 61 | "@babel/eslint-parser": "^7.15.0", 62 | "@babel/plugin-syntax-jsx": "^7.14.5", 63 | "@babel/plugin-transform-runtime": "^7.12.1", 64 | "@babel/preset-env": "^7.15.0", 65 | "@babel/preset-react": "^7.14.5", 66 | "babel-jest": "^26.6.3", 67 | "eslint": "^7.32.0", 68 | "eslint-config-airbnb": "^18.2.1", 69 | "eslint-plugin-import": "^2.24.0", 70 | "eslint-plugin-jsx-a11y": "^6.4.1", 71 | "eslint-plugin-react": "^7.24.0", 72 | "eslint-plugin-react-hooks": "^4.2.0", 73 | "gh-pages": "^3.2.3", 74 | "jest": "^26.6.0", 75 | "jest-dom": "^4.0.0", 76 | "msw": "^0.35.0", 77 | "riteway": "^6.3.1", 78 | "stylelint": "^13.13.1", 79 | "stylelint-config-standard": "^21.0.0", 80 | "stylelint-csstree-validator": "^1.9.0", 81 | "stylelint-scss": "^3.20.1" 82 | }, 83 | "jest": { 84 | "automock": false, 85 | "resetMocks": false, 86 | "setupFiles": [ 87 | "./setupJest.js" 88 | ] 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | React App 12 | 13 | 14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /setupJest.js: -------------------------------------------------------------------------------- 1 | require('jest-fetch-mock').enableMocks(); 2 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect } from 'react'; 2 | import { 3 | Route, Switch, useLocation, 4 | } from 'react-router-dom'; 5 | import Details from './components/Details'; 6 | import Home from './components/Home'; 7 | import Header from './components/Header'; 8 | 9 | function App() { 10 | const { pathname } = useLocation(); 11 | useEffect(() => { 12 | window.scrollTo(0, 0); 13 | }, [pathname]); 14 | return ( 15 | <> 16 |
17 |
18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | ); 29 | } 30 | export default App; 31 | -------------------------------------------------------------------------------- /src/__test__/Country.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import renderer from 'react-test-renderer'; 4 | import '@testing-library/jest-dom'; 5 | import Country from '../components/Country'; 6 | 7 | describe('Country test', () => { 8 | test('The spinner appears in the Country view', () => { 9 | const { container } = render(); 10 | const linkElement = container.querySelector('.spinner'); 11 | expect(linkElement).toBeInTheDocument(); 12 | }); 13 | 14 | test('Test of Snapshot', () => { 15 | const tree = renderer.create().toJSON(); 16 | expect(tree).toMatchSnapshot(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/__test__/__snapshots__/Country.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Country test Test of Snapshot 1`] = ` 4 |
7 |
10 |
11 | `; 12 | -------------------------------------------------------------------------------- /src/components/Country.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { GoChevronRight } from 'react-icons/go'; 3 | import { LinkContainer } from 'react-router-bootstrap'; 4 | 5 | const Country = (props) => { 6 | const { country, filter } = props; 7 | let ans = ( 8 |
9 |
10 |
11 | ); 12 | 13 | if (country) { 14 | ans = Object.values(country).filter(({ name }) => ( 15 | name.toLowerCase().startsWith(filter.toLowerCase()) 16 | )).map((country, index) => ( 17 | 18 |
24 | 25 | 26 |
{country.name.toUpperCase()}
27 |

28 | Infections: 29 | {' '} 30 | { 31 | Number(country.today_confirmed).toLocaleString() 32 | } 33 | 34 |

35 | 36 |
37 |
38 |
39 | )); 40 | } 41 | 42 | return ans; 43 | }; 44 | 45 | export default Country; 46 | -------------------------------------------------------------------------------- /src/components/Details.js: -------------------------------------------------------------------------------- 1 | import { useSelector } from 'react-redux'; 2 | import { useParams } from 'react-router-dom'; 3 | 4 | function Details() { 5 | const params = useParams(); 6 | const { id } = params; 7 | const country = Object.values(useSelector((state) => state.countries)) 8 | .find((country) => country.id === id); 9 | return ( 10 |
11 |
12 |
13 |

{country ? country.name.toUpperCase() : 'Loading...'}

14 |

15 | Infections: 16 | {' '} 17 | {country ? Number(country.today_confirmed).toLocaleString() : '0'} 18 |

19 |

20 | Deaths: 21 | {' '} 22 | {country ? Number(country.today_deaths).toLocaleString() : '0'} 23 |

24 |
25 |
    26 |
  • 27 |

    28 | New confirm: 29 | {' '} 30 | { country.today_new_confirmed } 31 |

    32 |
  • 33 |
  • 34 |

    35 | New deaths: 36 | {' '} 37 | { country.today_new_deaths } 38 |

    39 |
  • 40 |
  • 41 |

    42 | New recovered: 43 | {' '} 44 | { country.today_new_recovered } 45 |

    46 |
  • 47 |
  • 48 |

    49 | Open Cases: 50 | {' '} 51 | { country.today_open_cases } 52 |

    53 |
  • 54 |
  • 55 |

    56 | New Open Cases: 57 | {' '} 58 | { country.today_new_open_cases } 59 |

    60 |
  • 61 |
  • 62 |

    63 | Source: 64 | {' '} 65 | { country.source } 66 |

    67 |
  • 68 |
69 |
70 |
71 | ); 72 | } 73 | export default Details; 74 | -------------------------------------------------------------------------------- /src/components/Filter.js: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types'; 2 | import { GrSend } from 'react-icons/gr'; 3 | 4 | const Filter = (props) => { 5 | const filterValues = (e) => { 6 | props.setFilter(e.target.value); 7 | }; 8 | return ( 9 |
10 | 11 | 12 | 13 | 14 |
15 | ); 16 | }; 17 | Filter.propTypes = { 18 | setFilter: PropTypes.func.isRequired, 19 | }; 20 | export default Filter; 21 | -------------------------------------------------------------------------------- /src/components/Header.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Link } from 'react-router-dom'; 3 | import { FaAngleLeft, FaMicrophone } from 'react-icons/fa'; 4 | import { IoMdSettings } from 'react-icons/io'; 5 | import { MdCoronavirus } from 'react-icons/md'; 6 | 7 | const Header = () => ( 8 |
9 | 25 |
26 | ); 27 | export default Header; 28 | -------------------------------------------------------------------------------- /src/components/Home.js: -------------------------------------------------------------------------------- 1 | import { useState } from 'react'; 2 | import { useSelector } from 'react-redux'; 3 | import Country from './Country'; 4 | import Filter from './Filter'; 5 | import Corona from '../img/Corona.png'; 6 | 7 | function Home() { 8 | const [filter, setFilter] = useState(''); 9 | const countries = useSelector((state) => state.countries); 10 | return ( 11 |
12 |
13 |
14 | virus 15 |
16 |

World

17 |

18 | Infections: 19 | {' '} 20 | {Number(useSelector((state) => state.totalConfirmed)).toLocaleString()} 21 |

22 |
23 |
24 |
25 |
26 |
27 |
28 | 29 |
30 |
31 | 32 |
33 |
34 | ); 35 | } 36 | export default Home; 37 | -------------------------------------------------------------------------------- /src/img/Corona.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Laylo309/react_capstone/7add4831e7f745b06b32ac07db27838dff19a06d/src/img/Corona.png -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --light-magenta: #db4681; 3 | --intense-magenta: #d04379; 4 | --white-with-little-red: #ff91e9; 5 | } 6 | 7 | * { 8 | margin: 0; 9 | padding: 0; 10 | } 11 | 12 | body { 13 | background-color: var(--intense-magenta) !important; 14 | margin: 0; 15 | min-height: 100vh; 16 | } 17 | 18 | .intense-magenta { 19 | background-color: var(--intense-magenta) !important; 20 | } 21 | 22 | .light-magenta { 23 | background: var(--light-magenta); 24 | } 25 | 26 | .pointer { 27 | cursor: pointer; 28 | } 29 | 30 | .min-height { 31 | min-height: 70vh; 32 | } 33 | 34 | .list-style-none { 35 | list-style: none; 36 | } 37 | 38 | .spinner { 39 | border: 4px solid rgba(0, 0, 0, 0.1); 40 | width: 36px !important; 41 | height: 36px; 42 | border-radius: 50%; 43 | border-left-color: var(--white-with-little-red); 44 | animation: spin 1s ease infinite; 45 | } 46 | 47 | @keyframes spin { 48 | 0% { transform: rotate(0deg); } 49 | 100% { transform: rotate(360deg); } 50 | } 51 | 52 | .delete-shadow:focus { 53 | box-shadow: none; 54 | } 55 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import { Provider } from 'react-redux'; 5 | import { BrowserRouter as Router } from 'react-router-dom'; 6 | import { fetchVirus } from './redux/virus/virusInformation'; 7 | import App from './App'; 8 | import store from './redux/configureStore'; 9 | import 'bootstrap/dist/css/bootstrap.min.css'; 10 | import 'bootstrap/dist/js/bootstrap.min'; 11 | 12 | store.dispatch(fetchVirus); 13 | 14 | ReactDOM.render( 15 | 16 | 17 | 18 | 19 | 20 | 21 | , 22 | document.getElementById('root'), 23 | ); 24 | -------------------------------------------------------------------------------- /src/redux/configureStore.js: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware } from 'redux'; 2 | import logger from 'redux-logger'; 3 | import thunkMiddleware from 'redux-thunk'; 4 | import reducer from './virus/virusInformation'; 5 | 6 | const store = createStore( 7 | reducer, 8 | applyMiddleware(thunkMiddleware, logger), 9 | ); 10 | 11 | export default store; 12 | -------------------------------------------------------------------------------- /src/redux/virus/virusInformation.js: -------------------------------------------------------------------------------- 1 | export const FETCH_VIRUS = 'data/FETCH_VIRUS'; 2 | 3 | const LOAD_COUNTRIES = 'countries/LOAD_COUNTRIES'; 4 | const initialState = {}; 5 | 6 | const loadCountries = (payload) => ({ 7 | type: LOAD_COUNTRIES, 8 | payload, 9 | }); 10 | 11 | export const fetchVirus = async (dispatch) => { 12 | const currentDate = new Date().toISOString().slice(0, 10); 13 | await fetch(`https://api.covid19tracking.narrativa.com/api/${currentDate}`) 14 | .then((response) => response.json()) 15 | .then((data) => { 16 | const totalConfirmed = data.total.today_confirmed; 17 | const { countries } = data.dates[currentDate]; 18 | dispatch(loadCountries({ countries, totalConfirmed })); 19 | }); 20 | }; 21 | 22 | const reducer = (state = initialState, action) => { 23 | switch (action.type) { 24 | case LOAD_COUNTRIES: 25 | return action.payload; 26 | default: 27 | return state; 28 | } 29 | }; 30 | 31 | export default reducer; 32 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | --------------------------------------------------------------------------------