├── .gitignore ├── ApiSetup.md ├── README.md ├── license.md ├── package.json ├── postcss.config.js ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.js ├── App.test.js ├── Components │ ├── Footer.js │ ├── Header.js │ ├── HelloWorld.js │ ├── Loader.js │ ├── Navigation.js │ ├── NavigationMenu.js │ └── ProductCard.js ├── Hooks │ └── HttpRequests.js ├── Images │ ├── images-resource.png │ ├── product-resource.png │ └── resources.png ├── Views │ ├── About.js │ ├── Home.js │ └── Product.js ├── index.css ├── index.js ├── logo.svg ├── serviceWorker.js ├── setupTests.js └── tailwind.css ├── tailwind.config.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /ApiSetup.md: -------------------------------------------------------------------------------- 1 | # Set up the API 2 | 3 | This project uses a [Mock API](https://mockapi.io/projects) to fake data. 4 | 5 | ## Here's what the resources look like 6 | 7 | **All Resouces** 8 | ![API Resources](src/Images/resources.png) 9 | 10 | **The product resource with custom description** 11 | ![Product Resource](src/Images/product-resource.png) 12 | 13 | **The image resource with a custom imageUrl** 14 | ![Image Resource](src/Images/images-resource.png) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React JS for beginners 2 | 3 | This is a repository for my [free YouTube course on React JS for beginners](https://www.youtube.com/watch?v=HDEVMozZhv8&list=PL41lfR-6DnOoTiHU4Ub6efP-p3xAq3eiV). 4 | 5 | ### Support more free courses like this 6 | The courses I provide for free are competitive with many paid resources out there. If I can make $5000 monthly through your contributions below, then making videos can become my full time job, and I can help thousands more students get real world development experience with free resources just like this. 7 | 8 | * [Become a Patron](https://www.patreon.com/QuentinWatt) 9 | 10 | * [Join my YouTube channel](https://www.youtube.com/user/QuentinWatt/membership) 11 | 12 | --- 13 | 14 | ## Installation 15 | 16 | 1. Clone this project `git clone git@github.com:QuentinWatt/simple-react-boilerplate.git learn-react` 17 | 2. CD into the directory `cd learn-react` 18 | 3. Install all packages with `yarn` or `npm install` 19 | 4. Start the server with `yarn start` 20 | 5. Set up your own mock api using [these instructions](ApiSetup.md) 21 | 22 | --- 23 | 24 | ## Scripts available in this React Project 25 | 26 | In the project directory, you can run: 27 | 28 | ### `yarn start` 29 | 30 | Runs the app in the development mode.
31 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 32 | 33 | The page will reload if you make edits.
34 | You will also see any lint errors in the console. 35 | 36 | ### `yarn test` 37 | 38 | Launches the test runner in the interactive watch mode.
39 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 40 | 41 | ### `yarn build` 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 | ### `yarn eject` 52 | 53 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 54 | 55 | 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. 56 | 57 | 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. 58 | 59 | 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. 60 | 61 | ## Learn More 62 | 63 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 64 | 65 | To learn React, check out the [React documentation](https://reactjs.org/). 66 | 67 | ### Code Splitting 68 | 69 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 70 | 71 | ### Analyzing the Bundle Size 72 | 73 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 74 | 75 | ### Making a Progressive Web App 76 | 77 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 78 | 79 | ### Advanced Configuration 80 | 81 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 82 | 83 | ### Deployment 84 | 85 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 86 | 87 | ### `yarn build` fails to minify 88 | 89 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 90 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2020-present Quentin Watt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learning-react", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@fortawesome/fontawesome-svg-core": "^1.2.28", 7 | "@fortawesome/free-solid-svg-icons": "^5.13.0", 8 | "@fortawesome/react-fontawesome": "^0.1.9", 9 | "@testing-library/jest-dom": "^4.2.4", 10 | "@testing-library/react": "^9.3.2", 11 | "@testing-library/user-event": "^7.1.2", 12 | "autoprefixer": "^9.7.5", 13 | "axios": "^0.19.2", 14 | "postcss-cli": "^7.1.0", 15 | "react": "^16.13.1", 16 | "react-dom": "^16.13.1", 17 | "react-router-dom": "^5.1.2", 18 | "react-scripts": "3.4.1", 19 | "react-spring": "^8.0.27", 20 | "tailwindcss": "^1.2.0" 21 | }, 22 | "scripts": { 23 | "build:css": "postcss src/index.css -o src/tailwind.css", 24 | "watch:css": "postcss src/index.css -o src/tailwind.css -w", 25 | "start": "yarn build:css && react-scripts start", 26 | "build": "yarn build:css && react-scripts build", 27 | "test": "react-scripts test", 28 | "eject": "react-scripts eject" 29 | }, 30 | "eslintConfig": { 31 | "extends": "react-app" 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require('tailwindcss'), 4 | require('autoprefixer'), 5 | ] 6 | } -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinWatt/React-for-beginners-tutorial-series/5c076b6b24c0d39150483ad49deb238781db91a0/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinWatt/React-for-beginners-tutorial-series/5c076b6b24c0d39150483ad49deb238781db91a0/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinWatt/React-for-beginners-tutorial-series/5c076b6b24c0d39150483ad49deb238781db91a0/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | BrowserRouter as Router, 4 | Switch, 5 | Route 6 | } from "react-router-dom" 7 | import Header from './Components/Header' 8 | import Footer from './Components/Footer' 9 | import Home from './Views/Home' 10 | import About from './Views/About' 11 | import Product from './Views/Product' 12 | 13 | function App() { 14 | return ( 15 |
16 | 17 | 18 |
19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 | 34 |
38 | ); 39 | } 40 | 41 | export default App; 42 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/Components/Footer.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | function Footer(){ 4 | return ( 5 | 8 | ) 9 | } 10 | 11 | export default Footer -------------------------------------------------------------------------------- /src/Components/Header.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Navigation from './Navigation' 3 | import {Link} from 'react-router-dom' 4 | 5 | function Header(){ 6 | return ( 7 |
8 |
9 | 10 | AppName 11 | 12 | 13 | 14 |
15 |
16 | ) 17 | } 18 | 19 | export default Header -------------------------------------------------------------------------------- /src/Components/HelloWorld.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react' 2 | 3 | class HelloWorld extends Component{ 4 | render(){ 5 | return ( 6 |

