From 2c2515abba5fef6f19955d1d82ea61b70a3a554c Mon Sep 17 00:00:00 2001 From: zv Date: Sat, 4 Jul 2026 20:53:13 +0200 Subject: [PATCH] fix: show offline status in pwa --- components/layout/app-shell.tsx | 23 ++++++++++++++++++++++- lib/i18n.tsx | 2 ++ public/sw.js | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/components/layout/app-shell.tsx b/components/layout/app-shell.tsx index 775d1c4..fc32072 100644 --- a/components/layout/app-shell.tsx +++ b/components/layout/app-shell.tsx @@ -2,7 +2,8 @@ import Link from "next/link"; import { usePathname } from "next/navigation"; -import { CloudSun, Droplets, Settings, TriangleAlert } from "lucide-react"; +import { useEffect, useState } from "react"; +import { CloudSun, Droplets, Settings, TriangleAlert, WifiOff } from "lucide-react"; import type { LucideIcon } from "lucide-react"; import { isAppNavItemVisible } from "@/lib/app-sections"; import { NAV_ITEMS } from "@/lib/constants"; @@ -23,6 +24,18 @@ export function AppShell({ children }: { children: React.ReactNode }) { const { t } = useI18n(); const appSections = useWeatherStore((state) => state.appSections); const visibleNavItems = NAV_ITEMS.filter((item) => isAppNavItemVisible(item.href, appSections)); + const [isOffline, setIsOffline] = useState(false); + + useEffect(() => { + const updateConnectionStatus = () => setIsOffline(!navigator.onLine); + updateConnectionStatus(); + window.addEventListener("online", updateConnectionStatus); + window.addEventListener("offline", updateConnectionStatus); + return () => { + window.removeEventListener("online", updateConnectionStatus); + window.removeEventListener("offline", updateConnectionStatus); + }; + }, []); return (
@@ -56,6 +69,14 @@ export function AppShell({ children }: { children: React.ReactNode }) {
+ {isOffline && ( +
+
+
+
+ )}
{children}