Skip to content

Commit e821fec

Browse files
Clear queued message input (#74)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 3166575 commit e821fec

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

app/routes/_app+/recipients+/$recipientId.index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,22 @@ export default function RecipientRoute() {
300300
const data = useLoaderData<typeof loader>()
301301
const newMessageFetcher = useFetcher<typeof action>()
302302
const isCreating = newMessageFetcher.state !== 'idle'
303+
const newMessageInputRef = useRef<HTMLTextAreaElement | null>(null)
304+
const shouldClearMessageInput = useRef(false)
305+
306+
useEffect(() => {
307+
if (newMessageFetcher.state !== 'idle') {
308+
shouldClearMessageInput.current = true
309+
return
310+
}
311+
if (!shouldClearMessageInput.current) return
312+
313+
const hasErrors = Boolean(newMessageFetcher.data?.result?.error)
314+
if (!hasErrors && newMessageInputRef.current) {
315+
newMessageInputRef.current.value = ''
316+
}
317+
shouldClearMessageInput.current = false
318+
}, [newMessageFetcher.state, newMessageFetcher.data])
303319

304320
return (
305321
<div className="flex flex-col gap-8">
@@ -341,6 +357,7 @@ export default function RecipientRoute() {
341357
<textarea
342358
id="new-message"
343359
name="content"
360+
ref={newMessageInputRef}
344361
placeholder="Aa"
345362
className="text-foreground placeholder:text-muted-foreground min-h-[44px] flex-1 resize-none rounded-full bg-transparent px-4 py-2 text-sm leading-relaxed focus-visible:outline-none"
346363
rows={1}

0 commit comments

Comments
 (0)