feat: auto-scroll to bottom on new messages, return null for empty suggestions
- Added functionality to automatically scroll to the bottom of the messages container upon receiving new messages. - Return null when suggestions list is empty instead of displaying an empty container.
This commit is contained in:
parent
6aee3d8088
commit
bb137cc799
@ -73,6 +73,7 @@ const Messages: FC<Props> = ({ assistant, topic, setActiveTopic }) => {
|
|||||||
const unsubscribes = [
|
const unsubscribes = [
|
||||||
EventEmitter.on(EVENT_NAMES.SEND_MESSAGE, async (msg: Message) => {
|
EventEmitter.on(EVENT_NAMES.SEND_MESSAGE, async (msg: Message) => {
|
||||||
await onSendMessage(msg)
|
await onSendMessage(msg)
|
||||||
|
containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: 'auto' })
|
||||||
fetchChatCompletion({
|
fetchChatCompletion({
|
||||||
assistant,
|
assistant,
|
||||||
messages: [...messages, msg],
|
messages: [...messages, msg],
|
||||||
@ -173,10 +174,6 @@ const Messages: FC<Props> = ({ assistant, topic, setActiveTopic }) => {
|
|||||||
})
|
})
|
||||||
}, [topic.id])
|
}, [topic.id])
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// setTimeout(() => containerRef.current?.scrollTo({ top: containerRef.current.scrollHeight, behavior: 'auto' }), 0)
|
|
||||||
// }, [messages])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
runAsyncFunction(async () => {
|
runAsyncFunction(async () => {
|
||||||
EventEmitter.emit(EVENT_NAMES.ESTIMATED_TOKEN_COUNT, {
|
EventEmitter.emit(EVENT_NAMES.ESTIMATED_TOKEN_COUNT, {
|
||||||
@ -207,6 +204,7 @@ const Container = styled.div`
|
|||||||
max-height: calc(100vh - var(--input-bar-height) - var(--navbar-height));
|
max-height: calc(100vh - var(--input-bar-height) - var(--navbar-height));
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
background-color: var(--color-background);
|
background-color: var(--color-background);
|
||||||
|
padding-bottom: 20px;
|
||||||
`
|
`
|
||||||
|
|
||||||
export default Messages
|
export default Messages
|
||||||
|
|||||||
@ -67,7 +67,7 @@ const Suggestions: FC<Props> = ({ assistant, messages, lastMessage }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (suggestions.length === 0) {
|
if (suggestions.length === 0) {
|
||||||
return <Container style={{ paddingBottom: 10 }} />
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user