Skip to content

Commit

Permalink
fix: message list scrolling was jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
raaymax committed Feb 3, 2024
1 parent 609c619 commit c582d2c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/app/src/js/components/Conversation/conversation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function Conversation() {
status={status}
selected={stream.selected}
onDateChange={(date) => setStream({ ...stream, date })}
onScrollTop={() => {
prev();
onScrollTop={async () => {
await prev();
setStream({...stream, type: 'archive', selected: undefined});
bumpProgress();
}}
Expand Down
7 changes: 4 additions & 3 deletions packages/app/src/js/components/MessageList/MessageList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const MessageList = (props) => {
});
if (r) {
const date = r.getAttribute('data-date');
if (setCurrent) setCurrent([date, r])
if (setCurrent) {
setCurrent([date, r.getBoundingClientRect()]);
}
if (onDateChange) onDateChange(date);
}
}, [setCurrent, onDateChange]);
Expand All @@ -64,9 +66,8 @@ export const MessageList = (props) => {
} else if (rect && current && current[1]?.y) {
element.current.scrollTop += (rect.y - current[1].y);
}
setCurrent([current[0], rect]);
}
const rect = getRect();
setCurrent([current[0], rect]);
setOldList(list);
}, [list, stream, oldList, setOldList, current, setCurrent]);

Expand Down
7 changes: 4 additions & 3 deletions packages/app/src/js/services/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const selectors = {
};

export const loadPrevious = (stream) => async (dispatch, getState) => {
if (getState().messages.loading) return;
const loadingDone = loading(dispatch, getState);
const date = selectors.getEarliestDate(stream, getState());

Expand All @@ -45,12 +46,13 @@ export const loadPrevious = (stream) => async (dispatch, getState) => {
if (selectors.countMessagesInStream(stream, getState()) > 100) {
setTimeout(() => {
dispatch.actions.messages.takeOldest({ stream, count: 100 });
}, 1);
}, 10);
}
loadingDone();
};

export const loadNext = (stream) => async (dispatch, getState) => {
if (getState().messages.loading) return;
const loadingDone = loading(dispatch, getState);
const date = selectors.getLatestDate(stream, getState());

Expand All @@ -61,11 +63,10 @@ export const loadNext = (stream) => async (dispatch, getState) => {
if (messages?.length > 0) {
dispatch.methods.progress.update(messages[0].id);
}

if (selectors.countMessagesInStream(stream, getState()) > 100) {
setTimeout(() => {
dispatch.actions.messages.takeYoungest({ stream, count: 100 });
}, 1);
}, 10);
}
loadingDone();
return messages.length
Expand Down

0 comments on commit c582d2c

Please sign in to comment.