feat: getConversationQuotes selector for memoising quotes lookup state

This commit is contained in:
William Grant 2023-05-15 14:30:11 +10:00
parent e90e548715
commit aa3855e49f

View file

@ -9,6 +9,7 @@ import {
MessageModelPropsWithoutConvoProps,
MessagePropsDetails,
PropsForQuote,
QuoteLookupType,
ReduxConversationType,
SortedMessageModelProps,
} from '../ducks/conversations';
@ -56,6 +57,13 @@ export const getConversationsCount = createSelector(getConversationLookup, (stat
return Object.values(state).length;
});
export const getConversationQuotes = createSelector(
getConversations,
(state: ConversationsStateType): QuoteLookupType | undefined => {
return state.quotes;
}
);
export const getSelectedConversationKey = createSelector(
getConversations,
(state: ConversationsStateType): string | undefined => {
@ -973,10 +981,10 @@ export const getMessageLinkPreviewProps = createSelector(getMessagePropsByMessag
});
export const getMessageQuoteProps = createSelector(
getConversations,
getConversationQuotes,
getMessagePropsByMessageId,
(convosProps, msgProps) => {
if (!convosProps || isEmpty(convosProps) || !msgProps || isEmpty(msgProps)) {
(quotesProps, msgProps) => {
if (!msgProps || isEmpty(msgProps)) {
return undefined;
}
@ -990,7 +998,12 @@ export const getMessageQuoteProps = createSelector(
return undefined;
}
const sourceMessage = convosProps.quotes[`${messageId}-${sender}`];
// NOTE: if the message is not found, we still want to render the quote
if (!quotesProps || isEmpty(quotesProps)) {
return { direction, quote: { sender, referencedMessageNotFound: true } };
}
const sourceMessage = quotesProps[`${messageId}-${sender}`];
if (!sourceMessage) {
return { direction, quote: { sender, referencedMessageNotFound: true } };
}