Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Routes, Route, NavLink, Navigate, useLocation } from 'react-router-dom'
import { userSession, authenticate, disconnect } from './utils/stacks';
import Header from './components/Header';
import SendTip from './components/SendTip';
import OfflineBanner from './components/OfflineBanner';
import { AnimatedHero } from './components/ui/animated-hero';
import { ToastContainer, useToast } from './components/ui/toast';

Expand Down Expand Up @@ -59,6 +60,7 @@ function App() {

return (
<div className="min-h-screen bg-[#F8FAFC] dark:bg-gray-950 transition-colors">
<OfflineBanner />
<Header userData={userData} onAuth={handleAuth} authLoading={authLoading} />

<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/components/OfflineBanner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useOnlineStatus } from '../hooks/useOnlineStatus';

export default function OfflineBanner() {
const isOnline = useOnlineStatus();

if (isOnline) return null;

return (
<div className="fixed top-0 inset-x-0 z-50 bg-red-600 text-white text-center py-2 px-4 text-sm font-medium shadow-lg" role="alert">
<div className="flex items-center justify-center gap-2">
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M18.364 5.636a9 9 0 010 12.728M5.636 5.636a9 9 0 000 12.728M12 9v4m0 4h.01" />
</svg>
<span>You are offline. Some features may not work until your connection is restored.</span>
</div>
</div>
);
}
20 changes: 20 additions & 0 deletions frontend/src/hooks/useOnlineStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useState, useEffect } from 'react';

export function useOnlineStatus() {
const [isOnline, setIsOnline] = useState(navigator.onLine);

useEffect(() => {
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);
};
}, []);

return isOnline;
}
Loading