1- import React , { useState , useRef , useEffect , useMemo } from 'react'
1+ import React , { useState , useRef , useEffect } from 'react'
22import { makeStyles } from '@material-ui/core'
33import SendRoundedIcon from '@material-ui/icons/SendRounded' ;
44import IconButton from "@material-ui/core/IconButton" ;
55import { TextField } from '@postgres.ai/shared/components/TextField'
6+ import { ReadyState } from "react-use-websocket" ;
7+ import { useLocation } from "react-router-dom" ;
68import {
79 checkIsSendCmd ,
810 checkIsNewLineCmd ,
@@ -15,7 +17,6 @@ import { useCaret } from './useCaret'
1517import { theme } from "@postgres.ai/shared/styles/theme" ;
1618import { isMobileDevice } from "../../../utils/utils" ;
1719import { useAiBot } from "../hooks" ;
18- import { ReadyState } from "react-use-websocket" ;
1920
2021type Props = {
2122 threadId ?: string
@@ -103,6 +104,8 @@ export const Command = React.memo((props: Props) => {
103104 // Input caret.
104105 const caret = useCaret ( inputRef )
105106
107+ let location = useLocation < { skipReloading ?: boolean } > ( ) ;
108+
106109 const onSend = async ( message : string ) => {
107110 await sendMessage ( {
108111 content : message ,
@@ -186,11 +189,11 @@ export const Command = React.memo((props: Props) => {
186189 // Skip other keyboard events to fill input.
187190 }
188191
189- // Autofocus.
192+ // Autofocus and clear on thread changed
190193 useEffect ( ( ) => {
191194 if ( ! inputRef . current ) return
192195 if ( window . innerWidth > theme . breakpoints . values . md ) inputRef . current . focus ( )
193- setValue ( '' )
196+ if ( ! location . state ?. skipReloading ) setValue ( '' )
194197 } , [ threadId ] ) ;
195198
196199 return (
0 commit comments