1
- import React , { useState , useRef , useEffect , useMemo } from 'react'
1
+ import React , { useState , useRef , useEffect } from 'react'
2
2
import { makeStyles } from '@material-ui/core'
3
3
import SendRoundedIcon from '@material-ui/icons/SendRounded' ;
4
4
import IconButton from "@material-ui/core/IconButton" ;
5
5
import { TextField } from '@postgres.ai/shared/components/TextField'
6
+ import { ReadyState } from "react-use-websocket" ;
7
+ import { useLocation } from "react-router-dom" ;
6
8
import {
7
9
checkIsSendCmd ,
8
10
checkIsNewLineCmd ,
@@ -15,7 +17,6 @@ import { useCaret } from './useCaret'
15
17
import { theme } from "@postgres.ai/shared/styles/theme" ;
16
18
import { isMobileDevice } from "../../../utils/utils" ;
17
19
import { useAiBot } from "../hooks" ;
18
- import { ReadyState } from "react-use-websocket" ;
19
20
20
21
type Props = {
21
22
threadId ?: string
@@ -103,6 +104,8 @@ export const Command = React.memo((props: Props) => {
103
104
// Input caret.
104
105
const caret = useCaret ( inputRef )
105
106
107
+ let location = useLocation < { skipReloading ?: boolean } > ( ) ;
108
+
106
109
const onSend = async ( message : string ) => {
107
110
await sendMessage ( {
108
111
content : message ,
@@ -186,11 +189,11 @@ export const Command = React.memo((props: Props) => {
186
189
// Skip other keyboard events to fill input.
187
190
}
188
191
189
- // Autofocus.
192
+ // Autofocus and clear on thread changed
190
193
useEffect ( ( ) => {
191
194
if ( ! inputRef . current ) return
192
195
if ( window . innerWidth > theme . breakpoints . values . md ) inputRef . current . focus ( )
193
- setValue ( '' )
196
+ if ( ! location . state ?. skipReloading ) setValue ( '' )
194
197
} , [ threadId ] ) ;
195
198
196
199
return (
0 commit comments