Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'
import { useCallback, useLayoutEffect, useRef } from 'react'
import { cn } from '@/lib/core/utils/cn'
import { MessageActions } from '@/app/workspace/[workspaceId]/components'
import { ChatMessageAttachments } from '@/app/workspace/[workspaceId]/home/components/chat-message-attachments'
Expand Down Expand Up @@ -99,41 +99,16 @@ export function MothershipChat({
const hasMessages = messages.length > 0
const initialScrollDoneRef = useRef(false)

const primedQueueIdRef = useRef<string | null>(null)
const primeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const messageQueueRef = useRef(messageQueue)
messageQueueRef.current = messageQueue
const onSendQueuedMessageRef = useRef(onSendQueuedMessage)
onSendQueuedMessageRef.current = onSendQueuedMessage

const clearPrimed = useCallback(() => {
primedQueueIdRef.current = null
if (primeTimerRef.current) {
clearTimeout(primeTimerRef.current)
primeTimerRef.current = null
}
}, [])

const handleEnterWhileEmpty = useCallback(() => {
const topMessage = messageQueueRef.current[0]
if (!topMessage) return false

if (primedQueueIdRef.current === topMessage.id) {
clearPrimed()
void onSendQueuedMessageRef.current(topMessage.id)
return true
}

primedQueueIdRef.current = topMessage.id
if (primeTimerRef.current) clearTimeout(primeTimerRef.current)
primeTimerRef.current = setTimeout(clearPrimed, 3000)
void onSendQueuedMessageRef.current(topMessage.id)
return true
}, [clearPrimed])

useEffect(() => {
return () => {
if (primeTimerRef.current) clearTimeout(primeTimerRef.current)
}
}, [])

useLayoutEffect(() => {
Expand Down Expand Up @@ -235,7 +210,6 @@ export function MothershipChat({
editValue={editValue}
onEditValueConsumed={onEditValueConsumed}
onEnterWhileEmpty={handleEnterWhileEmpty}
onPrimedDismiss={clearPrimed}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ interface UserInputProps {
userId?: string
onContextAdd?: (context: ChatContext) => void
onEnterWhileEmpty?: () => boolean
onPrimedDismiss?: () => void
}

export function UserInput({
Expand All @@ -123,7 +122,6 @@ export function UserInput({
userId,
onContextAdd,
onEnterWhileEmpty,
onPrimedDismiss,
}: UserInputProps) {
const { workspaceId } = useParams<{ workspaceId: string }>()
const { data: workflowsById = {} } = useWorkflowMap(workspaceId)
Expand Down Expand Up @@ -456,7 +454,8 @@ export function UserInput({
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
e.preventDefault()
if (isSendingRef.current && !valueRef.current.trim() && onEnterWhileEmptyRef.current?.()) {
if (isSendingRef.current && !valueRef.current.trim()) {
onEnterWhileEmptyRef.current?.()
return
}
handleSubmit()
Expand Down Expand Up @@ -551,9 +550,8 @@ export function UserInput({

setValue(newValue)
restartRecognition(newValue)
if (newValue.trim()) onPrimedDismiss?.()
},
[restartRecognition, onPrimedDismiss]
[restartRecognition]
)

const handleSelectAdjust = useCallback(() => {
Expand Down
Loading