Skip to content

Commit 383aa49

Browse files
author
Bogdan Tsechoev
committed
Merge branch 'bot_ui_prevent_input_clear' into 'master'
Bot UI: Prevents clearing the input field after streaming when creating a chat See merge request postgres-ai/database-lab!898
2 parents 9aa0ec9 + 90971ed commit 383aa49

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ui/packages/platform/src/pages/Bot/Command/Command.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React, { useState, useRef, useEffect, useMemo } from 'react'
1+
import React, { useState, useRef, useEffect } from 'react'
22
import { makeStyles } from '@material-ui/core'
33
import SendRoundedIcon from '@material-ui/icons/SendRounded';
44
import IconButton from "@material-ui/core/IconButton";
55
import { TextField } from '@postgres.ai/shared/components/TextField'
6+
import { ReadyState } from "react-use-websocket";
7+
import { useLocation } from "react-router-dom";
68
import {
79
checkIsSendCmd,
810
checkIsNewLineCmd,
@@ -15,7 +17,6 @@ import { useCaret } from './useCaret'
1517
import { theme } from "@postgres.ai/shared/styles/theme";
1618
import { isMobileDevice } from "../../../utils/utils";
1719
import { useAiBot } from "../hooks";
18-
import { ReadyState } from "react-use-websocket";
1920

2021
type 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

Comments
 (0)