feat: getConversationQuotes selector for memoising quotes lookup state

pull/2757/head
William Grant 2 years ago
parent e90e548715
commit aa3855e49f

@ -9,6 +9,7 @@ import {
MessageModelPropsWithoutConvoProps, MessageModelPropsWithoutConvoProps,
MessagePropsDetails, MessagePropsDetails,
PropsForQuote, PropsForQuote,
QuoteLookupType,
ReduxConversationType, ReduxConversationType,
SortedMessageModelProps, SortedMessageModelProps,
} from '../ducks/conversations'; } from '../ducks/conversations';
@ -56,6 +57,13 @@ export const getConversationsCount = createSelector(getConversationLookup, (stat
return Object.values(state).length; return Object.values(state).length;
}); });
export const getConversationQuotes = createSelector(
getConversations,
(state: ConversationsStateType): QuoteLookupType | undefined => {
return state.quotes;
}
);
export const getSelectedConversationKey = createSelector( export const getSelectedConversationKey = createSelector(
getConversations, getConversations,
(state: ConversationsStateType): string | undefined => { (state: ConversationsStateType): string | undefined => {
@ -973,10 +981,10 @@ export const getMessageLinkPreviewProps = createSelector(getMessagePropsByMessag
}); });
export const getMessageQuoteProps = createSelector( export const getMessageQuoteProps = createSelector(
getConversations, getConversationQuotes,
getMessagePropsByMessageId, getMessagePropsByMessageId,
(convosProps, msgProps) => { (quotesProps, msgProps) => {
if (!convosProps || isEmpty(convosProps) || !msgProps || isEmpty(msgProps)) { if (!msgProps || isEmpty(msgProps)) {
return undefined; return undefined;
} }
@ -990,7 +998,12 @@ export const getMessageQuoteProps = createSelector(
return undefined; 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) { if (!sourceMessage) {
return { direction, quote: { sender, referencedMessageNotFound: true } }; return { direction, quote: { sender, referencedMessageNotFound: true } };
} }

Loading…
Cancel
Save