|
1 | | -import { memo, useEffect, useState } from 'react' |
| 1 | +import { memo, useEffect, useRef, useState } from 'react' |
2 | 2 | import PropTypes from 'prop-types' |
3 | 3 | import Browser from 'webextension-polyfill' |
4 | 4 | import InputBox from '../InputBox' |
@@ -34,6 +34,7 @@ function ConversationCard(props) { |
34 | 34 | const [port, setPort] = useState(() => Browser.runtime.connect()) |
35 | 35 | const [session, setSession] = useState(props.session) |
36 | 36 | const windowSize = useClampWindowSize([0, Infinity], [250, 1100]) |
| 37 | + const bodyRef = useRef(null) |
37 | 38 | /** |
38 | 39 | * @type {[ConversationItemData[], (conversationItemData: ConversationItemData[]) => void]} |
39 | 40 | */ |
@@ -67,6 +68,10 @@ function ConversationCard(props) { |
67 | 68 | if (props.onUpdate) props.onUpdate() |
68 | 69 | }) |
69 | 70 |
|
| 71 | + useEffect(() => { |
| 72 | + bodyRef.current.scrollTop = bodyRef.current.scrollHeight |
| 73 | + }, [session]) |
| 74 | + |
70 | 75 | useEffect(() => { |
71 | 76 | // when the page is responsive, session may accumulate redundant data and needs to be cleared after remounting and before making a new request |
72 | 77 | if (props.question) { |
@@ -215,7 +220,11 @@ function ConversationCard(props) { |
215 | 220 | </span> |
216 | 221 | </div> |
217 | 222 | <hr /> |
218 | | - <div className="markdown-body" style={{ maxHeight: windowSize[1] * 0.75 + 'px' }}> |
| 223 | + <div |
| 224 | + ref={bodyRef} |
| 225 | + className="markdown-body" |
| 226 | + style={{ maxHeight: windowSize[1] * 0.75 + 'px' }} |
| 227 | + > |
219 | 228 | {conversationItemData.map((data, idx) => ( |
220 | 229 | <ConversationItem |
221 | 230 | content={data.content} |
|
0 commit comments