feat(ui): complete phase 4 Poyraz UI foundation
This commit is contained in:
@@ -1,26 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { WifiOff } from "lucide-react";
|
||||
|
||||
export function OfflineIndicator() {
|
||||
const [isOnline, setIsOnline] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Sadece client-side'da çalışır
|
||||
setIsOnline(navigator.onLine);
|
||||
|
||||
const handleOnline = () => setIsOnline(true);
|
||||
const handleOffline = () => setIsOnline(false);
|
||||
|
||||
window.addEventListener("online", handleOnline);
|
||||
window.addEventListener("offline", handleOffline);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("online", handleOnline);
|
||||
window.removeEventListener("offline", handleOffline);
|
||||
};
|
||||
}, []);
|
||||
const isOnline = useSyncExternalStore(
|
||||
(onStoreChange) => {
|
||||
window.addEventListener("online", onStoreChange);
|
||||
window.addEventListener("offline", onStoreChange);
|
||||
return () => {
|
||||
window.removeEventListener("online", onStoreChange);
|
||||
window.removeEventListener("offline", onStoreChange);
|
||||
};
|
||||
},
|
||||
() => navigator.onLine,
|
||||
() => true,
|
||||
);
|
||||
|
||||
if (isOnline) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user