Highlight the selected conversation when filter by unread is enabled
This commit is contained in:
parent
a2bbfd9496
commit
e27b99aa61
2 changed files with 94 additions and 3 deletions
|
@ -26,6 +26,7 @@ import type { GetConversationByIdType } from './conversations';
|
||||||
import {
|
import {
|
||||||
getConversationLookup,
|
getConversationLookup,
|
||||||
getConversationSelector,
|
getConversationSelector,
|
||||||
|
getSelectedConversationId,
|
||||||
} from './conversations';
|
} from './conversations';
|
||||||
|
|
||||||
import { hydrateRanges } from '../../types/BodyRange';
|
import { hydrateRanges } from '../../types/BodyRange';
|
||||||
|
@ -113,11 +114,17 @@ export const getMessageSearchResultLookup = createSelector(
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getSearchResults = createSelector(
|
export const getSearchResults = createSelector(
|
||||||
[getSearch, getSearchConversationName, getConversationLookup],
|
[
|
||||||
|
getSearch,
|
||||||
|
getSearchConversationName,
|
||||||
|
getConversationLookup,
|
||||||
|
getSelectedConversationId,
|
||||||
|
],
|
||||||
(
|
(
|
||||||
state: SearchStateType,
|
state: SearchStateType,
|
||||||
searchConversationName,
|
searchConversationName,
|
||||||
conversationLookup: ConversationLookupType
|
conversationLookup: ConversationLookupType,
|
||||||
|
selectedConversationId: string | undefined
|
||||||
): Pick<
|
): Pick<
|
||||||
LeftPaneSearchPropsType,
|
LeftPaneSearchPropsType,
|
||||||
| 'conversationResults'
|
| 'conversationResults'
|
||||||
|
@ -136,7 +143,7 @@ export const getSearchResults = createSelector(
|
||||||
messagesLoading,
|
messagesLoading,
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
return {
|
const searchResults: ReturnType<typeof getSearchResults> = {
|
||||||
conversationResults: discussionsLoading
|
conversationResults: discussionsLoading
|
||||||
? { isLoading: true }
|
? { isLoading: true }
|
||||||
: {
|
: {
|
||||||
|
@ -159,6 +166,21 @@ export const getSearchResults = createSelector(
|
||||||
searchTerm: state.query,
|
searchTerm: state.query,
|
||||||
filterByUnread: state.filterByUnread,
|
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;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -454,5 +454,74 @@ describe('both/state/selectors/search', () => {
|
||||||
filterByUnread: false,
|
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,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue