mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 00:51:14 -05:00
feat: Implement collapsible sidebar navigation
This commit is contained in:
10
src/App.tsx
10
src/App.tsx
@@ -33,7 +33,10 @@ import NotFound from "./pages/NotFound";
|
||||
import Terms from "./pages/Terms";
|
||||
import Privacy from "./pages/Privacy";
|
||||
import SubmissionGuidelines from "./pages/SubmissionGuidelines";
|
||||
import Admin from "./pages/Admin";
|
||||
import AdminDashboard from "./pages/AdminDashboard";
|
||||
import AdminModeration from "./pages/AdminModeration";
|
||||
import AdminReports from "./pages/AdminReports";
|
||||
import AdminUsers from "./pages/AdminUsers";
|
||||
import AdminSettings from "./pages/AdminSettings";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
@@ -71,7 +74,10 @@ function AppContent() {
|
||||
<Route path="/profile" element={<Profile />} />
|
||||
<Route path="/profile/:username" element={<Profile />} />
|
||||
<Route path="/settings" element={<UserSettings />} />
|
||||
<Route path="/admin" element={<Admin />} />
|
||||
<Route path="/admin" element={<AdminDashboard />} />
|
||||
<Route path="/admin/moderation" element={<AdminModeration />} />
|
||||
<Route path="/admin/reports" element={<AdminReports />} />
|
||||
<Route path="/admin/users" element={<AdminUsers />} />
|
||||
<Route path="/admin/settings" element={<AdminSettings />} />
|
||||
<Route path="/terms" element={<Terms />} />
|
||||
<Route path="/privacy" element={<Privacy />} />
|
||||
|
||||
62
src/components/layout/AdminLayout.tsx
Normal file
62
src/components/layout/AdminLayout.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
import { ReactNode, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { SidebarProvider } from '@/components/ui/sidebar';
|
||||
import { AdminSidebar } from './AdminSidebar';
|
||||
import { AdminTopBar } from './AdminTopBar';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
|
||||
interface AdminLayoutProps {
|
||||
children: ReactNode;
|
||||
onRefresh?: () => void;
|
||||
isRefreshing?: boolean;
|
||||
}
|
||||
|
||||
export function AdminLayout({ children, onRefresh, isRefreshing }: AdminLayoutProps) {
|
||||
const { user, loading: authLoading } = useAuth();
|
||||
const { isModerator, loading: roleLoading } = useUserRole();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading && !roleLoading) {
|
||||
if (!user) {
|
||||
navigate('/auth');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isModerator()) {
|
||||
navigate('/');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, [user, authLoading, roleLoading, navigate, isModerator]);
|
||||
|
||||
if (authLoading || roleLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto mb-4"></div>
|
||||
<p className="text-muted-foreground">Loading admin panel...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!user || !isModerator()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<SidebarProvider defaultOpen={true}>
|
||||
<div className="flex min-h-screen w-full">
|
||||
<AdminSidebar />
|
||||
<main className="flex-1 flex flex-col">
|
||||
<AdminTopBar onRefresh={onRefresh} isRefreshing={isRefreshing} />
|
||||
<div className="flex-1 overflow-auto">
|
||||
{children}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</SidebarProvider>
|
||||
);
|
||||
}
|
||||
148
src/components/layout/AdminSidebar.tsx
Normal file
148
src/components/layout/AdminSidebar.tsx
Normal file
@@ -0,0 +1,148 @@
|
||||
import { LayoutDashboard, FileText, Flag, Users, Settings, ArrowLeft } from 'lucide-react';
|
||||
import { NavLink, useLocation } from 'react-router-dom';
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
SidebarFooter,
|
||||
SidebarHeader,
|
||||
useSidebar,
|
||||
} from '@/components/ui/sidebar';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
|
||||
const navigationItems = [
|
||||
{
|
||||
title: 'Dashboard',
|
||||
url: '/admin',
|
||||
icon: LayoutDashboard,
|
||||
},
|
||||
{
|
||||
title: 'Moderation Queue',
|
||||
url: '/admin/moderation',
|
||||
icon: FileText,
|
||||
},
|
||||
{
|
||||
title: 'Reports',
|
||||
url: '/admin/reports',
|
||||
icon: Flag,
|
||||
},
|
||||
{
|
||||
title: 'User Management',
|
||||
url: '/admin/users',
|
||||
icon: Users,
|
||||
},
|
||||
];
|
||||
|
||||
export function AdminSidebar() {
|
||||
const location = useLocation();
|
||||
const { state } = useSidebar();
|
||||
const { isSuperuser } = useUserRole();
|
||||
const isCollapsed = state === 'collapsed';
|
||||
|
||||
const isActive = (path: string) => {
|
||||
if (path === '/admin') {
|
||||
return location.pathname === '/admin';
|
||||
}
|
||||
return location.pathname.startsWith(path);
|
||||
};
|
||||
|
||||
return (
|
||||
<Sidebar collapsible="icon" className="border-r">
|
||||
<SidebarHeader className="border-b px-4 py-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-primary text-primary-foreground">
|
||||
<span className="text-sm font-bold">TW</span>
|
||||
</div>
|
||||
{!isCollapsed && (
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-semibold">ThrillWiki</span>
|
||||
<span className="text-xs text-muted-foreground">Admin Panel</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</SidebarHeader>
|
||||
|
||||
<SidebarContent>
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Navigation</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{navigationItems.map((item) => (
|
||||
<SidebarMenuItem key={item.url}>
|
||||
<SidebarMenuButton
|
||||
asChild
|
||||
isActive={isActive(item.url)}
|
||||
tooltip={isCollapsed ? item.title : undefined}
|
||||
>
|
||||
<NavLink
|
||||
to={item.url}
|
||||
end={item.url === '/admin'}
|
||||
className={({ isActive }) =>
|
||||
cn(
|
||||
'flex items-center gap-3 rounded-md transition-colors',
|
||||
isActive
|
||||
? 'bg-primary/10 text-primary font-medium'
|
||||
: 'hover:bg-muted/50'
|
||||
)
|
||||
}
|
||||
>
|
||||
<item.icon className="h-5 w-5" />
|
||||
{!isCollapsed && <span>{item.title}</span>}
|
||||
</NavLink>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
|
||||
{isSuperuser() && (
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton
|
||||
asChild
|
||||
isActive={isActive('/admin/settings')}
|
||||
tooltip={isCollapsed ? 'Settings' : undefined}
|
||||
>
|
||||
<NavLink
|
||||
to="/admin/settings"
|
||||
className={({ isActive }) =>
|
||||
cn(
|
||||
'flex items-center gap-3 rounded-md transition-colors',
|
||||
isActive
|
||||
? 'bg-primary/10 text-primary font-medium'
|
||||
: 'hover:bg-muted/50'
|
||||
)
|
||||
}
|
||||
>
|
||||
<Settings className="h-5 w-5" />
|
||||
{!isCollapsed && <span>Settings</span>}
|
||||
</NavLink>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
)}
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
</SidebarContent>
|
||||
|
||||
<SidebarFooter className="border-t p-2">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton asChild tooltip={isCollapsed ? 'Back to ThrillWiki' : undefined}>
|
||||
<NavLink
|
||||
to="/"
|
||||
className="flex items-center gap-3 text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<ArrowLeft className="h-5 w-5" />
|
||||
{!isCollapsed && <span>Back to ThrillWiki</span>}
|
||||
</NavLink>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
);
|
||||
}
|
||||
38
src/components/layout/AdminTopBar.tsx
Normal file
38
src/components/layout/AdminTopBar.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { SidebarTrigger } from '@/components/ui/sidebar';
|
||||
import { ThemeToggle } from '@/components/theme/ThemeToggle';
|
||||
import { NotificationCenter } from '@/components/notifications/NotificationCenter';
|
||||
import { AuthButtons } from '@/components/auth/AuthButtons';
|
||||
|
||||
interface AdminTopBarProps {
|
||||
onRefresh?: () => void;
|
||||
isRefreshing?: boolean;
|
||||
}
|
||||
|
||||
export function AdminTopBar({ onRefresh, isRefreshing }: AdminTopBarProps) {
|
||||
return (
|
||||
<header className="sticky top-0 z-10 flex h-14 items-center gap-4 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 px-4">
|
||||
<SidebarTrigger className="-ml-1" />
|
||||
|
||||
{onRefresh && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onRefresh}
|
||||
disabled={isRefreshing}
|
||||
className="gap-2"
|
||||
>
|
||||
<RefreshCw className={`h-4 w-4 ${isRefreshing ? 'animate-spin' : ''}`} />
|
||||
<span className="hidden sm:inline">Refresh</span>
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<NotificationCenter />
|
||||
<ThemeToggle />
|
||||
<AuthButtons />
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
116
src/pages/AdminDashboard.tsx
Normal file
116
src/pages/AdminDashboard.tsx
Normal file
@@ -0,0 +1,116 @@
|
||||
import { useRef, useCallback } from 'react';
|
||||
import { RefreshCw, FileText, Flag, AlertCircle } from 'lucide-react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { AdminLayout } from '@/components/layout/AdminLayout';
|
||||
import { useModerationStats } from '@/hooks/useModerationStats';
|
||||
import { useAdminSettings } from '@/hooks/useAdminSettings';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
|
||||
export default function AdminDashboard() {
|
||||
const { user, loading: authLoading } = useAuth();
|
||||
const { isModerator, loading: roleLoading } = useUserRole();
|
||||
|
||||
// Get admin settings for polling configuration
|
||||
const {
|
||||
getAdminPanelRefreshMode,
|
||||
getAdminPanelPollInterval,
|
||||
} = useAdminSettings();
|
||||
|
||||
const refreshMode = getAdminPanelRefreshMode();
|
||||
const pollInterval = getAdminPanelPollInterval();
|
||||
|
||||
// Use stats hook with configurable polling
|
||||
const { stats, refresh: refreshStats, lastUpdated } = useModerationStats({
|
||||
enabled: !!user && !authLoading && !roleLoading && isModerator(),
|
||||
pollingEnabled: refreshMode === 'auto',
|
||||
pollingInterval: pollInterval,
|
||||
});
|
||||
|
||||
const handleRefresh = useCallback(() => {
|
||||
refreshStats();
|
||||
}, [refreshStats]);
|
||||
|
||||
return (
|
||||
<AdminLayout onRefresh={handleRefresh}>
|
||||
<div className="container mx-auto px-6 py-8 max-w-7xl">
|
||||
{/* Refresh status indicator */}
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground mb-6">
|
||||
<RefreshCw className="w-3 h-3" />
|
||||
{refreshMode === 'auto' ? (
|
||||
<span>Auto-refresh: every {pollInterval / 1000}s</span>
|
||||
) : (
|
||||
<span>Manual refresh</span>
|
||||
)}
|
||||
{lastUpdated && (
|
||||
<span>• {lastUpdated.toLocaleTimeString()}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Stats Overview */}
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold mb-6">Dashboard Overview</h1>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<Card className="border-border/50 hover:border-border/80 transition-colors">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-amber-500/10">
|
||||
<FileText className="h-5 w-5 text-amber-700 dark:text-amber-300" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-muted-foreground">Pending</p>
|
||||
<p className="text-xs text-muted-foreground/80">Submissions</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-4xl font-bold text-amber-700 dark:text-amber-300">
|
||||
{stats.pendingSubmissions}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="border-border/50 hover:border-border/80 transition-colors">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-red-500/10">
|
||||
<Flag className="h-5 w-5 text-red-700 dark:text-red-300" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-muted-foreground">Open</p>
|
||||
<p className="text-xs text-muted-foreground/80">Reports</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-4xl font-bold text-red-700 dark:text-red-300">
|
||||
{stats.openReports}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="border-border/50 hover:border-border/80 transition-colors">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="p-2 rounded-lg bg-orange-500/10">
|
||||
<AlertCircle className="h-5 w-5 text-orange-700 dark:text-orange-300" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-muted-foreground">Flagged</p>
|
||||
<p className="text-xs text-muted-foreground/80">Content</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-4xl font-bold text-orange-700 dark:text-orange-300">
|
||||
{stats.flaggedContent}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
22
src/pages/AdminModeration.tsx
Normal file
22
src/pages/AdminModeration.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useRef, useCallback } from 'react';
|
||||
import { AdminLayout } from '@/components/layout/AdminLayout';
|
||||
import { ModerationQueue, ModerationQueueRef } from '@/components/moderation/ModerationQueue';
|
||||
|
||||
export default function AdminModeration() {
|
||||
const moderationQueueRef = useRef<ModerationQueueRef>(null);
|
||||
|
||||
const handleRefresh = useCallback(() => {
|
||||
moderationQueueRef.current?.refresh();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AdminLayout onRefresh={handleRefresh}>
|
||||
<div className="container mx-auto px-6 py-8 max-w-7xl">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold mb-6">Moderation Queue</h1>
|
||||
<ModerationQueue ref={moderationQueueRef} />
|
||||
</div>
|
||||
</div>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
22
src/pages/AdminReports.tsx
Normal file
22
src/pages/AdminReports.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useRef, useCallback } from 'react';
|
||||
import { AdminLayout } from '@/components/layout/AdminLayout';
|
||||
import { ReportsQueue, ReportsQueueRef } from '@/components/moderation/ReportsQueue';
|
||||
|
||||
export default function AdminReports() {
|
||||
const reportsQueueRef = useRef<ReportsQueueRef>(null);
|
||||
|
||||
const handleRefresh = useCallback(() => {
|
||||
reportsQueueRef.current?.refresh();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AdminLayout onRefresh={handleRefresh}>
|
||||
<div className="container mx-auto px-6 py-8 max-w-7xl">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold mb-6">Reports Queue</h1>
|
||||
<ReportsQueue ref={reportsQueueRef} />
|
||||
</div>
|
||||
</div>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { Switch } from '@/components/ui/switch';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { AdminHeader } from '@/components/layout/AdminHeader';
|
||||
import { AdminLayout } from '@/components/layout/AdminLayout';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { useAdminSettings } from '@/hooks/useAdminSettings';
|
||||
@@ -28,20 +28,18 @@ export default function AdminSettings() {
|
||||
|
||||
if (roleLoading || isLoading) {
|
||||
return (
|
||||
<>
|
||||
<AdminHeader />
|
||||
<AdminLayout>
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<Loader2 className="w-8 h-8 animate-spin" />
|
||||
</div>
|
||||
</>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
|
||||
if (!user || !isSuperuser()) {
|
||||
return (
|
||||
<>
|
||||
<AdminHeader />
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<AdminLayout>
|
||||
<div className="container mx-auto px-6 py-8">
|
||||
<div className="text-center space-y-4">
|
||||
<h1 className="text-2xl font-bold mb-4">Access Denied</h1>
|
||||
<p className="text-muted-foreground">You don't have permission to access admin settings.</p>
|
||||
@@ -52,15 +50,14 @@ export default function AdminSettings() {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
|
||||
if (!settings || settings.length === 0) {
|
||||
return (
|
||||
<>
|
||||
<AdminHeader />
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<AdminLayout>
|
||||
<div className="container mx-auto px-6 py-8">
|
||||
<div className="text-center space-y-4">
|
||||
<h1 className="text-2xl font-bold mb-4">No Settings Found</h1>
|
||||
<p className="text-muted-foreground">
|
||||
@@ -73,7 +70,7 @@ export default function AdminSettings() {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -431,11 +428,10 @@ export default function AdminSettings() {
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<AdminHeader />
|
||||
<div className="container mx-auto px-4 py-8 max-w-4xl">
|
||||
<AdminLayout>
|
||||
<div className="container mx-auto px-6 py-8 max-w-6xl">
|
||||
<div className="mb-8">
|
||||
<h1 className="text-3xl font-bold mb-2">Admin Settings</h1>
|
||||
<h1 className="text-2xl font-bold mb-2">Admin Settings</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Configure system-wide settings and preferences with easy-to-use controls
|
||||
</p>
|
||||
@@ -598,6 +594,6 @@ export default function AdminSettings() {
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
</>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
15
src/pages/AdminUsers.tsx
Normal file
15
src/pages/AdminUsers.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { AdminLayout } from '@/components/layout/AdminLayout';
|
||||
import { UserManagement } from '@/components/admin/UserManagement';
|
||||
|
||||
export default function AdminUsers() {
|
||||
return (
|
||||
<AdminLayout>
|
||||
<div className="container mx-auto px-6 py-8 max-w-7xl">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold mb-6">User Management</h1>
|
||||
<UserManagement />
|
||||
</div>
|
||||
</div>
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user