diff --git a/public/service-worker.js b/public/service-worker.js index 3593d27..32463af 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -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) => { diff --git a/src/pages/DashboardPage.jsx b/src/pages/DashboardPage.jsx index 96805ad..cd8948f 100644 --- a/src/pages/DashboardPage.jsx +++ b/src/pages/DashboardPage.jsx @@ -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()} ); -}; +}; \ No newline at end of file