mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-05-24 10:29:11 +00:00

Minor fixes such as setting the start_url to `/editor`. Also add complete offline support by updating configuration. This is especially nice for mobile users. I've had some slight issues running this via `npm run dev`. However, `npm run build && npm run preview` seems to work fine.
35 lines
894 B
JavaScript
35 lines
894 B
JavaScript
import { useRegisterSW } from "virtual:pwa-register/react";
|
|
import { Typography, Toast } from "@douyinfe/semi-ui";
|
|
import { useEffect } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
const { Text } = Typography;
|
|
|
|
export function PwaUpdatePrompt() {
|
|
const { t } = useTranslation();
|
|
const {
|
|
needRefresh: [isRefreshNeeded],
|
|
updateServiceWorker,
|
|
} = useRegisterSW();
|
|
|
|
useEffect(() => {
|
|
if (!isRefreshNeeded) return;
|
|
|
|
Toast.info({
|
|
duration: 0, // indefinite
|
|
content: (
|
|
<div>
|
|
<h5>{t("update_available")}</h5>
|
|
<p className="text-xs">{t("reload_page_to_update")}</p>
|
|
<div className="mt-2">
|
|
<Text link onClick={updateServiceWorker}>
|
|
{t("reload_now")}
|
|
</Text>
|
|
</div>
|
|
</div>
|
|
),
|
|
});
|
|
}, [isRefreshNeeded, updateServiceWorker, t]);
|
|
|
|
return <></>;
|
|
}
|