Skip to content

Commit

Permalink
Modified service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
surielmx committed Mar 19, 2021
1 parent 6c8432a commit f762474
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
command: 'npm start'
background: true
- run:
name: "Runing tests"
name: "Running tests"
command: npx cypress run --record --key $CYPRESS_RECORD_KEY
30 changes: 30 additions & 0 deletions .firebase/hosting.YnVpbGQ.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
asset-manifest.json,1607015017838,637795db4c9bfd5a83b3be695b53eefbf41babc0a6c41be26001a69a491f6f74
index.html,1607015017838,5a3074114a4d1fef5062cd2eac42e3ba4f0a93a99fa90c2331849ae6564fbc08
logo192.png,1607014993783,caff018b7f1e8fd481eb1c50d75b0ef236bcd5078b1d15c8bb348453fee30293
static/css/6.f8d41b26.chunk.css,1607015017835,7ac0851dee7003928162d122ea99fa0f91ca2d6db5f260f79caeddc32d2f1c0d
favicon.ico,1607014993782,b72f7455f00e4e58792d2bca892abb068e2213838c0316d6b7a0d6d16acd1955
static/css/6.f8d41b26.chunk.css.map,1607015017834,c9b94518337e29837d8cff7ac2931be2ac01c811cecb2a9d1a2ce641335684b7
static/css/main.f21e830a.chunk.css,1607015017832,3cca8007a83800f3781e82526aad6f6f1e5c3f5ac22159d570b229ecb9a1e2af
logo512.png,1607014993789,191fc21360b4ccfb1cda11a1efb97f489ed22672ca83f4064316802bbfdd750e
manifest.json,1607014993792,341d52628782f8ac9290bbfc43298afccb47b7cbfcee146ae30cf0f46bc30900
robots.txt,1607014993797,391d14b3c2f8c9143a27a28c7399585142228d4d1bdbe2c87ac946de411fa9a2
static/js/2.a7db07db.chunk.js.LICENSE.txt,1607015017834,10c6f21b02a3e5df21b9e300b25eded1e0353200e84518db8b2a9e7a3f6fcfe0
static/css/main.f21e830a.chunk.css.map,1607015017836,0db2a1c52b95862370abc59e0a78ef66d33c430ff681c5cd76698e749f4e7d58
static/js/3.aec9c59e.chunk.js,1607015017834,1c530ebea53490d63f9b1af418fee0cda9f536bd21bc3d423ae62a95d97d3257
service-worker.js,1607015017829,240be5c423d354b5bdef2d5db613c5b6e3dd7171e695fc5e48a0d62f97956287
static/js/4.32f755a1.chunk.js,1607015017834,4dfaa4606163e479d71a11ffe73dd4497f5e3f63566113c557fed2a26d3b4a99
static/js/5.cc09b653.chunk.js,1607015017835,dc2679a31890ec4bc0c4e77e63f65b5425a7e8562af0368ee4872ac064ccd84a
static/js/3.aec9c59e.chunk.js.map,1607015017839,46b43a72df7a7e55faa57974c7d53ce46ee6e463b1bbfa45a0924602d0bcd09b
static/js/6.191246bc.chunk.js,1607015017835,9aadd1b5f10f0347bb0fbb3a34879ded59e7b6db54916e525d0d362866eb400a
static/js/4.32f755a1.chunk.js.map,1607015017839,a60d0641a940bcc61cbb3ca13a394849bba2811d7bd3e1ba5422d9a92a69e4f4
static/js/6.191246bc.chunk.js.map,1607015017839,abdc56840e0d82df161534c3b136e246f0957a712457686a7635f1a2d69365ad
static/js/7.79b372a3.chunk.js,1607015017834,318484a47de83a32dc833d262d39c633389d5547749557fca99c8eee9fdd8d0c
static/js/7.79b372a3.chunk.js.map,1607015017839,1baca1e1ef9f233b79e085adc12822c1d738e4795592a4490b10657e628482a0
static/js/main.ebc54cc1.chunk.js,1607015017833,84888735d5f02c1ade2c80b5c06e92683690a46f9435a3232e75c3a7cdbbe948
static/js/runtime-main.fb277b5b.js,1607015017834,bb90654d55a167f829d48b64677d62c7646562a60084b81c7cf64786e011d862
static/js/main.ebc54cc1.chunk.js.map,1607015017834,ff645b903412484021173807497d582efa86419125ad580354b704d1470cf19a
static/js/5.cc09b653.chunk.js.map,1607015017839,a6871eaaa33e64c2431ae7afef4bb59ef5c69c23f6030ab1ea3d7288c20c7e42
static/js/runtime-main.fb277b5b.js.map,1607015017834,b2a0123c407990521461178849037449ed5f2f3bb9fcc055bd0e242ba13c8b57
static/js/2.a7db07db.chunk.js,1607015017833,f4cdf46ab9a94e5d6cd51d0ab7c49ba241f79e4b358362611beed13ed2aacffc
service-worker.js.map,1607015017829,5a94c4d369c4b21cf3dd2122d036d46642394e0cf0c61d77e33537736ce82275
static/js/2.a7db07db.chunk.js.map,1607015017839,9210ddbad9d8e9a2acce3f2caa819526c47a6abb7e9d8880ce6ce2d7c45b491c
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
.eslintcache
.firebase/**

# dependencies
/node_modules
Expand All @@ -22,3 +23,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.vscode/
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"json.schemas": [
{
"fileMatch": [
"cypress.json"
],
"url": "https://on.cypress.io/cypress.schema.json"
}
]
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"react-toastify": "^7.0.3",
"web-vitals": "^0.2.4",
"workbox-background-sync": "^5.1.3",
"workbox-broadcast-update": "^5.1.3",
Expand Down
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck
import React, { Fragment, Suspense, lazy } from 'react';
import { Route, Switch, Redirect } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';

import Skeleton from './components/Skeleton';
import Progress from './components/Progress/Progress';
Expand Down Expand Up @@ -80,6 +81,7 @@ function App() {
</Switch>
</Suspense>
</main>
<ToastContainer />
<Snackbar showStatus={isOffLine} />
</Fragment>
);
Expand Down
37 changes: 26 additions & 11 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
:root{
--title: #2D3848;
:root {
--title: #2d3848;
--content: #666c75;
--header: #ffffff;
--body:#ffffff;
--bg:#ffffff;
--body: #ffffff;
--bg: #ffffff;
--link: #3854b2;
--skeleton: #eaeaea;
}
.dark{
.dark {
--title: #ffffff;
--content: #ffffff;
--header: #1A202C;
--body:#3A4556;
--bg:#2d3747;
--header: #1a202c;
--body: #3a4556;
--bg: #2d3747;
--link: #74befa;
--skeleton: #1d2939;
}
Expand Down Expand Up @@ -40,13 +40,25 @@ body {
width: 15px;
}
*::-webkit-scrollbar-thumb {
background: -webkit-gradient(linear, left top, left bottom, from(var(--skeleton)), to(var(--skeleton)));
background: -webkit-gradient(
linear,
left top,
left bottom,
from(var(--skeleton)),
to(var(--skeleton))
);
background: linear-gradient(to bottom, var(--title), var(--title));
border-radius: 30px;
box-shadow: inset 3px 3px 3px var(--title), inset -2px -2px 2px rgba(0, 0, 0, 0.25);
}
*::-webkit-scrollbar-track {
background: linear-gradient(to right, var(--body), var(--body) 0.0625rem, var(--skeleton) 0.0625rem, var(--skeleton));
background: linear-gradient(
to right,
var(--body),
var(--body) 0.0625rem,
var(--skeleton) 0.0625rem,
var(--skeleton)
);
}
.container {
max-width: 980px;
Expand Down Expand Up @@ -75,7 +87,7 @@ p {
left: 16px;
right: 16px;
bottom: 16px;
background-color: #1A202C;
background-color: #1a202c;
border-radius: 4px;
min-width: 288px;
padding: 1rem;
Expand All @@ -88,6 +100,9 @@ p {
border-radius: 4px;
margin: 0;
}
.Toastify__toast--dark {
background: #323337;
}
@keyframes dot {
50% {
transform: translateX(96px);
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import './index.css';
import App from './App';
import { toast } from 'react-toastify';
import * as serviceWorkerRegistration from './serviceWorkerRegistration';
import reportWebVitals from './reportWebVitals';
import 'react-toastify/dist/ReactToastify.css';

ReactDOM.render(
<React.StrictMode>
Expand Down
59 changes: 31 additions & 28 deletions src/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,50 @@ precacheAndRoute(self.__WB_MANIFEST);
// https://developers.google.com/web/fundamentals/architecture/app-shell
const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$');
registerRoute(
// Return false to exempt requests from being fulfilled by index.html.
({ request, url }) => {
// If this isn't a navigation, skip.
if (request.mode !== 'navigate') {
return false;
} // If this is a URL that starts with /_, skip.
// Return false to exempt requests from being fulfilled by index.html.
({ request, url }) => {
// If this isn't a navigation, skip.
if (request.mode !== 'navigate') {
return false;
} // If this is a URL that starts with /_, skip.

if (url.pathname.startsWith('/_')) {
return false;
} // If this looks like a URL for a resource, because it contains // a file extension, skip.
if (url.pathname.startsWith('/_')) {
return false;
} // If this looks like a URL for a resource, because it contains // a file extension, skip.

if (url.pathname.match(fileExtensionRegexp)) {
return false;
} // Return true to signal that we want to use the handler.
if (url.pathname.match(fileExtensionRegexp)) {
return false;
} // Return true to signal that we want to use the handler.

return true;
},
createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
return true;
},
createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
);

// An example runtime caching route for requests that aren't handled by the
// precache, in this case same-origin .png requests like those from in public/
registerRoute(
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 }),
],
})
// Add in any other file extensions or routing criteria as needed.
({ url }) => url.origin === self.location.origin && url.pathname.endsWith('.png'), // Customize this strategy as needed, e.g., by changing to CacheFirst.
new StaleWhileRevalidate({
cacheName: 'images',
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 50 }),
],
})
);

// This allows the web app to trigger skipWaiting via
// registration.waiting.postMessage({type: 'SKIP_WAITING'})
self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});

// Any other custom service worker logic can go here.
self.addEventListener('install', function (event) {
self.skipWaiting();
});
Loading

0 comments on commit f762474

Please sign in to comment.