import React, { useState } from 'react'; import { useLocation } from 'wouter'; import { Settings, MessageSquare, Menu, Video, Image, AlertCircle } from 'lucide-react'; import { Link } from 'wouter'; import { Button } from '@/components/ui/button'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip'; import ChatHistory from '@/components/ChatHistory'; import ChatInputForm from '@/components/ChatInputForm'; import ConversationSidebar from '@/components/ConversationSidebar'; import ConnectionStatus from '@/components/ConnectionStatus'; import UserSettingsModal from '@/components/UserSettingsModal'; import { useAuth } from '@/hooks/use-auth'; import { useChat } from '@/lib/hooks'; // Main home page component const Home: React.FC = () => { const { user, logoutMutation } = useAuth(); const [, navigate] = useLocation(); const [sidebarOpen, setSidebarOpen] = useState(false); const [errorVisible, setErrorVisible] = useState(true); const [settingsOpen, setSettingsOpen] = useState(false); const { messages, isLoading, error, isConnected, currentModel, sendMessage, conversationId, setConversationId } = useChat("default"); // Handle creating a new conversation const handleNewConversation = async () => { try { // Create a new conversation on the server const response = await fetch('/api/conversations', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ title: '' // Let the server generate a title }), }); if (!response.ok) { throw new Error('Failed to create new conversation'); } const newConversation = await response.json(); setConversationId(newConversation.id); // The useEffect in useChat will automatically load messages setSidebarOpen(false); } catch (error) { console.error('Error creating new conversation:', error); } }; // Handle selecting a conversation const handleSelectConversation = (id: string) => { if (id === conversationId) { // Already selected, just close the sidebar setSidebarOpen(false); return; } // Set the conversation ID, which will trigger loading the messages setConversationId(id); // Close sidebar on mobile after selection setSidebarOpen(false); }; // Handle sign in button click const handleSignIn = () => { navigate('/auth'); }; return (
{/* Conversation Sidebar */} setSidebarOpen(false)} selectedConversationId={conversationId} onSelectConversation={handleSelectConversation} onNewConversation={handleNewConversation} /> {/* Header */}

AI Chat Assistant

Create AI-generated images

Create AI-generated videos

Settings

{/* Main chat container */}
{/* Error message */} {error && errorVisible && (

{error}

{error.includes('API quota') && (

This usually means the OpenAI API key has reached its limit or doesn't have a payment method associated with it. The system will attempt to use the Qwen fallback model.

)}
)} {/* Chat history */}
{/* Input area */}
{/* User Settings Modal */} {user && ( setSettingsOpen(false)} /> )}
); }; export default Home;