@@ -11,111 +11,27 @@ import { InlineChatHeader } from "./InlineChatHeader";
11
11
import { ChatInput } from "./ChatInput" ;
12
12
13
13
export const ChatMode = ( ) => {
14
- const { props, modalRef, minHeight, resetHeight, addHeight } =
15
- useModalState ( ) ;
14
+ const { props, modalRef } = useModalState ( ) ;
16
15
const { messages } = useChatState ( ) ;
17
16
18
17
const actualChatRef = useRef < HTMLDivElement > ( null ) ;
19
- const rulerRef = useRef < HTMLDivElement > ( null ) ;
20
18
21
19
const [ ref , { entry } ] = useIntersectionObserver ( ) ;
22
20
const isOnScreen = entry && entry . isIntersecting ;
23
21
24
- const onMessageSend = ( ) => {
25
- setTimeout ( ( ) => {
26
- if ( ! actualChatRef . current || ! modalRef . current ) {
27
- return ;
28
- }
29
-
30
- const userMessages = actualChatRef . current . querySelectorAll (
31
- ".user-message-container" ,
32
- ) ;
33
- if ( userMessages . length === 0 ) {
34
- return ;
35
- }
36
-
37
- const lastUserMessage = userMessages [ userMessages . length - 1 ] ;
38
-
39
- const messageRect = lastUserMessage . getBoundingClientRect ( ) ;
40
- const containerRect = modalRef . current . getBoundingClientRect ( ) ;
41
-
42
- const bufferSpace = 20 ;
43
-
44
- const scrollTo =
45
- messageRect . top -
46
- containerRect . top +
47
- modalRef . current . scrollTop -
48
- bufferSpace ;
49
-
50
- handleHeightAddition ( ) ;
51
-
52
- setTimeout ( ( ) => {
53
- if ( ! modalRef . current ) {
54
- return ;
55
- }
56
- modalRef . current . scrollTo ( {
57
- top : scrollTo ,
58
- behavior : "smooth" ,
59
- } ) ;
60
- } , 30 ) ; // 30 used for consistency with react-dom updates
61
- } , 100 ) ;
62
- } ;
63
-
64
- const calculateHeightToAdd = ( ) => {
65
- if ( ! modalRef . current || ! actualChatRef . current ) {
66
- return 0 ;
67
- }
68
- if ( ! rulerRef . current ) {
69
- return 0 ;
70
- }
71
-
72
- const userMessages = actualChatRef . current . querySelectorAll (
73
- ".user-message-container" ,
74
- ) ;
75
- if ( userMessages . length === 0 ) {
76
- return 0 ;
77
- }
78
-
79
- const lastUserMessage = userMessages [ userMessages . length - 1 ] ;
80
-
81
- const messageRect = lastUserMessage . getBoundingClientRect ( ) ;
82
-
83
- const scrollContainerVisibleHeight = modalRef . current . clientHeight ;
84
- const messageRectYDistance =
85
- messageRect . top +
86
- modalRef . current . scrollTop +
87
- lastUserMessage . scrollHeight ;
88
-
89
- const redLead = rulerRef . current . scrollHeight - messageRectYDistance ;
90
-
91
- const targetGap =
92
- scrollContainerVisibleHeight - lastUserMessage . scrollHeight ;
93
-
94
- const heightToAdd = targetGap - redLead ;
95
- return heightToAdd - 80 ;
96
- } ;
97
-
98
- const handleHeightAddition = ( ) => {
99
- const height = calculateHeightToAdd ( ) ;
100
- addHeight ( height ) ;
101
- } ;
102
-
103
22
return (
104
23
< Suspense >
105
- { props . previewTopicId == undefined && (
106
- < InlineChatHeader resetHeight = { resetHeight } />
107
- ) }
24
+ { props . previewTopicId == undefined && < InlineChatHeader /> }
108
25
< div
109
26
ref = { modalRef }
110
27
className = "chat-modal-wrapper tv-justify-items-stretch tv-flex-grow tv-pt-3 tv-pb-2 tv-px-2 tv-relative tv-overflow-y-auto tv-flex tv-overflow-x-hidden"
111
28
>
112
- < ChatRuler rulerRef = { rulerRef } minHeight = { minHeight } />
113
29
< div
114
30
className = "tv-flex-col tv-h-full tv-grow tv-flex tv-gap-4 tv-max-w-full"
115
31
ref = { actualChatRef }
116
32
>
117
33
{ /* Only shows with zero messages */ }
118
- < SuggestedQuestions onMessageSend = { onMessageSend } /> { " " }
34
+ < SuggestedQuestions onMessageSend = { ( ) => { } } /> { " " }
119
35
{ messages . map ( ( message , i ) => {
120
36
if ( message . type === "user" ) {
121
37
return < UserMessage key = { i } message = { message } idx = { i } /> ;
@@ -130,28 +46,9 @@ export const ChatMode = () => {
130
46
> </ div >
131
47
</ div >
132
48
</ div >
133
- < ChatInput onMessageSend = { onMessageSend } showShadow = { ! isOnScreen } />
49
+ < ChatInput onMessageSend = { ( ) => { } } showShadow = { ! isOnScreen } />
134
50
</ Suspense >
135
51
) ;
136
52
} ;
137
53
138
- // sits on the left side of chat in a flexbox to enforce the minimum height and control scroll
139
- const ChatRuler = ( {
140
- minHeight,
141
- rulerRef,
142
- } : {
143
- minHeight : number ;
144
- rulerRef : React . RefObject < HTMLDivElement > ;
145
- } ) => {
146
- return (
147
- < div
148
- ref = { rulerRef }
149
- className = "tv-min-w-[1px]"
150
- style = { {
151
- minHeight,
152
- } }
153
- > </ div >
154
- ) ;
155
- } ;
156
-
157
54
export default ChatMode ;
0 commit comments