"use client"; import { Bell, Loader2 } from "lucide-react"; import { usePathname } from "next/navigation"; import { useGetConversationsQuery, type ChatConversation, } from "@/app/api/queries/useGetConversationsQuery"; import { useGetSettingsQuery } from "@/app/api/queries/useGetSettingsQuery"; import { KnowledgeFilterPanel } from "@/components/knowledge-filter-panel"; import Logo from "@/components/logo/logo"; import { Navigation } from "@/components/navigation"; import { TaskNotificationMenu } from "@/components/task-notification-menu"; import { Button } from "@/components/ui/button"; import { UserNav } from "@/components/user-nav"; import { useAuth } from "@/contexts/auth-context"; import { useChat } from "@/contexts/chat-context"; import { useKnowledgeFilter } from "@/contexts/knowledge-filter-context"; // import { GitHubStarButton } from "@/components/github-star-button" // import { DiscordLink } from "@/components/discord-link" import { useTask } from "@/contexts/task-context"; import { cn } from "@/lib/utils"; export function LayoutWrapper({ children }: { children: React.ReactNode }) { const pathname = usePathname(); const { tasks, isMenuOpen, toggleMenu } = useTask(); const { isPanelOpen } = useKnowledgeFilter(); const { isLoading, isAuthenticated, isNoAuthMode } = useAuth(); const { endpoint, refreshTrigger, refreshConversations, startNewConversation, } = useChat(); const { isLoading: isSettingsLoading, data: settings } = useGetSettingsQuery({ enabled: isAuthenticated || isNoAuthMode, }); // Only fetch conversations on chat page const isOnChatPage = pathname === "/" || pathname === "/chat"; const { data: conversations = [], isLoading: isConversationsLoading } = useGetConversationsQuery(endpoint, refreshTrigger, { enabled: isOnChatPage && (isAuthenticated || isNoAuthMode), }) as { data: ChatConversation[]; isLoading: boolean }; const handleNewConversation = () => { refreshConversations(); startNewConversation(); }; // List of paths that should not show navigation const authPaths = ["/login", "/auth/callback", "/onboarding"]; const isAuthPage = authPaths.includes(pathname); // List of paths with smaller max-width const smallWidthPaths = ["/settings", "/settings/connector/new"]; const isSmallWidthPath = smallWidthPaths.includes(pathname); // Calculate active tasks for the bell icon const activeTasks = tasks.filter( (task) => task.status === "pending" || task.status === "running" || task.status === "processing" ); // Show loading state when backend isn't ready if (isLoading || isSettingsLoading) { return (
Starting OpenRAG...