Highlight the selected conversation when filter by unread is enabled

Co-authored-by: yash-signal <yash@signal.org>
This commit is contained in:
automated-signal 2024-12-02 20:08:52 -06:00 committed by GitHub
parent 054f50bcd4
commit cbeb51a68b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 94 additions and 3 deletions

View file

@ -26,6 +26,7 @@ import type { GetConversationByIdType } from './conversations';
import {
getConversationLookup,
getConversationSelector,
getSelectedConversationId,
} from './conversations';
import { hydrateRanges } from '../../types/BodyRange';
@ -113,11 +114,17 @@ export const getMessageSearchResultLookup = createSelector(
);
export const getSearchResults = createSelector(
[getSearch, getSearchConversationName, getConversationLookup],
[
getSearch,
getSearchConversationName,
getConversationLookup,
getSelectedConversationId,
],
(
state: SearchStateType,
searchConversationName,
conversationLookup: ConversationLookupType
conversationLookup: ConversationLookupType,
selectedConversationId: string | undefined
): Pick<
LeftPaneSearchPropsType,
| 'conversationResults'
@ -136,7 +143,7 @@ export const getSearchResults = createSelector(
messagesLoading,
} = state;
return {
const searchResults: ReturnType<typeof getSearchResults> = {
conversationResults: discussionsLoading
? { isLoading: true }
: {
@ -159,6 +166,21 @@ export const getSearchResults = createSelector(
searchTerm: state.query,
filterByUnread: state.filterByUnread,
};
if (
state.filterByUnread &&
searchResults.conversationResults.isLoading === false
) {
searchResults.conversationResults.results =
searchResults.conversationResults.results.map(conversation => {
return {
...conversation,
isSelected: selectedConversationId === conversation.id,
};
});
}
return searchResults;
}
);

View file

@ -454,5 +454,74 @@ describe('both/state/selectors/search', () => {
filterByUnread: false,
});
});
it('adds isSelected flag to conversations when filterByUnread is true', () => {
const conversations: Array<ConversationType> = [
getDefaultConversation({ id: '1' }),
getDefaultConversation({ id: 'selected-id' }),
];
const state: StateType = {
...getEmptyRootState(),
conversations: {
...getEmptyConversationState(),
conversationLookup: makeLookup(conversations, 'id'),
selectedConversationId: 'selected-id',
},
search: {
...getEmptySearchState(),
query: 'foo bar',
conversationIds: conversations.map(({ id }) => id),
discussionsLoading: false,
filterByUnread: true,
},
};
const searchResults = getSearchResults(state);
assert.deepEqual(searchResults.conversationResults, {
isLoading: false,
results: [
{
...conversations[0],
isSelected: false,
},
{
...conversations[1],
isSelected: true,
},
],
});
});
it('does not add isSelected flag to conversations when filterByUnread is false', () => {
const conversations: Array<ConversationType> = [
getDefaultConversation({ id: '1' }),
getDefaultConversation({ id: '2' }),
];
const state: StateType = {
...getEmptyRootState(),
conversations: {
...getEmptyConversationState(),
conversationLookup: makeLookup(conversations, 'id'),
selectedConversationId: '2',
},
search: {
...getEmptySearchState(),
query: 'foo bar',
conversationIds: conversations.map(({ id }) => id),
discussionsLoading: false,
filterByUnread: false,
},
};
const searchResults = getSearchResults(state);
assert.deepEqual(searchResults.conversationResults, {
isLoading: false,
results: conversations,
});
});
});
});