Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 71796eb

Browse files
basic service worker file added, react log errors are removed in multiple files
1 parent 2bd7723 commit 71796eb

File tree

7 files changed

+196
-139
lines changed

7 files changed

+196
-139
lines changed

public/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,14 @@
3636
To begin the development, run `npm start` or `yarn start`.
3737
To create a production bundle, use `npm run build` or `yarn build`.
3838
--></body>
39+
<script>
40+
if ('serviceWorker' in navigator) {
41+
window.addEventListener('load', () => {
42+
navigator.serviceWorker
43+
.register('./serviceworker.js')
44+
.then((reg) => console.log('Success: ', reg.scope))
45+
.catch((err) => console.log('Failure: ', err));
46+
});
47+
}
48+
</script>
3949
</html>

public/serviceworker.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const CACHE_NAME = 'version-1';
2+
const urlsToCache = ['index.html', 'offline.html'];
3+
4+
const self = this;
5+
6+
// Install SW
7+
self.addEventListener('install', (event) => {
8+
event.waitUntil(
9+
caches.open(CACHE_NAME).then((cache) => {
10+
console.log('Opened cache');
11+
12+
return cache.addAll(urlsToCache);
13+
})
14+
);
15+
});
16+
17+
// Listen for requests
18+
self.addEventListener('fetch', (event) => {
19+
event.respondWith(
20+
caches.match(event.request).then(() => {
21+
return fetch(event.request).catch(() =>
22+
caches.match('offline.html')
23+
);
24+
})
25+
);
26+
});
27+
28+
// Activate the SW
29+
self.addEventListener('activate', (event) => {
30+
const cacheWhitelist = [];
31+
cacheWhitelist.push(CACHE_NAME);
32+
33+
event.waitUntil(
34+
caches.keys().then((cacheNames) =>
35+
Promise.all(
36+
cacheNames.map((cacheName) => {
37+
if (!cacheWhitelist.includes(cacheName)) {
38+
return caches.delete(cacheName);
39+
}
40+
})
41+
)
42+
)
43+
);
44+
});

src/components/routes/PrivateRoute.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { useEffect } from 'react';
2-
import { Route } from 'react-router-dom';
31
import { Layout } from 'antd';
2+
import React, { useEffect } from 'react';
43
import { useDispatch } from 'react-redux';
4+
import { Route } from 'react-router-dom';
55
import { SESSION } from '../../services';
6-
import { Sidebar } from '../sidebar';
6+
// import { Sidebar } from '../sidebar';
77
import { HeadNavbar } from '../common';
88

99
const { Content } = Layout;

src/forms/todo/todo.form.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import React, { useState, useEffect } from 'react';
2-
import { useDispatch, useSelector } from 'react-redux';
3-
import { message, Col, Row } from 'antd';
4-
import { Form, Input, DatePicker, Select } from 'formik-antd';
1+
import { Col, message, Row } from 'antd';
52
import { Formik } from 'formik';
6-
import * as Yup from 'yup';
7-
import PropTypes from 'prop-types';
8-
import moment from 'moment';
3+
import { DatePicker, Form, Input, Select } from 'formik-antd';
94
import { isEmpty } from 'lodash';
10-
import { API } from '../../services';
11-
import { FormActionButtons } from '../FormActionButtons';
5+
import moment from 'moment';
6+
import PropTypes from 'prop-types';
7+
import React, { useEffect, useState } from 'react';
8+
import { useDispatch, useSelector } from 'react-redux';
9+
import * as Yup from 'yup';
1210
import { TODO_LABEL } from '../../helpers/constants';
11+
import { API } from '../../services';
1312
import { updatedTodoList } from '../../store/actions/api.actions';
13+
import { FormActionButtons } from '../FormActionButtons';
1414

1515
const { Option } = Select;
1616

@@ -46,17 +46,17 @@ function TodoForm({ onClose }) {
4646

4747
useEffect(() => {
4848
try {
49-
const formInitialValues = {
49+
const formData = {
5050
title: editMode ? editTodoData.title : undefined,
5151
description: editMode ? editTodoData.description : undefined,
5252
dueDate: editMode ? moment(editTodoData.dueDate) : TOMORROW,
5353
label: editMode ? editTodoData.label : 1,
5454
};
55-
setFormInitialValues(formInitialValues);
55+
setFormInitialValues(formData);
5656
} catch (error) {
5757
console.log('error', error);
5858
}
59-
}, [editMode]);
59+
}, [editMode, editTodoData]);
6060

6161
function handleSubmit(values, { setErrors, resetForm, setSubmitting }) {
6262
let url = `todos`;

src/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { Provider } from 'react-redux';
4-
54
import 'typeface-roboto';
6-
import './styles/style.scss';
5+
// import { ErrorBoundary } from './components/common';
76
import Router from './router';
8-
import store from './store/configureStore';
97
import * as serviceWorker from './serviceWorker';
10-
import { ErrorBoundary } from './components/common';
8+
import store from './store/configureStore';
9+
import './styles/style.scss';
1110

1211
console.log('build = ', process.env.NODE_ENV);
1312

1413
ReactDOM.render(
15-
<ErrorBoundary>
16-
<Provider store={store}>
17-
<Router />
18-
</Provider>
19-
</ErrorBoundary>,
14+
// <ErrorBoundary></ErrorBoundary>
15+
<Provider store={store}>
16+
<Router />
17+
</Provider>,
2018
document.getElementById('root')
2119
);
2220

src/pages/Todo.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { Col, Row } from 'antd';
12
import React from 'react';
2-
import { Row, Col } from 'antd';
3-
import { ModalForm, DrawerForm, TodoForm } from '../forms/todo';
3+
// import { ModalForm, DrawerForm, TodoForm } from '../forms/todo';
44
import { TodoList } from '../components/todo';
5+
import { ModalForm } from '../forms/todo';
56

67
export default function Todo() {
7-
function onClose() {
8-
console.log('onClose');
9-
}
8+
// function onClose() {
9+
// console.log('onClose');
10+
// }
1011

1112
return (
1213
<div className="main-layout">

0 commit comments

Comments
 (0)