Skip to content

Commit f3a9dda

Browse files
committed
updated styling to match existing subblocks
1 parent 052ded6 commit f3a9dda

File tree

4 files changed

+244
-633
lines changed

4 files changed

+244
-633
lines changed

apps/sim/app/chat/[identifier]/chat.tsx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
175175
const distanceFromBottom = scrollHeight - scrollTop - clientHeight
176176
setShowScrollButton(distanceFromBottom > 100)
177177

178-
// Track if user is manually scrolling during streaming
179178
if (isStreamingResponse && !isUserScrollingRef.current) {
180179
setUserHasScrolled(true)
181180
}
@@ -191,13 +190,10 @@ export default function ChatClient({ identifier }: { identifier: string }) {
191190
return () => container.removeEventListener('scroll', handleScroll)
192191
}, [handleScroll])
193192

194-
// Reset user scroll tracking when streaming starts
195193
useEffect(() => {
196194
if (isStreamingResponse) {
197-
// Reset userHasScrolled when streaming starts
198195
setUserHasScrolled(false)
199196

200-
// Give a small delay to distinguish between programmatic scroll and user scroll
201197
isUserScrollingRef.current = true
202198
setTimeout(() => {
203199
isUserScrollingRef.current = false
@@ -215,7 +211,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
215211
})
216212

217213
if (!response.ok) {
218-
// Check if auth is required
219214
if (response.status === 401) {
220215
const errorData = await response.json()
221216

@@ -236,7 +231,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
236231
throw new Error(`Failed to load chat configuration: ${response.status}`)
237232
}
238233

239-
// Reset auth required state when authentication is successful
240234
setAuthRequired(null)
241235

242236
const data = await response.json()
@@ -260,7 +254,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
260254
}
261255
}
262256

263-
// Fetch chat config on mount and generate new conversation ID
264257
useEffect(() => {
265258
fetchChatConfig()
266259
setConversationId(uuidv4())
@@ -285,7 +278,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
285278
}, 800)
286279
}
287280

288-
// Handle sending a message
289281
const handleSendMessage = async (
290282
messageParam?: string,
291283
isVoiceInput = false,
@@ -308,7 +300,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
308300
filesCount: files?.length,
309301
})
310302

311-
// Reset userHasScrolled when sending a new message
312303
setUserHasScrolled(false)
313304

314305
const userMessage: ChatMessage = {
@@ -325,24 +316,20 @@ export default function ChatClient({ identifier }: { identifier: string }) {
325316
})),
326317
}
327318

328-
// Add the user's message to the chat
329319
setMessages((prev) => [...prev, userMessage])
330320
setInputValue('')
331321
setIsLoading(true)
332322

333-
// Scroll to show only the user's message and loading indicator
334323
setTimeout(() => {
335324
scrollToMessage(userMessage.id, true)
336325
}, 100)
337326

338-
// Create abort controller for request cancellation
339327
const abortController = new AbortController()
340328
const timeoutId = setTimeout(() => {
341329
abortController.abort()
342330
}, CHAT_REQUEST_TIMEOUT_MS)
343331

344332
try {
345-
// Send structured payload to maintain chat context
346333
const payload: any = {
347334
input:
348335
typeof userMessage.content === 'string'
@@ -351,7 +338,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
351338
conversationId,
352339
}
353340

354-
// Add files if present (convert to base64 for JSON transmission)
355341
if (files && files.length > 0) {
356342
payload.files = await Promise.all(
357343
files.map(async (file) => ({
@@ -379,7 +365,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
379365
signal: abortController.signal,
380366
})
381367

382-
// Clear timeout since request succeeded
383368
clearTimeout(timeoutId)
384369

385370
if (!response.ok) {
@@ -392,7 +377,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
392377
throw new Error('Response body is missing')
393378
}
394379

395-
// Use the streaming hook with audio support
396380
const shouldPlayAudio = isVoiceInput || isVoiceFirstMode
397381
const audioHandler = shouldPlayAudio
398382
? createAudioStreamHandler(
@@ -421,7 +405,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
421405
}
422406
)
423407
} catch (error: any) {
424-
// Clear timeout in case of error
425408
clearTimeout(timeoutId)
426409

427410
if (error.name === 'AbortError') {
@@ -442,7 +425,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
442425
}
443426
}
444427

445-
// Stop audio when component unmounts or when streaming is stopped
446428
useEffect(() => {
447429
return () => {
448430
stopAudio()
@@ -452,28 +434,23 @@ export default function ChatClient({ identifier }: { identifier: string }) {
452434
}
453435
}, [stopAudio])
454436

455-
// Voice interruption - stop audio when user starts speaking
456437
const handleVoiceInterruption = useCallback(() => {
457438
stopAudio()
458439

459-
// Stop any ongoing streaming response
460440
if (isStreamingResponse) {
461441
stopStreaming(setMessages)
462442
}
463443
}, [isStreamingResponse, stopStreaming, setMessages, stopAudio])
464444

465-
// Handle voice mode activation
466445
const handleVoiceStart = useCallback(() => {
467446
setIsVoiceFirstMode(true)
468447
}, [])
469448

470-
// Handle exiting voice mode
471449
const handleExitVoiceMode = useCallback(() => {
472450
setIsVoiceFirstMode(false)
473-
stopAudio() // Stop any playing audio when exiting
451+
stopAudio()
474452
}, [stopAudio])
475453

476-
// Handle voice transcript from voice-first interface
477454
const handleVoiceTranscript = useCallback(
478455
(transcript: string) => {
479456
logger.info('Received voice transcript:', transcript)
@@ -482,14 +459,11 @@ export default function ChatClient({ identifier }: { identifier: string }) {
482459
[handleSendMessage]
483460
)
484461

485-
// If error, show error message using the extracted component
486462
if (error) {
487463
return <ChatErrorState error={error} starCount={starCount} />
488464
}
489465

490-
// If authentication is required, use the extracted components
491466
if (authRequired) {
492-
// Get title and description from the URL params or use defaults
493467
const title = new URLSearchParams(window.location.search).get('title') || 'chat'
494468
const primaryColor =
495469
new URLSearchParams(window.location.search).get('color') || 'var(--brand-primary-hover-hex)'
@@ -526,12 +500,10 @@ export default function ChatClient({ identifier }: { identifier: string }) {
526500
}
527501
}
528502

529-
// Loading state while fetching config using the extracted component
530503
if (!chatConfig) {
531504
return <ChatLoadingState />
532505
}
533506

534-
// Voice-first mode interface
535507
if (isVoiceFirstMode) {
536508
return (
537509
<VoiceInterface
@@ -551,7 +523,6 @@ export default function ChatClient({ identifier }: { identifier: string }) {
551523
)
552524
}
553525

554-
// Standard text-based chat interface
555526
return (
556527
<div className='fixed inset-0 z-[100] flex flex-col bg-white text-foreground'>
557528
{/* Header component */}

0 commit comments

Comments
 (0)