diff --git a/www/components/layout.jsx b/www/components/layout.jsx index 8b76f55..82587f6 100755 --- a/www/components/layout.jsx +++ b/www/components/layout.jsx @@ -1,19 +1,31 @@ -import React from 'react' +import React, { useEffect } from 'react' import Head from 'next/head' import Link from 'next/link' import { logout } from '../utils/auth' import { getRandomSlogan } from '../utils/misc' +import { editableWhenOnline } from '../utils/hooks' const Layout = ({ children }) => { const title = getRandomSlogan() + const online = typeof window !== 'undefined' + ? editableWhenOnline() + : true + + useEffect(() => { + if (window && 'navigator' in window && 'serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('/sw.js') + }) + } + }, []) + return {title} - {/* https://www.flaticon.com/packs/zoo-20 */} @@ -70,12 +82,21 @@ const Layout = ({ children }) => { + {!online &&
Offline
} + {/* language=CSS */}