Hello {this.props.name}

7 | ) 8 | } 9 | } 10 | 11 | export default HelloWorld -------------------------------------------------------------------------------- /src/Components/Loader.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | function Loader(){ 4 | return ( 5 |
6 |
7 |
8 | ) 9 | } 10 | 11 | export default Loader -------------------------------------------------------------------------------- /src/Components/Navigation.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react' 2 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' 3 | import { faBars } from '@fortawesome/free-solid-svg-icons' 4 | import {useTransition, animated} from 'react-spring' 5 | import NavigationMenu from './NavigationMenu' 6 | 7 | 8 | function Navigation(){ 9 | const [showMenu, setShowMenu] = useState(false) 10 | 11 | const maskTransitions = useTransition(showMenu, null, { 12 | from: { position: 'absolute', opacity: 0 }, 13 | enter: { opacity: 1 }, 14 | leave: { opacity: 0 }, 15 | }) 16 | 17 | const menuTransitions = useTransition(showMenu, null, { 18 | from: { opacity: 0, transform: 'translateX(-100%)' }, 19 | enter: { opacity: 1, transform: 'translateX(0%)' }, 20 | leave: { opacity: 0, transform: 'translateX(-100%)' }, 21 | }) 22 | 23 | return ( 24 | 60 | ) 61 | } 62 | 63 | export default Navigation -------------------------------------------------------------------------------- /src/Components/NavigationMenu.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Link } from "react-router-dom" 3 | 4 | function NavigationMenu(props){ 5 | return ( 6 |
7 |
8 | AppName 9 |
10 | 30 |
31 | ) 32 | } 33 | 34 | export default NavigationMenu -------------------------------------------------------------------------------- /src/Components/ProductCard.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {Link} from 'react-router-dom' 3 | 4 | function ProductCard(props){ 5 | return ( 6 |
7 | 8 |
14 |
15 | 16 |
17 |

18 | 19 | { props.product.name } 20 | 21 |

22 |
23 | $ { props.product.price } 24 |
25 |
26 | { props.product.description } 27 |
28 | 32 | View 33 | 34 |
35 |
36 | ) 37 | } 38 | 39 | export default ProductCard -------------------------------------------------------------------------------- /src/Hooks/HttpRequests.js: -------------------------------------------------------------------------------- 1 | import {useEffect, useState} from 'react' 2 | import axios from 'axios' 3 | 4 | export function useAxiosGet(url){ 5 | const [request, setRequest] = useState({ 6 | loading: false, 7 | data: null, 8 | error: false 9 | }) 10 | 11 | useEffect(() => { 12 | setRequest({ 13 | loading: true, 14 | data: null, 15 | error: false 16 | }) 17 | axios.get(url) 18 | .then(response => { 19 | setRequest({ 20 | loading: false, 21 | data: response.data, 22 | error: false 23 | }) 24 | }) 25 | .catch(() => { 26 | setRequest({ 27 | loading: false, 28 | data: null, 29 | error: true 30 | }) 31 | }) 32 | }, [url]) 33 | 34 | return request 35 | } 36 | -------------------------------------------------------------------------------- /src/Images/images-resource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinWatt/React-for-beginners-tutorial-series/5c076b6b24c0d39150483ad49deb238781db91a0/src/Images/images-resource.png -------------------------------------------------------------------------------- /src/Images/product-resource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinWatt/React-for-beginners-tutorial-series/5c076b6b24c0d39150483ad49deb238781db91a0/src/Images/product-resource.png -------------------------------------------------------------------------------- /src/Images/resources.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuentinWatt/React-for-beginners-tutorial-series/5c076b6b24c0d39150483ad49deb238781db91a0/src/Images/resources.png -------------------------------------------------------------------------------- /src/Views/About.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | function About(){ 4 | return ( 5 |
6 |

About us

7 |

8 | This is the about page content. 9 |

10 |
11 | ) 12 | } 13 | 14 | export default About -------------------------------------------------------------------------------- /src/Views/Home.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Loader from '../Components/Loader' 3 | import ProductCard from '../Components/ProductCard' 4 | import { useAxiosGet } from '../Hooks/HttpRequests' 5 | 6 | function Home(){ 7 | // Create your own Mock API: https://mockapi.io/ 8 | const url = `https://5e9623dc5b19f10016b5e31f.mockapi.io/api/v1/products?page=1&limit=10` 9 | let products = useAxiosGet(url) 10 | 11 | let content = null 12 | 13 | if(products.error){ 14 | content =
15 |
16 | If you see this error. Please remember to create your own mock API. 17 |
18 |
19 | There was an error please refresh or try again later. 20 |
21 |
22 | } 23 | 24 | if(products.loading){ 25 | content =
26 | 27 |
28 | } 29 | 30 | if(products.data){ 31 | content = 32 | products.data.map((product) => 33 |
34 | 37 |
38 | ) 39 | } 40 | 41 | return ( 42 |
43 |

44 | Best Sellers 45 |

46 |
47 | {content} 48 |
49 |
50 | ) 51 | } 52 | 53 | export default Home -------------------------------------------------------------------------------- /src/Views/Product.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { useParams } from 'react-router-dom' 3 | import Loader from '../Components/Loader' 4 | import { useAxiosGet } from '../Hooks/HttpRequests' 5 | 6 | function Product(){ 7 | const { id } = useParams() 8 | // Create your own Mock API: https://mockapi.io/ 9 | const url = `https://5e9623dc5b19f10016b5e31f.mockapi.io/api/v1/products/${id}` 10 | 11 | let product = useAxiosGet(url) 12 | 13 | let content = null 14 | 15 | if(product.error){ 16 | content =
17 |
18 | If you see this error. Please remember to create your own mock API. 19 |
20 |
21 | There was an error please refresh or try again later. 22 |
23 |
24 | } 25 | 26 | if(product.loading){ 27 | content = 28 | } 29 | 30 | if(product.data){ 31 | content = 32 |
33 |

34 | {product.data.name} 35 |

36 |
37 | {product.data.name} 41 |
42 |
43 | $ {product.data.price} 44 |
45 |
46 | {product.data.description} 47 |
48 |
49 | } 50 | 51 | return ( 52 |
53 | {content} 54 |
55 | ) 56 | } 57 | 58 | export default Product -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | 3 | @tailwind components; 4 | 5 | @tailwind utilities; 6 | 7 | .loader { 8 | border: 5px solid #f3f3f3; 9 | border-radius: 50%; 10 | border-top: 5px solid #3498db; 11 | width: 50px; 12 | height: 50px; 13 | -webkit-animation: spin 2s linear infinite; /* Safari */ 14 | animation: spin 2s linear infinite; 15 | } 16 | 17 | /* Safari */ 18 | @-webkit-keyframes spin { 19 | 0% { -webkit-transform: rotate(0deg); } 20 | 100% { -webkit-transform: rotate(360deg); } 21 | } 22 | 23 | @keyframes spin { 24 | 0% { transform: rotate(0deg); } 25 | 100% { transform: rotate(360deg); } 26 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './tailwind.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want your app to work offline and load faster, you can change 15 | // unregister() to register() below. Note this comes with some pitfalls. 16 | // Learn more about service workers: https://bit.ly/CRA-PWA 17 | serviceWorker.unregister(); 18 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' }, 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready 134 | .then(registration => { 135 | registration.unregister(); 136 | }) 137 | .catch(error => { 138 | console.error(error.message); 139 | }); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | theme: { 3 | extend: { 4 | backgroundColor:{ 5 | 'black-t-50': 'rgba(0,0,0,0.5)', 6 | } 7 | }, 8 | }, 9 | variants: {}, 10 | plugins: [], 11 | } 12 | --------------------------------------------------------------------------------