From a8f959c6eb8f93b6ed46cde8855e7938a535ff20 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 26 May 2020 11:06:19 -0500 Subject: [PATCH] Show popup notifications for serviceWorker These need more user-friendly handling, but this will suffice for now. --- src/index.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index 3c425745..735019c1 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -10,6 +10,7 @@ import { createEpicMiddleware } from 'redux-observable'; import createSagaMiddleware from 'redux-saga'; import thunkMiddleware from 'redux-thunk'; import './index.scss'; +import * as notification from './actions/notification'; import App from './components/App'; import NotificationStack from './components/NotificationStack'; import rootEpic from './epics'; @@ -50,4 +51,17 @@ ReactDOM.render( // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://bit.ly/CRA-PWA -serviceWorker.register(); +serviceWorker.register({ + onUpdate: () => { + store.dispatch( + notification.add( + 'info', + 'New content is available and will be used when all ' + + 'tabs for this page are closed. See https://bit.ly/CRA-PWA.', + ), + ); + }, + onSuccess: () => { + store.dispatch(notification.add('info', 'Content is cached for offline use.')); + }, +});