<ServiceWorkerNotifications /> allow passing of props for messages and disabling
This commit is contained in:
parent
823f801af5
commit
3ac7816d8f
2 changed files with 18 additions and 4 deletions
|
|
@ -38,7 +38,9 @@ class App extends Component {
|
|||
<Router>
|
||||
<div>
|
||||
<ScrollToTop />
|
||||
<ServiceWorkerNotifications />
|
||||
<ServiceWorkerNotifications
|
||||
readyMessage='This message is displayed when the SW is registered'
|
||||
/>
|
||||
<GithubCorner url='https://github.com/Jinksi/hyperstatic' />
|
||||
<Helmet titleTemplate={`${siteTitle} | %s`} />
|
||||
<Nav>
|
||||
|
|
|
|||
|
|
@ -37,6 +37,15 @@ const CloseButton = styled.button.attrs({
|
|||
`
|
||||
|
||||
export default class ServiceWorkerNotifications extends Component {
|
||||
static defaultProps = {
|
||||
readyMessage: 'This site is cached for offline use!',
|
||||
updatedMessage: 'New content is available please refresh.',
|
||||
offlineMessage: 'You are now offline, browsing from cache.',
|
||||
ready: true,
|
||||
updated: true,
|
||||
offline: true
|
||||
}
|
||||
|
||||
state = {
|
||||
message: null
|
||||
}
|
||||
|
|
@ -54,15 +63,18 @@ export default class ServiceWorkerNotifications extends Component {
|
|||
}
|
||||
|
||||
handleReady = () => {
|
||||
this.setState({ message: 'This site is cached for offline use!' })
|
||||
if (!this.props.ready) return
|
||||
this.setState({ message: this.props.readyMessage })
|
||||
}
|
||||
|
||||
handleUpdated = () => {
|
||||
this.setState({ message: 'New content is available please refresh.' })
|
||||
if (!this.props.updated) return
|
||||
this.setState({ message: this.props.updatedMessage })
|
||||
}
|
||||
|
||||
handleOffline = () => {
|
||||
this.setState({ message: null })
|
||||
if (!this.props.offline) return
|
||||
this.setState({ message: this.props.offlineMessage })
|
||||
}
|
||||
|
||||
handleDismiss = () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue