tahamajs/IE / Projects /front /src /components /common /OfflineBanner.tsx
tahamajs's picture
download
raw
3.72 kB
// src/components/common/OfflineBanner.tsx
import { motion, AnimatePresence } from "framer-motion";
import { WifiOff, RefreshCw, Save, Cloud, Wifi, AlertTriangle, CheckCircle, X } from "lucide-react";
import { useOffline } from "@/context/OfflineContext";
import { useState } from "react";
export function OfflineBanner() {
const { isOnline, wasOffline, queueLength, retryFailedActions, clearQueue } = useOffline();
const [isDismissed, setIsDismissed] = useState(false);
if ((isOnline && !wasOffline) || isDismissed) return null;
const handleDismiss = () => setIsDismissed(true);
const handleRetry = () => {
retryFailedActions();
setIsDismissed(true);
};
return (
<AnimatePresence>
<motion.div
initial={{ y: -100, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
exit={{ y: -100, opacity: 0 }}
transition={{ type: "spring", damping: 20 }}
className="fixed top-16 left-1/2 -translate-x-1/2 z-50 w-full max-w-md px-4"
>
<div className={`relative rounded-2xl p-4 shadow-xl backdrop-blur-md ${
isOnline
? "bg-green-500/10 border border-green-500/30"
: "bg-yellow-500/10 border border-yellow-500/30"
}`}>
<button
onClick={handleDismiss}
className="absolute top-2 right-2 rounded-full p-1 hover:bg-white/10 transition"
>
<X className="h-4 w-4 text-gray-400" />
</button>
<div className="flex items-start gap-3 pr-6">
<div className={`rounded-full p-2 ${
isOnline
? "bg-green-500/20"
: "bg-yellow-500/20"
}`}>
{isOnline ? (
<Wifi className="h-5 w-5 text-green-500" />
) : (
<WifiOff className="h-5 w-5 text-yellow-500" />
)}
</div>
<div className="flex-1">
<p className={`text-sm font-semibold ${
isOnline ? "text-green-600 dark:text-green-400" : "text-yellow-600 dark:text-yellow-400"
}`}>
{isOnline ? "Connection restored" : "You're offline"}
</p>
<p className="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
{isOnline
? queueLength > 0
? `Syncing ${queueLength} pending ${queueLength === 1 ? "item" : "items"}...`
: "Your connection has been restored."
: queueLength > 0
? `${queueLength} pending ${queueLength === 1 ? "change" : "changes"} will sync when back online.`
: "Some features may be unavailable until your connection returns."
}
</p>
</div>
{isOnline && queueLength > 0 && (
<button
onClick={handleRetry}
className="flex items-center gap-1 rounded-lg bg-green-500/20 px-3 py-1.5 text-xs font-medium text-green-600 dark:text-green-400 hover:bg-green-500/30 transition"
>
<RefreshCw className="h-3 w-3" />
Sync ({queueLength})
</button>
)}
</div>
{/* Progress bar for sync */}
{isOnline && queueLength > 0 && (
<motion.div
initial={{ width: 0 }}
animate={{ width: "100%" }}
transition={{ duration: 2, repeat: Infinity }}
className="absolute bottom-0 left-0 h-0.5 bg-gradient-to-r from-green-500 to-emerald-500 rounded-full"
/>
)}
</div>
</motion.div>
</AnimatePresence>
);
}

Xet Storage Details

Size:
3.72 kB
·
Xet hash:
d003fd2536c54c33020bc7b47cec1ecdb6f3cff1167c9e123c6d6e6e5eccbdfd

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.