service worker

This commit is contained in:
cupcakearmy
2019-05-27 20:18:26 +02:00
parent 4b566cce32
commit c299177f2c
4 changed files with 125 additions and 4 deletions

View File

@@ -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 <React.Fragment>
<Head>
<title>{title}</title>
{/* https://www.flaticon.com/packs/zoo-20 */}
<link rel="stylesheet" href="/static/css/spectre.min.css"/>
<link rel="stylesheet" href="/static/css/spectre-exp.min.css"/>
<link rel="stylesheet" href="/static/css/spectre-icons.min.css"/>
@@ -70,12 +82,21 @@ const Layout = ({ children }) => {
</div>
</main>
{!online && <div id="msg-offline" className="bg-dark text-center p-2">Offline</div>}
{/* language=CSS */}
<style jsx>{`
main {
padding: 6em 0;
}
#msg-offline {
position: fixed;
bottom: 0;
left: 0;
width: 100vw;
}
#navbar-container {
position: fixed;
top: 0;