-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SW update available message implemented
- Loading branch information
1 parent
f6c3a02
commit c94b35c
Showing
6 changed files
with
48 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import * as serviceWorker from './serviceWorker'; | ||
import Alert from 'react-bootstrap/Alert'; | ||
import { ExclamationTriangle } from 'react-bootstrap-icons'; | ||
|
||
|
||
export const ServiceWorkerWrapper = () => { | ||
const [showReload, setShowReload] = useState(false); | ||
const [waitingWorker, setWaitingWorker] = useState<ServiceWorker | null>(null); | ||
|
||
const onSWUpdate = (registration: ServiceWorkerRegistration) => { | ||
setShowReload(true); | ||
setWaitingWorker(registration.waiting); | ||
}; | ||
|
||
useEffect(() => { | ||
serviceWorker.register({ onUpdate: onSWUpdate }); | ||
}, []); | ||
|
||
const reloadPage = () => { | ||
waitingWorker?.postMessage({ type: 'SKIP_WAITING' }); | ||
setShowReload(false); | ||
window.location.reload(true); | ||
} | ||
|
||
return ( | ||
<Alert | ||
show={showReload} | ||
variant="primary" | ||
className="alert-global"> | ||
<ExclamationTriangle /> | ||
A new version of TacoTab is available! <Alert.Link onClick={reloadPage}>Click to reload.</Alert.Link> | ||
</Alert> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters