Skip to content

Commit

Permalink
update pwa functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
arnovanstaden committed Apr 19, 2021
1 parent 2b8b8b9 commit c143a1c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- PWA Stuff -->
<link rel="apple-touch-icon" href="%PUBLIC_URL%/images/logos/logo192.png" />
<!-- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> -->
<link rel="manifest" href="/manifest.json" />
</head>

<body>
Expand Down
7 changes: 7 additions & 0 deletions public/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
self.addEventListener('install', function (event) {
self.skipWaiting();
});

self.addEventListener('fetch', function (event) {
event.respondWith(fetch(event.request));
});
6 changes: 5 additions & 1 deletion src/components/App/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useEffect } from "react";
import { registerServiceWorker } from "../../utils/pwa";

// Components
import AppWrap from "./AppWrap";

function App() {

useEffect(() => {
registerServiceWorker();
}, [])
return (
<AppWrap>
<div className="App">
Expand Down
14 changes: 14 additions & 0 deletions src/utils/pwa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const registerServiceWorker = () => {

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then(function (registration) {
registration.addEventListener('updatefound', function () {
let installingWorker = registration.installing;
});
})
.catch(function (error) {
console.log(error);
});
}
}

1 comment on commit c143a1c

@vercel
Copy link

@vercel vercel bot commented on c143a1c Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.