fix: better sentinel

This commit is contained in:
cha0s 2020-07-25 09:24:21 -05:00
parent aff0007c23
commit 27b3451ad7

View File

@ -23,7 +23,7 @@ export default function ChatMessages() {
const {current} = $messages; const {current} = $messages;
const [, setIsAtBottom] = useState(true); const [, setIsAtBottom] = useState(true);
const [outerHeight, setOuterHeight] = useState(0); const [outerHeight, setOuterHeight] = useState(0);
const [scrollTop, setScrollTop] = useState(0); const [scrollTop, setScrollTop] = useState(-1);
const [scrollHeight, setScrollHeight] = useState(Infinity); const [scrollHeight, setScrollHeight] = useState(Infinity);
const messages = useSelector((state) => channelMessagesSelector(state, channel)); const messages = useSelector((state) => channelMessagesSelector(state, channel));
const messageCount = messages && messages.length; const messageCount = messages && messages.length;
@ -44,7 +44,7 @@ export default function ChatMessages() {
useLayoutEffect(() => { useLayoutEffect(() => {
const isAtBottom = !current const isAtBottom = !current
? true ? true
: 0 === scrollTop || scrollTop + outerHeight >= scrollHeight; : -1 === scrollTop || scrollTop + outerHeight >= scrollHeight;
setIsAtBottom(isAtBottom); setIsAtBottom(isAtBottom);
if (isAtBottom) { if (isAtBottom) {
current?.scrollTo(0, scrollHeight); current?.scrollTo(0, scrollHeight);