├── .DS_Store
├── .gitignore
├── LICENSE
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
└── manifest.json
└── src
├── .DS_Store
├── App.css
├── App.js
├── App.test.js
├── api
└── quizQuestions.js
├── components
├── AnswerOption.js
├── Question.js
├── QuestionCount.js
├── Quiz.js
└── Result.js
├── index.css
├── index.js
├── serviceWorker.js
└── svg
├── icon-check.svg
└── logo.svg
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchgavan/react-multi-choice-quiz/0d98bd676f7a67b9d45e0abbba015f3cd15dba36/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 | .env.local
15 | .env.development.local
16 | .env.test.local
17 | .env.production.local
18 |
19 | npm-debug.log*
20 | yarn-debug.log*
21 | yarn-error.log*
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Mitch Gavan
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 | # React Quiz
2 |
3 | [View demo](http://mitchgavan.github.io/react-multi-choice-quiz/)
4 |
5 | There's also an accompanying [tutorial blog post](https://mitchgavan.com/react-quiz/).
6 |
7 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
8 |
9 | ## Available Scripts
10 |
11 | In the project directory, you can run:
12 |
13 | ### `npm start`
14 |
15 | Runs the app in the development mode.
16 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
17 |
18 | The page will reload if you make edits.
19 | You will also see any lint errors in the console.
20 |
21 | ### `npm test`
22 |
23 | Launches the test runner in the interactive watch mode.
24 | See the section about [running tests](#running-tests) for more information.
25 |
26 | ### `npm run build`
27 |
28 | Builds the app for production to the `build` folder.
29 | It correctly bundles React in production mode and optimizes the build for the best performance.
30 |
31 | The build is minified and the filenames include the hashes.
32 | Your app is ready to be deployed!
33 |
34 | See the section about [deployment](#deployment) for more information.
35 |
36 | ### `npm run eject`
37 |
38 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
39 |
40 | 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.
41 |
42 | 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.
43 |
44 | 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.
45 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-quiz",
3 | "version": "2.0.0",
4 | "private": false,
5 | "dependencies": {
6 | "prop-types": "^15.6.2",
7 | "react": "^16.5.2",
8 | "react-dom": "^16.5.2",
9 | "react-scripts": "5.0.1",
10 | "react-transition-group": "^1.2.1"
11 | },
12 | "scripts": {
13 | "start": "react-scripts start",
14 | "build": "react-scripts build",
15 | "test": "react-scripts test",
16 | "eject": "react-scripts eject"
17 | },
18 | "eslintConfig": {
19 | "extends": "react-app"
20 | },
21 | "browserslist": [
22 | ">0.2%",
23 | "not dead",
24 | "not ie <= 11",
25 | "not op_mini all"
26 | ]
27 | }
28 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchgavan/react-multi-choice-quiz/0d98bd676f7a67b9d45e0abbba015f3cd15dba36/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
22 | React App
23 |
24 |
25 |
26 | You need to enable JavaScript to run this app.
27 |
28 |
29 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/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 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitchgavan/react-multi-choice-quiz/0d98bd676f7a67b9d45e0abbba015f3cd15dba36/src/.DS_Store
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | .App-logo {
2 | animation: spin infinite 20s linear;
3 | height: 80px;
4 | }
5 |
6 | .App-header {
7 | background-color: #222;
8 | padding: 20px;
9 | color: white;
10 | text-align: center;
11 | }
12 |
13 | .App-intro {
14 | font-size: large;
15 | }
16 |
17 | @keyframes spin {
18 | from {
19 | transform: rotate(0deg);
20 | }
21 | to {
22 | transform: rotate(360deg);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import quizQuestions from './api/quizQuestions';
3 | import Quiz from './components/Quiz';
4 | import Result from './components/Result';
5 | import logo from './svg/logo.svg';
6 | import './App.css';
7 |
8 | class App extends Component {
9 | constructor(props) {
10 | super(props);
11 |
12 | this.state = {
13 | counter: 0,
14 | questionId: 1,
15 | question: '',
16 | answerOptions: [],
17 | answer: '',
18 | answersCount: {},
19 | result: ''
20 | };
21 |
22 | this.handleAnswerSelected = this.handleAnswerSelected.bind(this);
23 | }
24 |
25 | componentDidMount() {
26 | const shuffledAnswerOptions = quizQuestions.map(question =>
27 | this.shuffleArray(question.answers)
28 | );
29 | this.setState({
30 | question: quizQuestions[0].question,
31 | answerOptions: shuffledAnswerOptions[0]
32 | });
33 | }
34 |
35 | shuffleArray(array) {
36 | var currentIndex = array.length,
37 | temporaryValue,
38 | randomIndex;
39 |
40 | // While there remain elements to shuffle...
41 | while (0 !== currentIndex) {
42 | // Pick a remaining element...
43 | randomIndex = Math.floor(Math.random() * currentIndex);
44 | currentIndex -= 1;
45 |
46 | // And swap it with the current element.
47 | temporaryValue = array[currentIndex];
48 | array[currentIndex] = array[randomIndex];
49 | array[randomIndex] = temporaryValue;
50 | }
51 |
52 | return array;
53 | }
54 |
55 | handleAnswerSelected(event) {
56 | this.setUserAnswer(event.currentTarget.value);
57 |
58 | if (this.state.questionId < quizQuestions.length) {
59 | setTimeout(() => this.setNextQuestion(), 300);
60 | } else {
61 | setTimeout(() => this.setResults(this.getResults()), 300);
62 | }
63 | }
64 |
65 | setUserAnswer(answer) {
66 | this.setState((state, props) => ({
67 | answersCount: {
68 | ...state.answersCount,
69 | [answer]: (state.answersCount[answer] || 0) + 1
70 | },
71 | answer: answer
72 | }));
73 | }
74 |
75 | setNextQuestion() {
76 | const counter = this.state.counter + 1;
77 | const questionId = this.state.questionId + 1;
78 |
79 | this.setState({
80 | counter: counter,
81 | questionId: questionId,
82 | question: quizQuestions[counter].question,
83 | answerOptions: quizQuestions[counter].answers,
84 | answer: ''
85 | });
86 | }
87 |
88 | getResults() {
89 | const answersCount = this.state.answersCount;
90 | const answersCountKeys = Object.keys(answersCount);
91 | const answersCountValues = answersCountKeys.map(key => answersCount[key]);
92 | const maxAnswerCount = Math.max.apply(null, answersCountValues);
93 |
94 | return answersCountKeys.filter(key => answersCount[key] === maxAnswerCount);
95 | }
96 |
97 | setResults(result) {
98 | if (result.length === 1) {
99 | this.setState({ result: result[0] });
100 | } else {
101 | this.setState({ result: 'Undetermined' });
102 | }
103 | }
104 |
105 | renderQuiz() {
106 | return (
107 |
115 | );
116 | }
117 |
118 | renderResult() {
119 | return ;
120 | }
121 |
122 | render() {
123 | return (
124 |
125 |
126 |
127 |
React Quiz
128 |
129 | {this.state.result ? this.renderResult() : this.renderQuiz()}
130 |
131 | );
132 | }
133 | }
134 |
135 | export default App;
136 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 |
5 | it('renders without crashing', () => {
6 | const div = document.createElement('div');
7 | ReactDOM.render( , div);
8 | ReactDOM.unmountComponentAtNode(div);
9 | });
10 |
--------------------------------------------------------------------------------
/src/api/quizQuestions.js:
--------------------------------------------------------------------------------
1 | var quizQuestions = [
2 | {
3 | question: "What franchise would you rather play a game from?",
4 | answers: [
5 | {
6 | type: "Microsoft",
7 | content: "Halo"
8 | },
9 | {
10 | type: "Nintendo",
11 | content: "Pokemon"
12 | },
13 | {
14 | type: "Sony",
15 | content: "Uncharted"
16 | }
17 | ]
18 | },
19 | {
20 | question: "Which console would you prefer to play with friends?",
21 | answers: [
22 | {
23 | type: "Microsoft",
24 | content: "X-Box"
25 | },
26 | {
27 | type: "Nintendo",
28 | content: "Nintendo 64"
29 | },
30 | {
31 | type: "Sony",
32 | content: "Playstation 1"
33 | }
34 | ]
35 | },
36 | {
37 | question: "Which of these racing franchises would you prefer to play a game from?",
38 | answers: [
39 | {
40 | type: "Microsoft",
41 | content: "Forza"
42 | },
43 | {
44 | type: "Nintendo",
45 | content: "Mario Kart"
46 | },
47 | {
48 | type: "Sony",
49 | content: "Gran Turismo"
50 | }
51 | ]
52 | },
53 | {
54 | question: "Which of these games do you think is best?",
55 | answers: [
56 | {
57 | type: "Microsoft",
58 | content: "BioShock"
59 | },
60 | {
61 | type: "Nintendo",
62 | content: "The Legend of Zelda: Ocarina of Time"
63 | },
64 | {
65 | type: "Sony",
66 | content: "Final Fantasy VII"
67 | }
68 | ]
69 | },
70 | {
71 | question: "What console would you prefer to own?",
72 | answers: [
73 | {
74 | type: "Microsoft",
75 | content: "X-Box One"
76 | },
77 | {
78 | type: "Nintendo",
79 | content: "Wii U"
80 | },
81 | {
82 | type: "Sony",
83 | content: "Playstation 4"
84 | }
85 | ]
86 | }
87 | ];
88 |
89 | export default quizQuestions;
90 |
--------------------------------------------------------------------------------
/src/components/AnswerOption.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 |
4 | function AnswerOption(props) {
5 | return (
6 |
7 |
17 |
18 | {props.answerContent}
19 |
20 |
21 | );
22 | }
23 |
24 | AnswerOption.propTypes = {
25 | answerType: PropTypes.string.isRequired,
26 | answerContent: PropTypes.string.isRequired,
27 | answer: PropTypes.string.isRequired,
28 | onAnswerSelected: PropTypes.func.isRequired
29 | };
30 |
31 | export default AnswerOption;
32 |
--------------------------------------------------------------------------------
/src/components/Question.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 |
4 | function Question(props) {
5 | return {props.content} ;
6 | }
7 |
8 | Question.propTypes = {
9 | content: PropTypes.string.isRequired
10 | };
11 |
12 | export default Question;
13 |
--------------------------------------------------------------------------------
/src/components/QuestionCount.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 |
4 | function QuestionCount(props) {
5 | return (
6 |
7 | Question {props.counter} of {props.total}
8 |
9 | );
10 | }
11 |
12 | QuestionCount.propTypes = {
13 | counter: PropTypes.number.isRequired,
14 | total: PropTypes.number.isRequired
15 | };
16 |
17 | export default QuestionCount;
18 |
--------------------------------------------------------------------------------
/src/components/Quiz.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import { CSSTransitionGroup } from 'react-transition-group';
4 | import Question from '../components/Question';
5 | import QuestionCount from '../components/QuestionCount';
6 | import AnswerOption from '../components/AnswerOption';
7 |
8 | function Quiz(props) {
9 | function renderAnswerOptions(key) {
10 | return (
11 |
19 | );
20 | }
21 |
22 | return (
23 |
32 |
33 |
34 |
35 |
36 | {props.answerOptions.map(renderAnswerOptions)}
37 |
38 |
39 |
40 | );
41 | }
42 |
43 | Quiz.propTypes = {
44 | answer: PropTypes.string.isRequired,
45 | answerOptions: PropTypes.array.isRequired,
46 | question: PropTypes.string.isRequired,
47 | questionId: PropTypes.number.isRequired,
48 | questionTotal: PropTypes.number.isRequired,
49 | onAnswerSelected: PropTypes.func.isRequired
50 | };
51 |
52 | export default Quiz;
53 |
--------------------------------------------------------------------------------
/src/components/Result.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import PropTypes from 'prop-types';
3 | import { CSSTransitionGroup } from 'react-transition-group';
4 |
5 | function Result(props) {
6 | return (
7 |
16 |
17 | You prefer {props.quizResult} !
18 |
19 |
20 | );
21 | }
22 |
23 | Result.propTypes = {
24 | quizResult: PropTypes.string.isRequired
25 | };
26 |
27 | export default Result;
28 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
5 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
6 | sans-serif;
7 | -webkit-font-smoothing: antialiased;
8 | -moz-osx-font-smoothing: grayscale;
9 | }
10 |
11 | code {
12 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
13 | monospace;
14 | }
15 |
16 | * {
17 | box-sizing: border-box;
18 | }
19 |
20 | body {
21 | margin: 0;
22 | padding: 0;
23 | background: #eee;
24 | font-family: sans-serif;
25 | }
26 |
27 | .container {
28 | position: relative;
29 | max-width: 800px;
30 | margin: 0 auto;
31 | background: #fff;
32 | border-radius: 3px;
33 | }
34 |
35 | @media (min-width: 769px) {
36 | .container {
37 | margin: 2.5rem auto;
38 | }
39 | }
40 |
41 | /* Result Component */
42 | .result {
43 | padding: 1.5rem 2.5rem;
44 | }
45 |
46 | /* Quiz Component */
47 | .answerOptions {
48 | margin: 0;
49 | padding: 0;
50 | list-style: none;
51 | }
52 |
53 | /* QuestionCount Component */
54 | .questionCount {
55 | padding: 1.5rem 2.5rem 0;
56 | font-size: 14px;
57 | }
58 |
59 | /* Question Component */
60 | .question {
61 | margin: 0;
62 | padding: 0.5rem 2.5rem 1.5rem 2.5rem;
63 | }
64 |
65 | /* AnswerOption Component */
66 | .answerOption {
67 | border-top: 1px solid #eee;
68 | }
69 |
70 | .answerOption:hover {
71 | background-color: #eefbfe;
72 | }
73 |
74 | .radioCustomButton {
75 | position: absolute;
76 | width: auto;
77 | opacity: 0;
78 | }
79 |
80 | .radioCustomButton,
81 | .radioCustomLabel {
82 | display: inline-block;
83 | vertical-align: middle;
84 | cursor: pointer;
85 | }
86 |
87 | .radioCustomLabel {
88 | position: relative;
89 | width: 100%;
90 | margin: 0;
91 | padding: 1.5rem 2.5rem 1.5rem 5rem;
92 | font-size: 16px;
93 | line-height: 1.5;
94 | }
95 |
96 | .radioCustomButton ~ .radioCustomLabel:before {
97 | position: absolute;
98 | top: 20px;
99 | left: 38px;
100 | width: 28px;
101 | height: 28px;
102 | content: '';
103 | display: inline-block;
104 | vertical-align: middle;
105 | background: #fff;
106 | border: 1px solid #bbb;
107 | border-radius: 50%;
108 | transition: all 0.3s;
109 | }
110 |
111 | .radioCustomButton:checked ~ .radioCustomLabel:before {
112 | content: '';
113 | background: #8bc53f url(./svg/icon-check.svg) no-repeat;
114 | background-size: 27px;
115 | border-color: #8bc53f;
116 | }
117 |
118 | /* Animation */
119 | .fade-enter {
120 | opacity: 0;
121 | }
122 |
123 | .fade-enter.fade-enter-active {
124 | opacity: 1;
125 | transition: opacity 0.5s ease-in-out 0.3s;
126 | }
127 |
128 | .fade-leave {
129 | position: absolute;
130 | top: 0;
131 | left: 0;
132 | width: 100%;
133 | opacity: 1;
134 | }
135 |
136 | .fade-leave.fade-leave-active {
137 | opacity: 0;
138 | transition: opacity 0.5s ease-in-out;
139 | }
140 |
141 | .fade-appear {
142 | opacity: 0;
143 | }
144 |
145 | .fade-appear.fade-appear-active {
146 | opacity: 1;
147 | transition: opacity 0.5s ease-in-out;
148 | }
149 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render( , document.getElementById('root'));
8 |
9 | // If you want your app to work offline and load faster, you can change
10 | // unregister() to register() below. Note this comes with some pitfalls.
11 | // Learn more about service workers: http://bit.ly/CRA-PWA
12 | serviceWorker.unregister();
13 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // In production, we register a service worker to serve assets from local cache.
2 |
3 | // This lets the app load faster on subsequent visits in production, and gives
4 | // it offline capabilities. However, it also means that developers (and users)
5 | // will only see deployed updates on the "N+1" visit to a page, since previously
6 | // cached resources are updated in the background.
7 |
8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
9 | // This link also includes instructions on opting out of this behavior.
10 |
11 | const isLocalhost = Boolean(
12 | window.location.hostname === 'localhost' ||
13 | // [::1] is the IPv6 localhost address.
14 | window.location.hostname === '[::1]' ||
15 | // 127.0.0.1/8 is considered localhost for IPv4.
16 | window.location.hostname.match(
17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
18 | )
19 | );
20 |
21 | export function register(config) {
22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
23 | // The URL constructor is available in all browsers that support SW.
24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
25 | if (publicUrl.origin !== window.location.origin) {
26 | // Our service worker won't work if PUBLIC_URL is on a different origin
27 | // from what our page is served on. This might happen if a CDN is used to
28 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
29 | return;
30 | }
31 |
32 | window.addEventListener('load', () => {
33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
34 |
35 | if (isLocalhost) {
36 | // This is running on localhost. Let's check if a service worker still exists or not.
37 | checkValidServiceWorker(swUrl, config);
38 |
39 | // Add some additional logging to localhost, pointing developers to the
40 | // service worker/PWA documentation.
41 | navigator.serviceWorker.ready.then(() => {
42 | console.log(
43 | 'This web app is being served cache-first by a service ' +
44 | 'worker. To learn more, visit https://goo.gl/SC7cgQ'
45 | );
46 | });
47 | } else {
48 | // Is not local host. Just register service worker
49 | registerValidSW(swUrl, config);
50 | }
51 | });
52 | }
53 | }
54 |
55 | function registerValidSW(swUrl, config) {
56 | navigator.serviceWorker
57 | .register(swUrl)
58 | .then(registration => {
59 | registration.onupdatefound = () => {
60 | const installingWorker = registration.installing;
61 | installingWorker.onstatechange = () => {
62 | if (installingWorker.state === 'installed') {
63 | if (navigator.serviceWorker.controller) {
64 | // At this point, the old content will have been purged and
65 | // the fresh content will have been added to the cache.
66 | // It's the perfect time to display a "New content is
67 | // available; please refresh." message in your web app.
68 | console.log('New content is available; please refresh.');
69 |
70 | // Execute callback
71 | if (config.onUpdate) {
72 | config.onUpdate(registration);
73 | }
74 | } else {
75 | // At this point, everything has been precached.
76 | // It's the perfect time to display a
77 | // "Content is cached for offline use." message.
78 | console.log('Content is cached for offline use.');
79 |
80 | // Execute callback
81 | if (config.onSuccess) {
82 | config.onSuccess(registration);
83 | }
84 | }
85 | }
86 | };
87 | };
88 | })
89 | .catch(error => {
90 | console.error('Error during service worker registration:', error);
91 | });
92 | }
93 |
94 | function checkValidServiceWorker(swUrl, config) {
95 | // Check if the service worker can be found. If it can't reload the page.
96 | fetch(swUrl)
97 | .then(response => {
98 | // Ensure service worker exists, and that we really are getting a JS file.
99 | if (
100 | response.status === 404 ||
101 | response.headers.get('content-type').indexOf('javascript') === -1
102 | ) {
103 | // No service worker found. Probably a different app. Reload the page.
104 | navigator.serviceWorker.ready.then(registration => {
105 | registration.unregister().then(() => {
106 | window.location.reload();
107 | });
108 | });
109 | } else {
110 | // Service worker found. Proceed as normal.
111 | registerValidSW(swUrl, config);
112 | }
113 | })
114 | .catch(() => {
115 | console.log(
116 | 'No internet connection found. App is running in offline mode.'
117 | );
118 | });
119 | }
120 |
121 | export function unregister() {
122 | if ('serviceWorker' in navigator) {
123 | navigator.serviceWorker.ready.then(registration => {
124 | registration.unregister();
125 | });
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/svg/icon-check.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/svg/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------