mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-06 17:11:55 +00:00
Add PWA update indicator.
This commit is contained in:
25
src/components/common/UpdateIndicator.tsx
Normal file
25
src/components/common/UpdateIndicator.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { updateSW } from "../../main";
|
||||
import IconButton from "../ui/IconButton";
|
||||
import { ThemeContext } from "../../context/Theme";
|
||||
import { Download } from "@styled-icons/boxicons-regular";
|
||||
import { internalSubscribe } from "../../lib/eventEmitter";
|
||||
import { useContext, useEffect, useState } from "preact/hooks";
|
||||
|
||||
var pendingUpdate = false;
|
||||
|
||||
export default function UpdateIndicator() {
|
||||
const [ pending, setPending ] = useState(pendingUpdate);
|
||||
|
||||
useEffect(() => {
|
||||
return internalSubscribe('PWA', 'update', () => setPending(true));
|
||||
});
|
||||
|
||||
if (!pending) return;
|
||||
const theme = useContext(ThemeContext);
|
||||
|
||||
return (
|
||||
<IconButton onClick={() => updateSW(true)}>
|
||||
<Download size={22} color={theme.success} />
|
||||
</IconButton>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user