forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

network-status-banner.tsx50 lines, 1.8 KiBHistoryRawDownload
1import { Show, createSignal, onCleanup, onMount } from "solid-js";
2import { Button } from "@/components/ui/button";
3import { IconWifiOff } from "@/components/ui/icons";
4import { useT } from "@/stores/preferences-context";
5
6/**
7 * Reflects the browser's own online/offline signal — nothing invented, no
8 * queued-write promise the app can't keep. Sits above the routed content so
9 * a lost connection is visible everywhere, not just on the page that
10 * happened to trigger a fetch.
11 */
12export function NetworkStatusBanner() {
13 const t = useT();
14 const [online, setOnline] = createSignal(true);
15
16 onMount(() => {
17 setOnline(navigator.onLine);
18 const handleOnline = () => setOnline(true);
19 const handleOffline = () => setOnline(false);
20 window.addEventListener("online", handleOnline);
21 window.addEventListener("offline", handleOffline);
22 onCleanup(() => {
23 window.removeEventListener("online", handleOnline);
24 window.removeEventListener("offline", handleOffline);
25 });
26 });
27
28 return (
29 <Show when={!online()}>
30 <div class="flex flex-wrap items-center justify-between gap-3 border-b border-warning/30 bg-warning/10 px-4 py-2.5 text-sm sm:px-6 lg:px-4">
31 <span class="flex min-w-0 items-center gap-2 text-text-strong">
32 <IconWifiOff class="h-4 w-4 shrink-0 text-warning-text" />
33 <span class="min-w-0">
34 <span class="font-semibold">{t("network.offlineTitle")}</span>
35 <span class="hidden text-text-subtle sm:inline"> — {t("network.offlineDescription")}</span>
36 </span>
37 </span>
38 <Button
39 type="button"
40 size="sm"
41 variant="outline"
42 class="h-[26px] shrink-0 rounded-lg"
43 onClick={() => setOnline(navigator.onLine)}
44 >
45 {t("network.reconnect")}
46 </Button>
47 </div>
48 </Show>
49 );
50}