diff --git a/src/App.tsx b/src/App.tsx index 5eaba72..12cf741 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,8 +12,12 @@ import { HomeView } from '@/views/HomeView' import { JobsView } from '@/views/JobsView' import { NotificationsView } from '@/views/NotificationsView' import { SettingsView } from '@/views/SettingsView' +import { useSession } from '@livekit/components-react' +import { TokenSource } from 'livekit-client' + export function App() { + const session = useSession(TokenSource.sandboxTokenServer('your-sandbox-id')) const [showSettings, setShowSettings] = useState(false) const [showJobs, setShowJobs] = useState(false) const [showNotifications, setShowNotifications] = useState(false) @@ -21,6 +25,7 @@ export function App() { return ( <> setShowSettings(true)} onJobsClick={() => setShowJobs(true)} onNotificationsClick={() => setShowNotifications(true)} diff --git a/src/views/HomeView.tsx b/src/views/HomeView.tsx index 9e61333..c56d96a 100644 --- a/src/views/HomeView.tsx +++ b/src/views/HomeView.tsx @@ -1,7 +1,6 @@ import { useRef, useState, useEffect } from 'react' -import { useSession, useAgent, useChat, useSessionMessages } from '@livekit/components-react' +import { useAgent, useChat, useSessionMessages, type UseSessionReturn } from '@livekit/components-react' import { Keyboard, Loader, SendHorizontal } from 'lucide-react' -import { TokenSource } from 'livekit-client' import { AgentAudioVisualizerAura } from '@/components/agents-ui/agent-audio-visualizer-aura' import { AgentChatTranscript } from '@/components/agents-ui/agent-chat-transcript' @@ -10,34 +9,34 @@ import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from import { AppBar } from '@/components/AppBar' interface HomeViewProps { + session: UseSessionReturn onSettingsClick: () => void onJobsClick: () => void onNotificationsClick: () => void } -export function HomeView({ onSettingsClick, onJobsClick, onNotificationsClick }: HomeViewProps) { - const session = useSession(TokenSource.sandboxTokenServer('your-sandbox-id')) +export function HomeView({ session, onSettingsClick, onJobsClick, onNotificationsClick }: HomeViewProps) { const { microphoneTrack, state: agentState } = useAgent(session) const { messages } = useSessionMessages(session) - const { send } = useChat({ room: session.room }) + // const { send } = useChat({ room: session.room }) - const [isOpen, setIsOpen] = useState(false) + const [isChatOpen, setChatOpen] = useState(false) const [message, setMessage] = useState('') - const [isSending, setIsSending] = useState(false) + const [isFormSubmitting, setFormSubmitting] = useState(false) const inputRef = useRef(null) - const isDisabled = isSending || message.trim().length === 0 + const isDisabled = isFormSubmitting || message.trim().length === 0 const handleSend = async () => { if (isDisabled) return try { - setIsSending(true) + setFormSubmitting(true) await send(message.trim()) setMessage('') } catch (error) { console.error(error) } finally { - setIsSending(false) + setFormSubmitting(false) } } @@ -49,19 +48,10 @@ export function HomeView({ onSettingsClick, onJobsClick, onNotificationsClick }: } useEffect(() => { - if (isOpen && inputRef.current) { + if (isChatOpen && inputRef.current) { inputRef.current.focus() } - }, [isOpen]) - - // Auto-open when first message arrives - const hasAutoOpened = useRef(false) - useEffect(() => { - if (messages.length > 0 && !hasAutoOpened.current) { - hasAutoOpened.current = true - setIsOpen(true) - } - }, [messages.length]) + }, [isChatOpen]) return (
@@ -76,8 +66,7 @@ export function HomeView({ onSettingsClick, onJobsClick, onNotificationsClick }:
- - +