Avoid repeated scollToMessage actions

This commit is contained in:
trevor-signal 2024-03-18 12:22:06 -04:00 committed by GitHub
parent 11ea595457
commit d2d2a230b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,7 +45,7 @@ export const SmartChatsTab = memo(function SmartChatsTab() {
const hasPendingUpdate = useSelector(getHasPendingUpdate); const hasPendingUpdate = useSelector(getHasPendingUpdate);
const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats); const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats);
const selectedConversationId = useSelector(getSelectedConversationId); const selectedConversationId = useSelector(getSelectedConversationId);
const targetedMessage = useSelector(getTargetedMessage); const targetedMessageId = useSelector(getTargetedMessage)?.id;
const targetedMessageSource = useSelector(getTargetedMessageSource); const targetedMessageSource = useSelector(getTargetedMessageSource);
const { const {
@ -64,16 +64,16 @@ export const SmartChatsTab = memo(function SmartChatsTab() {
if (selectedConversationId !== lastOpenedConversationId.current) { if (selectedConversationId !== lastOpenedConversationId.current) {
lastOpenedConversationId.current = selectedConversationId; lastOpenedConversationId.current = selectedConversationId;
if (selectedConversationId) { if (selectedConversationId) {
onConversationOpened(selectedConversationId, targetedMessage?.id); onConversationOpened(selectedConversationId, targetedMessageId);
} }
} else if ( } else if (
selectedConversationId && selectedConversationId &&
targetedMessage && targetedMessageId &&
targetedMessageSource !== TargetedMessageSource.Focus targetedMessageSource !== TargetedMessageSource.Focus
) { ) {
scrollToMessage(selectedConversationId, targetedMessage?.id); scrollToMessage(selectedConversationId, targetedMessageId);
} }
}, [onConversationOpened, selectedConversationId, scrollToMessage, targetedMessage, targetedMessageSource]); }, [onConversationOpened, selectedConversationId, scrollToMessage, targetedMessageId, targetedMessageSource]);
const prevConversationId = usePrevious( const prevConversationId = usePrevious(
selectedConversationId, selectedConversationId,