1
- import { Button , Flex , Tooltip } from "antd" ;
1
+ import { Button , Flex , Space , Tooltip } from "antd" ;
2
2
import { debounce } from "lodash" ;
3
- import { CSSProperties , useCallback , useEffect , useRef } from "react" ;
4
-
3
+ import { CSSProperties , useCallback , useEffect , useRef , useState } from "react" ;
5
4
import {
6
5
redux ,
7
6
useActions ,
@@ -31,6 +30,7 @@ interface Props {
31
30
export default function SideChat ( { project_id, path, style } : Props ) {
32
31
const actions : ChatActions = useActions ( project_id , path ) ;
33
32
const messages = useRedux ( [ "messages" ] , project_id , path ) ;
33
+ const [ lastVisible , setLastVisible ] = useState < Date | null > ( null ) ;
34
34
const input : string = useRedux ( [ "input" ] , project_id , path ) ;
35
35
const search : string = useRedux ( [ "search" ] , project_id , path ) ;
36
36
const addCollab : boolean = useRedux ( [ "add_collab" ] , project_id , path ) ;
@@ -55,11 +55,21 @@ export default function SideChat({ project_id, path, style }: Props) {
55
55
markAsRead ( ) ;
56
56
} , [ ] ) ;
57
57
58
- const sendChat = useCallback ( ( ) => {
59
- const input = submitMentionsRef . current ?.( ) ;
60
- actions . send_chat ( { input } ) ;
61
- scrollToBottomRef . current ?.( true ) ;
62
- } , [ actions ] ) ;
58
+ const sendChat = useCallback (
59
+ ( options ?) => {
60
+ const input = submitMentionsRef . current ?.( ) ;
61
+ actions . send_chat ( { input, ...options } ) ;
62
+ actions . delete_draft ( 0 ) ;
63
+ scrollToBottomRef . current ?.( true ) ;
64
+ setTimeout ( ( ) => {
65
+ scrollToBottomRef . current ?.( true ) ;
66
+ } , 10 ) ;
67
+ setTimeout ( ( ) => {
68
+ scrollToBottomRef . current ?.( true ) ;
69
+ } , 1000 ) ;
70
+ } ,
71
+ [ actions ] ,
72
+ ) ;
63
73
64
74
if ( messages == null ) {
65
75
return < Loading /> ;
@@ -155,25 +165,38 @@ export default function SideChat({ project_id, path, style }: Props) {
155
165
path = { path }
156
166
scrollToBottomRef = { scrollToBottomRef }
157
167
mode = { "sidechat" }
168
+ setLastVisible = { setLastVisible }
158
169
/>
159
170
</ div >
160
171
161
172
< div >
162
173
{ input . trim ( ) ? (
163
174
< Flex vertical = { false } align = "center" justify = "space-between" >
164
175
< Tooltip title = "Send message (shift+enter)" >
165
- < Button
166
- style = { { margin : "5px 0 5px 5px" } }
167
- onClick = { ( ) => {
168
- sendChat ( ) ;
169
- user_activity ( "side_chat" , "send_chat" , "click" ) ;
170
- } }
171
- disabled = { ! input ?. trim ( ) || is_uploading }
172
- type = "primary"
173
- >
174
- < Icon name = "paper-plane" />
175
- Send
176
- </ Button >
176
+ < Space >
177
+ { lastVisible && (
178
+ < Button
179
+ type = "primary"
180
+ onClick = { ( ) => {
181
+ sendChat ( { reply_to : new Date ( lastVisible ) } ) ;
182
+ } }
183
+ >
184
+ Reply (shift+enter)
185
+ </ Button >
186
+ ) }
187
+ < Button
188
+ type = { ! lastVisible ? "primary" : undefined }
189
+ style = { { margin : "5px 0 5px 5px" } }
190
+ onClick = { ( ) => {
191
+ sendChat ( ) ;
192
+ user_activity ( "side_chat" , "send_chat" , "click" ) ;
193
+ } }
194
+ disabled = { ! input ?. trim ( ) || is_uploading }
195
+ >
196
+ < Icon name = "paper-plane" />
197
+ Start New Conversation
198
+ </ Button >
199
+ </ Space >
177
200
</ Tooltip >
178
201
< LLMCostEstimationChat
179
202
compact
@@ -187,7 +210,7 @@ export default function SideChat({ project_id, path, style }: Props) {
187
210
cacheId = { `${ path } ${ project_id } -new` }
188
211
input = { input }
189
212
on_send = { ( ) => {
190
- sendChat ( ) ;
213
+ sendChat ( lastVisible ? { reply_to : lastVisible } : undefined ) ;
191
214
user_activity ( "side_chat" , "send_chat" , "keyboard" ) ;
192
215
} }
193
216
style = { { height : INPUT_HEIGHT } }
0 commit comments