File size: 5,093 Bytes
d02c2a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | 'use client';
import { useEffect } from 'react';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { Home, Settings, BrainCircuit, Images, Plus, X } from 'lucide-react';
import { FaXTwitter, FaDiscord, FaYoutube } from 'react-icons/fa6';
import { createGlobalState } from 'react-global-hooks';
import ThemeToggle from './ThemeToggle';
import ThemeLogo from './ThemeLogo';
import ActiveJobWidget from './ActiveJobWidget';
export const mobileSidebarState = createGlobalState<boolean>(false);
const Sidebar = () => {
const [isMobileOpen, setIsMobileOpen] = mobileSidebarState.use();
const pathname = usePathname();
// Close mobile menu on route change
useEffect(() => {
setIsMobileOpen(false);
}, [pathname]);
// Lock body scroll when mobile menu open
useEffect(() => {
if (isMobileOpen) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
return () => {
document.body.style.overflow = '';
};
}, [isMobileOpen]);
const navigation = [
{ name: 'Dashboard', href: '/dashboard', icon: Home },
{ name: 'New Job', href: '/jobs/new', icon: Plus },
{ name: 'Queue', href: '/jobs', icon: BrainCircuit },
{ name: 'Datasets', href: '/datasets', icon: Images },
{ name: 'Settings', href: '/settings', icon: Settings },
];
const socialsBoxClass =
'flex flex-col items-center justify-center p-1 hover:bg-gray-800 rounded-lg transition-colors';
const socialIconClass = 'w-5 h-5 text-gray-400 hover:text-white';
const sidebarContent = (
<>
<div className="px-4 py-3 flex items-center justify-between">
<h1 className="text-l">
<ThemeLogo />
<span className="font-bold uppercase">Ostris</span>
<span className="ml-2 uppercase text-gray-300">AI-Toolkit</span>
</h1>
<button
onClick={() => setIsMobileOpen(false)}
className="md:hidden text-gray-400 hover:text-white p-1"
aria-label="Close menu"
>
<X className="w-5 h-5" />
</button>
</div>
<nav className="flex-1">
<ul className="px-2 py-4 space-y-2">
{navigation.map(item => (
<li key={item.name}>
<Link
href={item.href}
className="flex items-center px-4 py-2 text-gray-300 hover:bg-gray-800 rounded-lg transition-colors"
>
<item.icon className="w-5 h-5 mr-3" />
{item.name}
</Link>
</li>
))}
</ul>
</nav>
<ActiveJobWidget />
<a
href="https://ostris.com/support"
target="_blank"
rel="noreferrer"
className="group flex items-center space-x-2 px-4 py-3 text-gray-400 hover:text-gray-200 transition-colors"
>
<svg
height="20"
width="20"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
style={{ overflow: 'visible' }}
>
<path
className="animate-heartbeat"
d="m7 3c-1.5355 0-3.0784 0.5-4.25 1.7-2.3431 2.4-2.2788 6.1 0 8.5l9.25 9.8 9.25-9.8c2.279-2.4 2.343-6.1 0-8.5-2.343-2.3-6.157-2.3-8.5 0l-0.75 0.8-0.75-0.8c-1.172-1.2-2.7145-1.7-4.25-1.7z"
fill="#c0392b"
/>
</svg>
<span className="uppercase text-sm font-medium tracking-wide">Support AI-Toolkit</span>
</a>
{/* Social links grid */}
<div className="px-1 py-1 border-t border-gray-800">
<div className="grid grid-cols-4 gap-4">
<a href="https://discord.gg/VXmU2f5WEU" target="_blank" rel="noreferrer" className={socialsBoxClass}>
<FaDiscord className={socialIconClass} />
</a>
<a href="https://www.youtube.com/@ostrisai" target="_blank" rel="noreferrer" className={socialsBoxClass}>
<FaYoutube className={socialIconClass} />
</a>
<a href="https://x.com/ostrisai" target="_blank" rel="noreferrer" className={socialsBoxClass}>
<FaXTwitter className={socialIconClass} />
</a>
<ThemeToggle />
</div>
</div>
</>
);
return (
<>
{/* Desktop sidebar - always visible on md+ */}
<div className="hidden md:flex flex-col w-59 bg-gray-900 text-gray-100">{sidebarContent}</div>
{/* Mobile overlay sidebar */}
<div
className={`md:hidden fixed inset-0 bg-black/60 z-40 transition-opacity duration-300 ease-in-out ${
isMobileOpen ? 'opacity-100 pointer-events-auto' : 'opacity-0 pointer-events-none'
}`}
onClick={() => setIsMobileOpen(false)}
aria-hidden="true"
/>
<div
className={`md:hidden fixed top-0 left-0 bottom-0 w-64 max-w-[85vw] bg-gray-900 text-gray-100 z-50 flex flex-col shadow-xl transform transition-transform duration-300 ease-in-out ${
isMobileOpen ? 'translate-x-0' : '-translate-x-full'
}`}
>
{sidebarContent}
</div>
</>
);
};
export default Sidebar;
|