Skip to content

Commit 5f70daf

Browse files
Romaric MourguesLabels Bot
authored andcommitted
🛠 Fix infinite calls when scrolling down
1 parent 0881795 commit 5f70daf

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

twake/frontend/src/app/views/applications/messages/list-builder.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ export default React.memo(
6363
useEffect(() => {
6464
// Detect append or prepend or full replace items
6565
const ids = items.map(i => itemId(i));
66+
//Find the first index in props _items that is already in displayed items
6667
const first = _items.findIndex(i => ids.includes(itemId(i)));
67-
const last =
68-
_items.length -
69-
1 -
70-
_items.findIndex((_, i) => ids.includes(itemId(_items[_items.length - 1 - i])));
68+
//Find the last index in props _items that is already in displayed items
69+
const lastIndex = _items
70+
.slice()
71+
.reverse()
72+
.findIndex(i => ids.includes(itemId(i)));
73+
const last = lastIndex >= 0 ? _items.length - 1 - lastIndex : lastIndex;
7174
if (first == -1) {
7275
//Replacement
7376
setFirstItemIndex(START_INDEX);

twake/frontend/src/app/views/applications/messages/messages-list.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import RouterServices from 'app/features/router/services/router-service';
2020
import GoToBottom from './parts/go-to-bottom';
2121
import { MessagesPlaceholder } from './placeholder';
2222
import { cleanFrontMessagesFromListOfMessages } from 'app/features/messages/hooks/use-message-editor';
23+
import { getMessage } from 'app/features/messages/hooks/use-message';
2324

2425
type Props = {
2526
companyId: string;
@@ -177,7 +178,7 @@ export default ({ channelId, companyId, workspaceId, threadId }: Props) => {
177178
filterOnAppend={messages => {
178179
return cleanFrontMessagesFromListOfMessages(messages);
179180
}}
180-
itemId={m => m.type + m.threadId}
181+
itemId={m => m.type + (getMessage(m.id)?.context?._front_id || m.threadId)}
181182
emptyListComponent={<FirstMessage />}
182183
itemContent={row}
183184
followOutput={!!window.reachedEnd && 'smooth'}

twake/frontend/src/app/views/applications/messages/thread-messages-list.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { VirtuosoHandle } from 'react-virtuoso';
1414
import GoToBottom from './parts/go-to-bottom';
1515
import { MessagesPlaceholder } from './placeholder';
1616
import { cleanFrontMessagesFromListOfMessages } from 'app/features/messages/hooks/use-message-editor';
17+
import { getMessage } from 'app/features/messages/hooks/use-message';
1718

1819
type Props = {
1920
companyId: string;
@@ -111,7 +112,7 @@ export default ({ companyId, threadId }: Props) => {
111112
cancelHighlight();
112113
}}
113114
items={messages}
114-
itemId={m => m.type + m.id}
115+
itemId={m => m.type + (getMessage(m.id)?.context?._front_id || m.id)}
115116
emptyListComponent={<FirstThreadMessage noReplies />}
116117
filterOnAppend={messages => {
117118
return cleanFrontMessagesFromListOfMessages(messages);

0 commit comments

Comments
 (0)