All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 1m6s
The app was crashing with "useTheme must be used within ThemeProvider" error during server-side rendering. Changes: - Created AppLayout client component to wrap Navbar - Modified useTheme hook to return default values during SSR instead of throwing an error - Updated Navbar to safely handle theme context - Moved Navbar rendering into client-side only AppLayout This fixes the SSR hydration mismatch and allows the app to render correctly on both server and client. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useEffect } from 'react';
|
|
import Link from 'next/link';
|
|
import { usePathname } from 'next/navigation';
|
|
import { Moon, Sun, Activity } from 'lucide-react';
|
|
import { useTheme } from '@/components/providers/ThemeProvider';
|
|
import { Button } from '@/components/ui/button';
|
|
import { cn } from '@/lib/utils/cn';
|
|
|
|
const navItems = [
|
|
{ href: '/', label: 'Dashboard' },
|
|
{ href: '/processes', label: 'Processes' },
|
|
{ href: '/groups', label: 'Groups' },
|
|
{ href: '/logs', label: 'Logs' },
|
|
{ href: '/config', label: 'Configuration' },
|
|
];
|
|
|
|
export function Navbar() {
|
|
const pathname = usePathname();
|
|
const [mounted, setMounted] = useState(false);
|
|
const themeContext = useTheme();
|
|
|
|
useEffect(() => {
|
|
setMounted(true);
|
|
}, []);
|
|
|
|
const toggleTheme = () => {
|
|
if (themeContext) {
|
|
themeContext.setTheme(themeContext.resolvedTheme === 'dark' ? 'light' : 'dark');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<nav className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
|
<div className="container flex h-16 items-center px-4">
|
|
{/* Logo */}
|
|
<Link href="/" className="flex items-center gap-2 mr-8">
|
|
<Activity className="h-6 w-6 text-primary" />
|
|
<span className="font-bold text-xl bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
|
Supervisor
|
|
</span>
|
|
</Link>
|
|
|
|
{/* Navigation Links */}
|
|
<div className="flex gap-1 flex-1">
|
|
{navItems.map((item) => (
|
|
<Link key={item.href} href={item.href}>
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className={cn(
|
|
'transition-colors',
|
|
pathname === item.href && 'bg-accent text-accent-foreground'
|
|
)}
|
|
>
|
|
{item.label}
|
|
</Button>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
|
|
{/* Theme Toggle */}
|
|
{mounted && themeContext && (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={toggleTheme}
|
|
aria-label="Toggle theme"
|
|
>
|
|
{themeContext.resolvedTheme === 'dark' ? (
|
|
<Sun className="h-5 w-5" />
|
|
) : (
|
|
<Moon className="h-5 w-5" />
|
|
)}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</nav>
|
|
);
|
|
}
|