"use client" import * as React from "react" import Link from "next/link" import { usePathname } from "next/navigation" import { Command, Frame, HelpCircle, Settings2, Terminal, Target, Plus } from "lucide-react" import { NavUser } from "@/components/nav-user" import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarGroup, SidebarGroupLabel, SidebarGroupContent, } from "@/components/ui/sidebar" import { useQuery, useMutation } from "convex/react" import { api } from "@/convex/_generated/api" import { Checkbox } from "@/components/ui/checkbox" import { Label } from "@/components/ui/label" import { useProject } from "@/components/project-context" export function AppSidebar({ ...props }: React.ComponentProps) { const pathname = usePathname() const projects = useQuery(api.projects.getProjects); const { selectedProjectId, setSelectedProjectId } = useProject(); // Set default selected project React.useEffect(() => { if (projects && projects.length > 0 && !selectedProjectId) { // Prefer default project, otherwise first const defaultProj = projects.find(p => p.isDefault); setSelectedProjectId(defaultProj ? defaultProj._id : projects[0]._id); } }, [projects, selectedProjectId]); // Data Sources Query const dataSources = useQuery( api.dataSources.getProjectDataSources, selectedProjectId ? { projectId: selectedProjectId as any } : "skip" ); const toggleConfig = useMutation(api.projects.toggleDataSourceConfig); const selectedProject = projects?.find(p => p._id === selectedProjectId); const selectedSourceIds = selectedProject?.dorkingConfig?.selectedSourceIds || []; const handleToggle = async (sourceId: string, checked: boolean) => { if (!selectedProjectId) return; await toggleConfig({ projectId: selectedProjectId as any, sourceId: sourceId as any, selected: checked }); }; return (
Sanati Pro
{/* Platform Nav */} Platform Dashboard Opportunities Settings Help {/* Projects (Simple List for now, can be switcher) */} Projects {projects?.map((project) => ( setSelectedProjectId(project._id)} isActive={selectedProjectId === project._id} > {project.name} ))} Create Project {/* Data Sources Config */} {selectedProjectId && ( Active Data Sources ({selectedProject?.name})
{(!dataSources || dataSources.length === 0) && (
No data sources yet.
)} {dataSources?.map((source) => (
handleToggle(source._id, checked === true)} />
))}
)}
) }