"use client"; import { useAtomValue } from "jotai"; import { AlertCircle, Plus, Search } from "lucide-react"; import { motion } from "motion/react"; import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import { useEffect, useState } from "react"; import { searchSpacesAtom } from "@/atoms/search-spaces/search-space-query.atoms"; import { CreateSearchSpaceDialog } from "@/components/layout"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { useGlobalLoadingEffect } from "@/hooks/use-global-loading"; function ErrorScreen({ message }: { message: string }) { const t = useTranslations("dashboard"); const router = useRouter(); return (
{t("error")}
{t("something_wrong")}
{t("error_details")} {message}
); } function EmptyState({ onCreateClick }: { onCreateClick: () => void }) { const t = useTranslations("searchSpace"); return (

{t("welcome_title")}

{t("welcome_description")}

); } export default function DashboardPage() { const router = useRouter(); const [showCreateDialog, setShowCreateDialog] = useState(false); const t = useTranslations("dashboard"); const { data: searchSpaces = [], isLoading, error } = useAtomValue(searchSpacesAtom); useEffect(() => { if (isLoading) return; if (searchSpaces.length > 0) { router.replace(`/dashboard/${searchSpaces[0].id}/new-chat`); } }, [isLoading, searchSpaces, router]); // Show loading while fetching or while we have spaces and are about to redirect const shouldShowLoading = isLoading || searchSpaces.length > 0; // Use global loading screen - spinner animation won't reset useGlobalLoadingEffect(shouldShowLoading); if (error) return ; if (shouldShowLoading) { return null; } return ( <> setShowCreateDialog(true)} /> ); }