feat: auto-restore push subscription + bump SW cache v3
This commit is contained in:
parent
5f88b2ca65
commit
a04e8edb6e
|
|
@ -1,8 +1,8 @@
|
|||
const isLocalhost = self.location.hostname === "localhost" || self.location.hostname === "127.0.0.1";
|
||||
|
||||
if (!isLocalhost) {
|
||||
const STATIC_CACHE = "construction-delivery-static-v2";
|
||||
const RUNTIME_CACHE = "construction-delivery-runtime-v2";
|
||||
const STATIC_CACHE = "construction-delivery-static-v3";
|
||||
const RUNTIME_CACHE = "construction-delivery-runtime-v3";
|
||||
const APP_SHELL_URLS = ["/", "/index.html", "/manifest.webmanifest", "/icons/icon-192.svg", "/icons/icon-512.svg"];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { Panel } from "../components/UI/Panel";
|
|||
import { ProductGuidePanel } from "../components/dashboard/ProductGuidePanel";
|
||||
import { useAuth } from "../context/AuthContext";
|
||||
import { useNotifications } from "../hooks/useNotifications";
|
||||
import { usePushNotifications } from "../hooks/usePushNotifications";
|
||||
import { useOrderGroups } from "../hooks/useOrderGroups";
|
||||
import { AppShell } from "../layouts/AppShell";
|
||||
|
||||
|
|
@ -43,6 +44,15 @@ export const DashboardPage = () => {
|
|||
markAllAsRead: markAllNotificationsRead,
|
||||
} = useNotifications(user?.id);
|
||||
|
||||
// Auto-restore push subscription on login
|
||||
const { isSupported, isSubscribed, subscribe } = usePushNotifications(user?.id);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (isSupported && !isSubscribed && user?.id && Notification.permission === "granted") {
|
||||
subscribe();
|
||||
}
|
||||
}, [isSupported, isSubscribed, user?.id, subscribe]);
|
||||
|
||||
const {
|
||||
orderGroups,
|
||||
allOrderGroups,
|
||||
|
|
@ -158,4 +168,4 @@ export const DashboardPage = () => {
|
|||
{renderActiveSection()}
|
||||
</AppShell>
|
||||
);
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue