Merge pull request #60 from tluyben/firstload-autoscroll2

first load auto scroll to bottom
main
Cogent Apps 2023-04-12 02:38:17 -07:00 committed by GitHub
commit 6fcc7494f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -35,12 +35,14 @@ export default function ChatPage(props: any) {
const { id } = useParams(); const { id } = useParams();
const context = useAppContext(); const context = useAppContext();
let firstLoad = true;
useEffect(() => { useEffect(() => {
if (props.share || !context.currentChat.chatLoadedAt) { if (props.share || !context.currentChat.chatLoadedAt) {
return; return;
} }
const shouldScroll = (Date.now() - context.currentChat.chatLoadedAt) > 5000; const shouldScroll = (Date.now() - context.currentChat.chatLoadedAt) > 5000 || firstLoad;
firstLoad = false;
if (!shouldScroll) { if (!shouldScroll) {
return; return;