feat: implement local caching for vCon data

Persist clients, storage stats, and file lists in local cache to improve initial load performance. Added breadcrumb navigation to the AdminPageHeader.
This commit is contained in:
Team Dark Devil committed 2026-11-16 23:10:44 +06:00
1 parent b42029f67d
commit 1a1c19d7bb
25 files changed
+892 -342

No files matched your search

+16 -2
View File
@@ -1,3 +1,4 @@
import Link from 'next/link';
import React from 'react';
interface AdminPageHeaderProps {
@@ -7,8 +8,21 @@ interface AdminPageHeaderProps {
export function AdminPageHeader({ title, actions }: AdminPageHeaderProps) {
return (
<header className="mb-3 flex flex-wrap items-center justify-between gap-2">
<h1 className="text-[14px] font-medium tracking-tight text-[var(--text)]">{title}</h1>
<header className="mb-3 flex min-h-8 flex-wrap items-center justify-between gap-2 border-b border-[var(--border)] pb-2.5">
<div className="flex min-w-0 items-center gap-1.5">
<Link
href="/vcon/dashboard"
className="text-[11.5px] text-[var(--text-faint)] hover:text-[var(--text-muted)]"
>
Console
</Link>
<span className="text-[11px] text-[var(--border-strong)]" aria-hidden="true">
/
</span>
<h1 className="truncate text-[13.5px] font-medium tracking-tight text-[var(--text)]">
{title}
</h1>
</div>
{actions && <div className="flex items-center gap-1.5">{actions}</div>}
</header>
);
+30 -25
View File
@@ -1,6 +1,5 @@
'use client';
import { cn } from '@/lib/utils';
import React, { useState } from 'react';
import { Footer } from './Footer';
import { Navbar } from './Navbar';
@@ -17,32 +16,38 @@ export const MainLayout: React.FC<MainLayoutProps> = ({
}) => {
const [sidebarOpen, setSidebarOpen] = useState(false);
if (showSidebar) {
return (
<div className="min-h-dvh bg-[var(--bg-main)] text-[var(--text)] antialiased md:grid md:grid-cols-[184px_1fr]">
<Sidebar
isOpen={sidebarOpen}
onClose={() => setSidebarOpen(false)}
/>
<div className="flex min-h-dvh min-w-0 flex-col">
<Navbar
showSidebarToggle={true}
onToggleSidebar={() => setSidebarOpen((prev) => !prev)}
/>
<main className="flex flex-1 min-w-0 flex-col">
<div className="w-full max-w-[var(--console-width)] flex-1 px-3.5 py-3 sm:px-5 sm:py-3.5">
{children}
</div>
<Footer isAdmin={true} />
</main>
</div>
</div>
);
}
return (
<div className="min-h-dvh flex flex-col bg-[var(--bg-main)] text-[var(--text)] antialiased">
<Navbar
showSidebarToggle={showSidebar}
onToggleSidebar={() => setSidebarOpen((prev) => !prev)}
/>
<div className="flex-1 flex min-h-0 min-w-0 overflow-hidden">
{showSidebar && (
<Sidebar
isOpen={sidebarOpen}
onClose={() => setSidebarOpen(false)}
/>
)}
<main className="flex-1 min-h-0 overflow-y-auto flex flex-col min-w-0">
<div className={cn(
'flex-1 min-w-0 w-full mx-auto',
showSidebar
? 'max-w-[var(--console-width)] px-3.5 py-3 sm:px-5 sm:py-4'
: 'max-w-[var(--container-width)] px-6 py-0'
)}>
{children}
</div>
<Footer isAdmin={showSidebar} />
</main>
</div>
<Navbar showSidebarToggle={false} />
<main className="flex-1 flex flex-col min-w-0">
<div className="flex-1 min-w-0 w-full mx-auto max-w-[var(--container-width)] px-6 py-0">
{children}
</div>
<Footer isAdmin={false} />
</main>
</div>
);
};
+47 -49
View File
@@ -10,6 +10,18 @@ interface NavbarProps {
showSidebarToggle?: boolean;
}
const VCON_LABELS: Record<string, string> = {
'/vcon/dashboard': 'Dashboard',
'/vcon/data': 'Events',
'/vcon/clients': 'Clients',
'/vcon/export': 'Export',
'/vcon/storage': 'Storage',
'/vcon/sdk': 'Python SDK',
'/vcon/simulator': 'Simulator',
'/vcon/profile': 'Profile',
'/vcon/settings': 'Settings',
};
export const Navbar: React.FC<NavbarProps> = ({
onToggleSidebar,
showSidebarToggle = false,
@@ -34,24 +46,44 @@ export const Navbar: React.FC<NavbarProps> = ({
};
const isVcon = pathname?.startsWith('/vcon');
const currentSectionLabel = (pathname && VCON_LABELS[pathname]) || 'Console';
return (
<header className="h-11 shrink-0 bg-[var(--bg-activity)] border-b border-[var(--border)] px-3.5 sm:px-5 flex items-center justify-between gap-4 z-40 select-none">
{/* Left: Mobile hamburger + Brand */}
<div className="flex items-center gap-2.5 min-w-0">
{showSidebarToggle && (
if (showSidebarToggle && isVcon) {
return (
<header className="sticky top-0 z-30 flex h-10 shrink-0 items-center justify-between gap-3 border-b border-[var(--border)] bg-[var(--surface)] px-3.5 select-none md:hidden">
<div className="flex min-w-0 items-center gap-2">
<Button
type="button"
variant="icon"
size="icon"
icon="Menu"
onClick={onToggleSidebar}
className="lg:hidden h-7 w-7 shrink-0 border border-[var(--border)] bg-[var(--bg-elevated)]"
className="h-6.5 w-6.5 shrink-0 border border-[var(--border)] bg-[var(--surface-2)]"
aria-label="Toggle Navigation"
title="Toggle Navigation"
/>
)}
<span className="truncate text-[12px] font-medium text-[var(--text)]">
{currentSectionLabel}
</span>
</div>
<Button
type="button"
variant="icon"
size="icon"
icon={theme === 'dark' ? 'Sun' : 'Moon'}
onClick={toggleTheme}
aria-label="Toggle Theme"
title="Toggle Theme"
className="h-6.5 w-6.5 border border-[var(--border)] bg-[var(--surface-2)]"
/>
</header>
);
}
return (
<header className="h-11 shrink-0 bg-[var(--bg-activity)] border-b border-[var(--border)] px-3.5 sm:px-5 flex items-center justify-between gap-4 z-40 select-none">
<div className="flex items-center gap-2.5 min-w-0">
<Link href="/" className="flex items-center gap-1.5 min-w-0 text-[13px] font-medium whitespace-nowrap shrink-0">
<span className="grid h-3.5 w-3.5 shrink-0 place-items-center bg-[var(--accent)]">
<span className="h-1.5 w-1.5 bg-[var(--bg)]" />
@@ -62,44 +94,12 @@ export const Navbar: React.FC<NavbarProps> = ({
</Link>
</div>
{/* Middle: Links */}
<nav className="hidden sm:flex items-center gap-5 text-[12px]">
{isVcon ? (
<>
<Link href="/" className="text-[var(--text-muted)] hover:text-[var(--text)] whitespace-nowrap shrink-0">
Overview
</Link>
<Link
href="/vcon/dashboard"
className={`px-2 py-1.5 transition-colors border-b-2 whitespace-nowrap shrink-0 ${
pathname !== '/vcon/export'
? 'border-[var(--accent)] text-[var(--text)] font-medium'
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'
}`}
>
Console
</Link>
<Link
href="/vcon/export"
className={`px-2 py-1.5 transition-colors border-b-2 whitespace-nowrap shrink-0 ${
pathname === '/vcon/export'
? 'border-[var(--accent)] text-[var(--text)] font-medium'
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'
}`}
>
Export
</Link>
</>
) : (
<>
<Link href="#features" className="text-[var(--text-muted)] hover:text-[var(--text)] whitespace-nowrap shrink-0">Features</Link>
<Link href="#sdk" className="text-[var(--text-muted)] hover:text-[var(--text)] whitespace-nowrap shrink-0">SDK</Link>
<Link href="#about" className="text-[var(--text-muted)] hover:text-[var(--text)] whitespace-nowrap shrink-0">About</Link>
</>
)}
<Link href="#features" className="text-[var(--text-muted)] hover:text-[var(--text)] whitespace-nowrap shrink-0">Features</Link>
<Link href="#sdk" className="text-[var(--text-muted)] hover:text-[var(--text)] whitespace-nowrap shrink-0">SDK</Link>
<Link href="#about" className="text-[var(--text-muted)] hover:text-[var(--text)] whitespace-nowrap shrink-0">About</Link>
</nav>
{/* Right: Theme switcher or public CTA */}
<div className="flex items-center gap-2 shrink-0">
<Button
type="button"
@@ -112,13 +112,11 @@ export const Navbar: React.FC<NavbarProps> = ({
className="h-7 w-7 border border-[var(--border)] bg-[var(--bg-elevated)]"
/>
{!isVcon && (
<Link href="#sdk">
<Button size="xs" variant="primary">
SDK Guide
</Button>
</Link>
)}
<Link href="/vcon/dashboard">
<Button size="xs" variant="primary">
Console
</Button>
</Link>
</div>
</header>
);
+151 -130
View File
@@ -4,7 +4,7 @@ import { Button } from '@/components/ui/Button';
import { Icon } from '@/components/ui/Icon';
import { cn } from '@/lib/utils';
import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
import { usePathname } from 'next/navigation';
import React, { useEffect, useState } from 'react';
interface SidebarProps {
@@ -12,176 +12,197 @@ interface SidebarProps {
onClose?: () => void;
}
const NAVIGATION_SECTIONS = [
{
group: 'Main',
items: [
{ name: 'Dashboard', href: '/vcon/dashboard', icon: 'LayoutDashboard' },
{ name: 'Events', href: '/vcon/data', icon: 'Activity' },
{ name: 'Clients', href: '/vcon/clients', icon: 'Key' },
{ name: 'Export', href: '/vcon/export', icon: 'Download' },
{ name: 'Storage', href: '/vcon/storage', icon: 'HardDrive' },
],
},
{
group: 'System',
items: [
{ name: 'Python SDK', href: '/vcon/sdk', icon: 'FileCode2' },
{ name: 'Simulator', href: '/vcon/simulator', icon: 'Play' },
{ name: 'Settings', href: '/vcon/settings', icon: 'Sliders' },
{ name: 'Profile', href: '/vcon/profile', icon: 'User' },
],
},
];
export const Sidebar: React.FC<SidebarProps> = ({
isOpen = false,
onClose,
}) => {
const pathname = usePathname();
const router = useRouter();
const [isSigningOut, setIsSigningOut] = useState(false);
const [signOutError, setSignOutError] = useState('');
const navigation = [
{
group: 'Monitoring',
items: [
{ name: 'Dashboard', href: '/vcon/dashboard', icon: 'LayoutDashboard' },
{ name: 'Events', href: '/vcon/data', icon: 'Activity' },
],
},
{
group: 'Data',
items: [
{ name: 'Export', href: '/vcon/export', icon: 'Download' },
{ name: 'Storage', href: '/vcon/storage', icon: 'HardDrive' },
],
},
{
group: 'Administration',
items: [
{ name: 'Clients', href: '/vcon/clients', icon: 'Key' },
{ name: 'Settings', href: '/vcon/settings', icon: 'Sliders' },
],
},
{
group: 'Tools',
items: [
{ name: 'Python SDK', href: '/vcon/sdk', icon: 'FileCode2' },
{ name: 'Simulator', href: '/vcon/simulator', icon: 'Play' },
],
},
];
const activeGroup = navigation.find((section) =>
section.items.some((item) => item.href === pathname)
)?.group;
const [openGroup, setOpenGroup] = useState(activeGroup ?? navigation[0].group);
const [theme, setTheme] = useState<'dark' | 'light'>('dark');
useEffect(() => {
if (activeGroup) setOpenGroup(activeGroup);
}, [activeGroup]);
const saved = localStorage.getItem('datastack-theme') as 'dark' | 'light' | null;
const initial = saved === 'light' ? 'light' : 'dark';
setTheme(initial);
document.documentElement.classList.toggle('light', initial === 'light');
document.documentElement.classList.toggle('dark', initial === 'dark');
}, []);
const toggleTheme = () => {
const nextTheme = theme === 'dark' ? 'light' : 'dark';
setTheme(nextTheme);
localStorage.setItem('datastack-theme', nextTheme);
document.documentElement.classList.toggle('light', nextTheme === 'light');
document.documentElement.classList.toggle('dark', nextTheme === 'dark');
};
const signOut = async () => {
setIsSigningOut(true);
setSignOutError('');
try {
const response = await fetch('/api/auth/logout', {
method: 'POST',
credentials: 'include',
});
if (!response.ok) throw new Error('Unable to sign out. Please try again.');
if (!response.ok) throw new Error('Unable to sign out');
window.location.assign('/vcon/login');
} catch (error) {
setSignOutError(
error instanceof Error ? error.message : 'Unable to sign out. Please try again.',
);
} finally {
} catch {
setIsSigningOut(false);
}
};
return (
<>
{/* Mobile Backdrop */}
{isOpen && (
<div
onClick={onClose}
className="fixed inset-x-0 top-11 bottom-0 z-40 bg-black/50 lg:hidden"
className="fixed inset-0 z-40 bg-black/55 md:hidden"
/>
)}
{/* Sidebar Container */}
<aside
className={cn(
'fixed left-0 top-11 bottom-0 z-50 w-[216px] shrink-0 overflow-hidden bg-[var(--bg-sidebar)] border-r border-[var(--border)] flex flex-col transition-transform duration-150 ease-in-out lg:static lg:w-[216px] lg:translate-x-0',
'fixed inset-y-0 left-0 z-50 flex w-[184px] shrink-0 flex-col border-r border-[var(--border)] bg-[var(--surface)] transition-transform duration-150 ease-out md:sticky md:top-0 md:h-dvh md:translate-x-0',
isOpen ? 'translate-x-0' : '-translate-x-full'
)}
>
{/* Mobile Close Header */}
<div className="h-9 px-3 flex items-center justify-between border-b border-[var(--border)] bg-[var(--bg-activity)] shrink-0 lg:hidden">
<span className="text-[11px] font-medium text-[var(--text-muted)]">Menu</span>
<button
{/* Brand Header */}
<div className="flex h-10 shrink-0 items-center justify-between border-b border-[var(--border)] px-3">
<Link
href="/vcon/dashboard"
onClick={onClose}
className="text-[var(--text-dim)] hover:text-[var(--text)] p-1 cursor-pointer"
aria-label="Close menu"
className="flex min-w-0 items-center gap-2 text-[12.5px] font-medium text-[var(--text)]"
>
<Icon name="X" size={12} />
</button>
<span className="grid h-3 w-3 shrink-0 place-items-center bg-[var(--accent)]">
<span className="h-1 w-1 bg-[var(--bg)]" />
</span>
<span className="truncate">DataStack</span>
</Link>
<Link
href="/"
title="Public Home"
aria-label="Public Home"
className="hidden text-[10.5px] text-[var(--text-faint)] hover:text-[var(--text)] md:inline"
>
Site ↗
</Link>
<Button
type="button"
variant="icon"
size="icon"
icon="X"
onClick={onClose}
aria-label="Close navigation"
title="Close navigation"
className="h-6 w-6 md:hidden"
/>
</div>
{/* Navigation items */}
<nav aria-label="Admin navigation" className="flex-1 min-h-0 overflow-y-auto p-1.5 flex flex-col">
{navigation.map((section) => {
const isExpanded = openGroup === section.group;
const groupId = `nav-${section.group.toLowerCase().replaceAll(' ', '-')}`;
return (
<div key={section.group} className="border-b border-[var(--border)] last:border-b-0">
<button
type="button"
aria-expanded={isExpanded}
aria-controls={groupId}
onClick={() => setOpenGroup(isExpanded ? '' : section.group)}
className="w-full h-8 px-2.5 flex items-center justify-between gap-2 text-left text-[11px] font-medium text-[var(--text-muted)] hover:text-[var(--text)] transition-colors cursor-pointer"
>
<span className="truncate">{section.group}</span>
<Icon
name="ChevronDown"
size={11}
className={cn('transition-transform', isExpanded && 'rotate-180')}
/>
</button>
{isExpanded && (
<div id={groupId} className="pb-1 flex flex-col gap-0.5">
{section.items.map((item) => {
const isActive = pathname === item.href;
return (
<Link
key={item.href}
href={item.href}
onClick={onClose}
className={cn(
'flex h-8 min-w-0 items-center gap-2 px-2.5 text-[12px] transition-colors border',
isActive
? 'bg-[var(--accent-soft)] text-[var(--accent-hover)] font-medium border-[var(--accent)]'
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)]'
)}
>
<Icon
name={item.icon}
size={13}
className={isActive ? 'text-[var(--accent)]' : 'text-[var(--text-dim)]'}
/>
<span className="truncate">{item.name}</span>
</Link>
);
})}
</div>
)}
{/* Clean 2-Group Navigation */}
<nav
aria-label="Admin navigation"
className="flex-1 overflow-y-auto px-2 py-2.5 flex flex-col gap-3.5"
>
{NAVIGATION_SECTIONS.map((section) => (
<div key={section.group} className="flex flex-col gap-0.5">
<div className="px-2 pb-1 text-[9.5px] font-medium uppercase tracking-wider text-[var(--text-faint)]">
{section.group}
</div>
);
})}
{section.items.map((item) => {
const isActive = pathname === item.href;
return (
<Link
key={item.href}
href={item.href}
onClick={onClose}
className={cn(
'flex h-7 min-w-0 items-center gap-2 border-l-2 px-2 text-[12px] transition-colors select-none',
isActive
? 'border-l-[var(--accent)] bg-[var(--surface-2)] font-medium text-[var(--text)]'
: 'border-l-transparent text-[var(--text-muted)] hover:bg-[var(--surface-2)] hover:text-[var(--text)]'
)}
>
<Icon
name={item.icon}
size={13}
className={isActive ? 'text-[var(--accent)]' : 'text-[var(--text-faint)]'}
/>
<span className="truncate">{item.name}</span>
</Link>
);
})}
</div>
))}
</nav>
{/* Sign out action */}
{pathname !== '/vcon/setup' && (
<div className="p-1.5 border-t border-[var(--border)] bg-[var(--bg-main)] shrink-0">
{signOutError && (
<p role="alert" className="px-2 pb-1 text-[11px] text-[var(--danger)]">{signOutError}</p>
)}
<Button
type="button"
variant="ghost"
size="xs"
icon="LogOut"
loading={isSigningOut}
disabled={isSigningOut}
onClick={signOut}
className="w-full justify-start px-2.5 text-[11.5px] h-7"
>
Sign out
</Button>
</div>
)}
{/* Bottom Dock: Identity + Theme Toggle + Sign Out */}
<div className="flex shrink-0 items-center gap-1 border-t border-[var(--border)] bg-[var(--bg)] px-2.5 py-2">
<Link
href="/vcon/profile"
onClick={onClose}
className="flex flex-1 min-w-0 items-center gap-2 hover:opacity-90"
title="Admin Profile"
>
<div className="grid h-6 w-6 shrink-0 place-items-center border border-[var(--border-strong)] bg-[var(--surface-3)] text-[10.5px] font-medium text-[var(--text)]">
A
</div>
<div className="min-w-0 flex-1 leading-tight">
<div className="truncate text-[11px] font-medium text-[var(--text)]">
Admin
</div>
<div className="truncate text-[9px] uppercase tracking-wider text-[var(--text-faint)]">
Owner
</div>
</div>
</Link>
<Button
type="button"
variant="icon"
size="icon"
icon={theme === 'dark' ? 'Sun' : 'Moon'}
onClick={toggleTheme}
title="Toggle theme"
aria-label="Toggle theme"
className="h-6 w-6 border border-[var(--border)] bg-[var(--surface)]"
/>
<Button
type="button"
variant="icon"
size="icon"
icon="LogOut"
loading={isSigningOut}
disabled={isSigningOut}
onClick={signOut}
title="Sign out"
aria-label="Sign out"
className="h-6 w-6 border border-[var(--border)] bg-[var(--surface)] hover:border-[var(--danger)] hover:text-[var(--danger)]"
/>
</div>
</aside>
</>
);