fix: better sentinel
This commit is contained in:
parent
aff0007c23
commit
27b3451ad7
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user