feat: auto-restore push subscription + bump SW cache v3

This commit is contained in:
root 2026-05-22 11:18:58 +00:00
parent 5f88b2ca65
commit a04e8edb6e
2 changed files with 13 additions and 3 deletions

View File

@ -1,8 +1,8 @@
const isLocalhost = self.location.hostname === "localhost" || self.location.hostname === "127.0.0.1"; const isLocalhost = self.location.hostname === "localhost" || self.location.hostname === "127.0.0.1";
if (!isLocalhost) { if (!isLocalhost) {
const STATIC_CACHE = "construction-delivery-static-v2"; const STATIC_CACHE = "construction-delivery-static-v3";
const RUNTIME_CACHE = "construction-delivery-runtime-v2"; const RUNTIME_CACHE = "construction-delivery-runtime-v3";
const APP_SHELL_URLS = ["/", "/index.html", "/manifest.webmanifest", "/icons/icon-192.svg", "/icons/icon-512.svg"]; const APP_SHELL_URLS = ["/", "/index.html", "/manifest.webmanifest", "/icons/icon-192.svg", "/icons/icon-512.svg"];
self.addEventListener("install", (event) => { self.addEventListener("install", (event) => {

View File

@ -7,6 +7,7 @@ import { Panel } from "../components/UI/Panel";
import { ProductGuidePanel } from "../components/dashboard/ProductGuidePanel"; import { ProductGuidePanel } from "../components/dashboard/ProductGuidePanel";
import { useAuth } from "../context/AuthContext"; import { useAuth } from "../context/AuthContext";
import { useNotifications } from "../hooks/useNotifications"; import { useNotifications } from "../hooks/useNotifications";
import { usePushNotifications } from "../hooks/usePushNotifications";
import { useOrderGroups } from "../hooks/useOrderGroups"; import { useOrderGroups } from "../hooks/useOrderGroups";
import { AppShell } from "../layouts/AppShell"; import { AppShell } from "../layouts/AppShell";
@ -43,6 +44,15 @@ export const DashboardPage = () => {
markAllAsRead: markAllNotificationsRead, markAllAsRead: markAllNotificationsRead,
} = useNotifications(user?.id); } = 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 { const {
orderGroups, orderGroups,
allOrderGroups, allOrderGroups,
@ -158,4 +168,4 @@ export const DashboardPage = () => {
{renderActiveSection()} {renderActiveSection()}
</AppShell> </AppShell>
); );
}; };