1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-22 17:23:22 +01:00

service worker update notification

This commit is contained in:
Matthias Kretschmann 2021-09-19 16:22:05 +02:00
parent 9bc24f7a72
commit 3f55d2dda8
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 50 additions and 7 deletions

View File

@ -27,6 +27,9 @@
- React - React
- Ethereum - Ethereum
- Web3 - Web3
- 3Box
- Polygon
- Binance Smart Chain
- title: 'Ocean Protocol - IPFS Integration' - title: 'Ocean Protocol - IPFS Integration'
slug: '/oceanprotocol-ipfs/' slug: '/oceanprotocol-ipfs/'

View File

@ -2,6 +2,7 @@ import wrapPageElementWithLayout from './src/helpers/wrapPageElement'
// Global styles // Global styles
import './src/styles/global.css' import './src/styles/global.css'
import './src/styles/_toast.css'
// IntersectionObserver polyfill for gatsby-image (Safari, IE) // IntersectionObserver polyfill for gatsby-image (Safari, IE)
if (typeof window !== 'undefined' && !window.IntersectionObserver) { if (typeof window !== 'undefined' && !window.IntersectionObserver) {
@ -27,11 +28,9 @@ export const shouldUpdateScroll = ({
// Display a message when a service worker updates // Display a message when a service worker updates
// https://www.gatsbyjs.org/docs/add-offline-support-with-a-service-worker/#displaying-a-message-when-a-service-worker-updates // https://www.gatsbyjs.org/docs/add-offline-support-with-a-service-worker/#displaying-a-message-when-a-service-worker-updates
export const onServiceWorkerUpdateReady = () => { export const onServiceWorkerUpdateReady = () => {
const answer = window.confirm( const div = document.createElement('div')
'This application has been updated. ' + div.id = 'toast'
'Reload to display the latest version?' div.classList.add('alert', 'alert-info')
) div.innerHTML = `<button onClick="window.location.reload()">Updates are available. <span>Click to Reload</span>.</button>`
if (answer === true) { document.body.append(div)
window.location.reload()
}
} }

41
src/styles/_toast.css Normal file
View File

@ -0,0 +1,41 @@
#toast {
position: sticky;
z-index: 10;
bottom: var(--spacer);
left: calc(var(--spacer) / 2);
right: calc(var(--spacer) / 2);
margin: 0 auto;
width: fit-content;
font-size: var(--font-size-small);
padding: 0;
animation: animation 0.2s ease-out backwards;
background: var(--body-background-color);
border-radius: var(--border-radius);
border: var(--stroke-width) solid transparent;
box-shadow: var(--box-shadow);
}
#toast button {
font-family: inherit;
font-weight: inherit;
font-size: inherit;
color: inherit;
background: inherit;
border: none;
cursor: pointer;
margin: 0;
padding: calc(var(--spacer) / 3) var(--spacer);
}
#toast button span {
color: var(--link-color);
}
@keyframes animation {
0% {
transform: translateY(-3rem);
}
100% {
transform: translateY(0);
}
}