mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-13 22:15:04 +00:00
Implement auto-scroll of the chat list
This commit is contained in:
parent
2d037c3e46
commit
f65d4a20ff
@ -6,7 +6,7 @@ import {
|
|||||||
ListItemText,
|
ListItemText,
|
||||||
Typography,
|
Typography,
|
||||||
} from '@material-ui/core';
|
} from '@material-ui/core';
|
||||||
import React from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import { ChatMessage } from '../../build/main/chat/chat_message';
|
import { ChatMessage } from '../../build/main/chat/chat_message';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -22,7 +22,12 @@ export default function ChatList(props: Props) {
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
));
|
));
|
||||||
|
|
||||||
return <List dense={true}>{listItems}</List>;
|
return (
|
||||||
|
<List dense={true}>
|
||||||
|
{listItems}
|
||||||
|
<AlwaysScrollToBottom messages={messages} />
|
||||||
|
</List>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MessageProps {
|
interface MessageProps {
|
||||||
@ -65,3 +70,15 @@ function Message(props: MessageProps) {
|
|||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AlwaysScrollToBottom = (props: Props) => {
|
||||||
|
const elementRef = useRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
elementRef.current.scrollIntoView();
|
||||||
|
}, [props.messages]);
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
return <div ref={elementRef} />;
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user