(js) Improve auto scroll when no host bubble

Closes #522
This commit is contained in:
Baptiste Arnaud
2023-05-26 18:31:13 +02:00
parent 68f0202601
commit 0ca48e4c08
4 changed files with 9 additions and 3 deletions

View File

@@ -21,13 +21,16 @@ type Props = Pick<ChatReply, 'messages' | 'input'> & {
}
export const ChatChunk = (props: Props) => {
let inputRef: HTMLDivElement | undefined
const [displayedMessageIndex, setDisplayedMessageIndex] = createSignal(0)
onMount(() => {
if (props.messages.length === 0) {
props.onAllBubblesDisplayed()
}
props.onScrollToBottom()
props.onScrollToBottom(
inputRef?.offsetTop ? inputRef?.offsetTop - 50 : undefined
)
})
const displayNextMessage = async (bubbleOffsetTop?: number) => {
@@ -84,6 +87,7 @@ export const ChatChunk = (props: Props) => {
</Show>
{props.input && displayedMessageIndex() === props.messages.length && (
<InputChatBlock
ref={inputRef}
block={props.input}
inputIndex={props.inputIndex}
onSubmit={props.onSubmit}