27 changed files with 193 additions and 94 deletions
@ -0,0 +1,23 @@ |
|||||||
|
import { ReactNode } from "react"; |
||||||
|
import { Link as LinkRouter } from "react-router-dom"; |
||||||
|
|
||||||
|
export function MwLink(props: { |
||||||
|
children?: ReactNode; |
||||||
|
to?: string; |
||||||
|
url?: string; |
||||||
|
onClick?: () => void; |
||||||
|
}) { |
||||||
|
const isExternal = !!props.url; |
||||||
|
const isInternal = !!props.to; |
||||||
|
const content = ( |
||||||
|
<span className="group mt-1 cursor-pointer font-bold text-type-link hover:text-type-linkHover active:scale-95"> |
||||||
|
{props.children} |
||||||
|
</span> |
||||||
|
); |
||||||
|
|
||||||
|
if (isExternal) return <a href={props.url}>{content}</a>; |
||||||
|
if (isInternal) return <LinkRouter to={props.to ?? ""}>{content}</LinkRouter>; |
||||||
|
return ( |
||||||
|
<span onClick={() => props.onClick && props.onClick()}>{content}</span> |
||||||
|
); |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
import { registerSW } from "virtual:pwa-register"; |
||||||
|
|
||||||
|
const intervalMS = 60 * 60 * 1000; |
||||||
|
|
||||||
|
registerSW({ |
||||||
|
immediate: true, |
||||||
|
onRegisteredSW(swUrl, r) { |
||||||
|
if (!r) return; |
||||||
|
setInterval(async () => { |
||||||
|
if (!(!r.installing && navigator)) return; |
||||||
|
|
||||||
|
if ("connection" in navigator && !navigator.onLine) return; |
||||||
|
|
||||||
|
const resp = await fetch(swUrl, { |
||||||
|
cache: "no-store", |
||||||
|
headers: { |
||||||
|
cache: "no-store", |
||||||
|
"cache-control": "no-cache", |
||||||
|
}, |
||||||
|
}); |
||||||
|
|
||||||
|
if (resp?.status === 200) { |
||||||
|
await r.update(); |
||||||
|
} |
||||||
|
}, intervalMS); |
||||||
|
}, |
||||||
|
}); |
Loading…
Reference in new issue