Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

feat: replace MUI drawer with collapsible shadcn sidebar, breadcrumb header, and page skeleton

valzor5f28b4096dc5
diff --git a/frontend/src/layout/Header.jsx b/frontend/src/layout/Header.jsx
new file mode 100644
index 0000000..0718b70
--- /dev/null
+++ b/frontend/src/layout/Header.jsx
@@ -0,0 +1,102 @@
+import React from 'react';
+import { useNavigate, useLocation } from 'react-router-dom';
+import { SidebarTrigger } from '@/components/ui/sidebar';
+import { Button } from '@/components/ui/button';
+import { Avatar, AvatarFallback } from '@/components/ui/avatar';
+import {
+ Breadcrumb, BreadcrumbItem, BreadcrumbLink,
+ BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator,
+} from '@/components/ui/breadcrumb';
+import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
+import { RefreshCw, Settings, Sun, Moon } from 'lucide-react';
+import { useTheme } from 'next-themes';
+import { useAppContext } from '../context/AppContext';
+import { cn } from '@/lib/utils';
+
+const BREADCRUMB_MAP = {
+ '/': { label: 'Overview', parent: null },
+ '/videos': { label: 'All Videos', parent: 'Analytics' },
+ '/shorts': { label: 'Shorts', parent: 'Analytics' },
+ '/reels': { label: 'IG Content', parent: 'Analytics' },
+ '/upload': { label: 'Publish', parent: 'Publishing' },
+ '/accounts': { label: 'Accounts', parent: 'Management' },
+ '/settings': { label: 'Settings', parent: 'Management' },
+};
+
+export default function AppHeader() {
+ const navigate = useNavigate();
+ const location = useLocation();
+ const { loading, refreshAll } = useAppContext();
+ const { resolvedTheme, setTheme } = useTheme();
+ const isDark = resolvedTheme === 'dark';
+
+ let crumb = BREADCRUMB_MAP[location.pathname];
+ if (!crumb && location.pathname.startsWith('/channel/')) {
+ crumb = { label: 'Channel Analytics', parent: 'Analytics' };
+ } else if (!crumb && location.pathname.startsWith('/instagram/')) {
+ crumb = { label: 'Instagram Analytics', parent: 'Analytics' };
+ }
+
+ return (
+ <header className="flex h-14 shrink-0 items-center gap-2 border-b border-border bg-background/95 backdrop-blur px-4">
+ <SidebarTrigger className="-ml-1" />
+
+ {/* Breadcrumbs */}
+ {crumb && (
+ <Breadcrumb className="flex-1">
+ <BreadcrumbList>
+ <BreadcrumbItem>
+ <BreadcrumbLink
+ onClick={() => navigate('/')}
+ className="cursor-pointer text-xs"
+ >
+ Dashboard
+ </BreadcrumbLink>
+ </BreadcrumbItem>
+ {crumb.parent && (
+ <>
+ <BreadcrumbSeparator />
+ <BreadcrumbItem>
+ <BreadcrumbPage className="text-xs text-muted-foreground">
+ {crumb.parent}
+ </BreadcrumbPage>
+ </BreadcrumbItem>
+ </>
+ )}
+ <BreadcrumbSeparator />
+ <BreadcrumbItem>
+ <BreadcrumbPage className="text-xs font-semibold">{crumb.label}</BreadcrumbPage>
+ </BreadcrumbItem>
+ </BreadcrumbList>
+ </Breadcrumb>
+ )}
+
+ <div className="ml-auto flex items-center gap-1">
+ <Tooltip>
+ <TooltipTrigger render={<Button variant="ghost" size="icon" className="size-8" onClick={refreshAll} disabled={loading} />}>
+ <RefreshCw className={cn(loading && 'animate-spin')} />
+ </TooltipTrigger>
+ <TooltipContent>Refresh all accounts</TooltipContent>
+ </Tooltip>
+
+ <Tooltip>
+ <TooltipTrigger render={<Button variant="ghost" size="icon" className="size-8" onClick={() => setTheme(isDark ? 'light' : 'dark')} />}>
+ {isDark ? <Sun /> : <Moon />}
+ </TooltipTrigger>
+ <TooltipContent>{isDark ? 'Light mode' : 'Dark mode'}</TooltipContent>
+ </Tooltip>
+
+ <Tooltip>
+ <TooltipTrigger render={<Button variant="ghost" size="icon" className="size-8" onClick={() => navigate('/settings')} />}>
+ <Settings />
+ </TooltipTrigger>
+ <TooltipContent>Settings</TooltipContent>
+ </Tooltip>
+
+ <Avatar className="size-8 ml-1">
+ <AvatarFallback className="bg-primary text-primary-foreground text-xs font-bold">T</AvatarFallback>
+ </Avatar>
+ </div>
+ </header>
+ );
+}
diff --git a/frontend/src/layout/Sidebar.jsx b/frontend/src/layout/Sidebar.jsx
new file mode 100644
index 0000000..089e45b
--- /dev/null
+++ b/frontend/src/layout/Sidebar.jsx
@@ -0,0 +1,153 @@
+import React from 'react';
+import { useNavigate, useLocation } from 'react-router-dom';
+import {
+ Sidebar, SidebarContent, SidebarFooter, SidebarGroup,
+ SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton,
+ SidebarMenuItem, SidebarSeparator,
+} from '@/components/ui/sidebar';
+import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
+import {
+ LayoutDashboard, PlaySquare, Scissors, Camera,
+ Upload, Users, Settings,
+} from 'lucide-react';
+import { useAppContext } from '../context/AppContext';
+
+const NAV_GROUPS = [
+ {
+ label: 'Analytics',
+ items: [
+ { path: '/', label: 'Overview', icon: LayoutDashboard },
+ { path: '/videos', label: 'All Videos', icon: PlaySquare },
+ { path: '/shorts', label: 'Shorts', icon: Scissors },
+ { path: '/reels', label: 'IG Content', icon: Camera },
+ ],
+ },
+ {
+ label: 'Publishing',
+ items: [
+ { path: '/upload', label: 'Publish', icon: Upload },
+ ],
+ },
+ {
+ label: 'Management',
+ items: [
+ { path: '/accounts', label: 'Accounts', icon: Users },
+ { path: '/settings', label: 'Settings', icon: Settings },
+ ],
+ },
+];
+
+export default function AppSidebar() {
+ const navigate = useNavigate();
+ const location = useLocation();
+ const { accounts } = useAppContext();
+
+ const isActive = (path) => {
+ if (path === '/') return location.pathname === '/';
+ return location.pathname.startsWith(path);
+ };
+
+ return (
+ <Sidebar collapsible="icon" className="border-r border-border">
+ {/* Header */}
+ <SidebarHeader className="border-b border-border">
+ <SidebarMenu>
+ <SidebarMenuItem>
+ <SidebarMenuButton
+ size="lg"
+ className="cursor-default hover:bg-transparent active:bg-transparent"
+ >
+ <img src="/logo.png" alt="Twiligent" className="size-8 object-contain shrink-0" />
+ <div className="flex flex-col leading-tight min-w-0">
+ <span className="font-bold text-sm truncate">Twiligent</span>
+ <span className="text-xs text-muted-foreground truncate">Analytics</span>
+ </div>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ </SidebarMenu>
+ </SidebarHeader>
+
+ {/* Nav groups */}
+ <SidebarContent>
+ {NAV_GROUPS.map((group, gi) => (
+ <SidebarGroup key={gi}>
+ <SidebarGroupLabel>{group.label}</SidebarGroupLabel>
+ <SidebarMenu>
+ {group.items.map((item) => {
+ const Icon = item.icon;
+ const active = isActive(item.path);
+ return (
+ <SidebarMenuItem key={item.path}>
+ <SidebarMenuButton
+ isActive={active}
+ onClick={() => navigate(item.path)}
+ tooltip={item.label}
+ >
+ <Icon />
+ <span>{item.label}</span>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ );
+ })}
+ </SidebarMenu>
+ {gi < NAV_GROUPS.length - 1 && <SidebarSeparator className="mt-2" />}
+ </SidebarGroup>
+ ))}
+
+ {/* Accounts quick list */}
+ {accounts.length > 0 && (
+ <SidebarGroup>
+ <SidebarSeparator />
+ <SidebarGroupLabel>Accounts</SidebarGroupLabel>
+ <SidebarMenu>
+ {accounts.map((acc) => {
+ const isIG = acc.platform === 'instagram';
+ const path = isIG ? `/instagram/${acc.id}` : `/channel/${acc.id}`;
+ const initials = (acc.title || '?').slice(0, 2).toUpperCase();
+ return (
+ <SidebarMenuItem key={acc.id}>
+ <SidebarMenuButton
+ isActive={location.pathname === path}
+ onClick={() => navigate(path)}
+ tooltip={acc.title}
+ >
+ <Avatar className="size-5 flex-shrink-0">
+ <AvatarImage
+ src={acc.thumbnail || acc.profilePictureUrl || acc.thumbnails?.default}
+ alt={acc.title}
+ />
+ <AvatarFallback
+ style={{ background: isIG ? '#ec4899' : '#ef4444' }}
+ className="text-[0.5rem] font-bold text-white"
+ >
+ {initials}
+ </AvatarFallback>
+ </Avatar>
+ <span className="truncate text-sm">{acc.title}</span>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ );
+ })}
+ </SidebarMenu>
+ </SidebarGroup>
+ )}
+ </SidebarContent>
+
+ {/* Footer */}
+ <SidebarFooter className="border-t border-border p-2">
+ <SidebarMenu>
+ <SidebarMenuItem>
+ <SidebarMenuButton
+ onClick={() => navigate('/settings')}
+ tooltip="Settings"
+ className="text-muted-foreground"
+ >
+ <Settings />
+ <span>Settings</span>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ </SidebarMenu>
+ </SidebarFooter>
+ </Sidebar>
+ );
+}
diff --git a/frontend/src/layout/index.jsx b/frontend/src/layout/index.jsx
index 9867f05..1e54bf0 100644
--- a/frontend/src/layout/index.jsx
+++ b/frontend/src/layout/index.jsx
@@ -1,48 +1,36 @@
-import React, { useState } from 'react';
+import React, { Suspense } from 'react';
import { Outlet } from 'react-router-dom';
-import { Box, Toolbar, useMediaQuery } from '@mui/material';
-import MainDrawer, { DRAWER_WIDTH, MINI_DRAWER_WIDTH } from './Drawer/index';
-import Header from './Header/index';
-
-export default function MainLayout() {
- const isMobile = useMediaQuery('(max-width:1024px)');
- const [drawerOpen, setDrawerOpen] = useState(true);
-
- const toggleDrawer = () => setDrawerOpen(prev => !prev);
-
- const contentMargin = isMobile ? 0 : (drawerOpen ? DRAWER_WIDTH : MINI_DRAWER_WIDTH);
+import { SidebarProvider, SidebarInset } from '@/components/ui/sidebar';
+import AppSidebar from './Sidebar';
+import AppHeader from './Header';
+function PageSkeleton() {
return (
- <Box sx={{ display: 'flex', minHeight: '100vh', bgcolor: 'background.default' }}>
- <MainDrawer open={drawerOpen} onClose={() => setDrawerOpen(false)} />
-
- <Box
- component="main"
- sx={{
- flexGrow: 1,
- ml: isMobile ? 0 : `${contentMargin}px`,
- transition: 'margin-left 0.2s ease',
- minWidth: 0,
- display: 'flex',
- flexDirection: 'column',
- }}
- >
- <Header drawerOpen={drawerOpen} onToggleDrawer={toggleDrawer} />
-
- {/* Offset for fixed header */}
- <Toolbar sx={{ minHeight: '60px !important', flexShrink: 0 }} />
+ <div className="flex-1 p-4 sm:p-6 space-y-4 animate-pulse">
+ <div className="h-8 w-48 rounded-md bg-muted" />
+ <div className="h-4 w-72 rounded-md bg-muted" />
+ <div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4 mt-6">
+ {Array.from({ length: 4 }).map((_, i) => (
+ <div key={i} className="h-28 rounded-xl bg-muted" />
+ ))}
+ </div>
+ <div className="h-64 rounded-xl bg-muted" />
+ </div>
+ );
+}
- {/* Page content */}
- <Box
- sx={{
- flex: 1,
- p: { xs: 2, sm: 3 },
- overflowX: 'hidden',
- }}
- >
- <Outlet />
- </Box>
- </Box>
- </Box>
+export default function MainLayout() {
+ return (
+ <SidebarProvider>
+ <AppSidebar />
+ <SidebarInset>
+ <AppHeader />
+ <main className="flex-1 overflow-auto p-4 sm:p-6">
+ <Suspense fallback={<PageSkeleton />}>
+ <Outlet />
+ </Suspense>
+ </main>
+ </SidebarInset>
+ </SidebarProvider>
);
}