Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Search Page Order #6971

Merged
merged 8 commits into from
Jan 14, 2022
33 changes: 19 additions & 14 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ function getOptions(reports, personalDetails, activeReportID, {
includeRecentReports = false,
prioritizePinnedReports = false,
prioritizeDefaultRoomsInSearch = false,

// When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well.
sortByReportTypeInSearch = false,
sortByLastMessageTimestamp = false,
searchValue = '',
Expand All @@ -371,7 +373,7 @@ function getOptions(reports, personalDetails, activeReportID, {
}) {
let recentReportOptions = [];
const pinnedReportOptions = [];
const personalDetailsOptions = [];
let personalDetailsOptions = [];
const iouDebtReportOptions = [];
const draftReportOptions = [];

Expand Down Expand Up @@ -513,19 +515,6 @@ function getOptions(reports, personalDetails, activeReportID, {
recentReportOptions = reportsSplitByDefaultChatRoom[0].concat(reportsSplitByDefaultChatRoom[1]);
}

// If we are prioritizing 1:1 chats in search, do it only once we started searching
if (sortByReportTypeInSearch && searchValue !== '') {
recentReportOptions = lodashOrderBy(recentReportOptions, [(option) => {
if (option.isChatRoom || option.isArchivedRoom) {
return 3;
}
if (!option.login) {
return 2;
}
return 1;
}], ['asc']);
}

if (includePersonalDetails) {
// Next loop over all personal details removing any that are selectedUsers or recentChats
_.each(allPersonalDetailsOptions, (personalDetailOption) => {
Expand Down Expand Up @@ -565,6 +554,22 @@ function getOptions(reports, personalDetails, activeReportID, {
userToInvite.icons = [defaultAvatarForUserToInvite];
}

// If we are prioritizing 1:1 chats in search, do it only once we started searching
if (sortByReportTypeInSearch && searchValue !== '') {
// When sortByReportTypeInSearch is true, recentReports will be returned with all the reports including personalDetailsOptions in the correct Order.
recentReportOptions.push(...personalDetailsOptions);
personalDetailsOptions = [];
recentReportOptions = lodashOrderBy(recentReportOptions, [(option) => {
if (option.isChatRoom || option.isArchivedRoom) {
return 3;
}
if (!option.login) {
return 2;
}
return 1;
}], ['asc']);
}

return {
personalDetails: personalDetailsOptions,
recentReports: recentReportOptions,
Expand Down
38 changes: 22 additions & 16 deletions src/pages/SearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,18 @@ class SearchPage extends Component {
* @returns {Array}
*/
getSections() {
const sections = [{
title: this.props.translate('common.recents'),
data: this.state.recentReports.concat(this.state.personalDetails),
shouldShow: true,
indexOffset: 0,
}];
const sections = [
{
data: this.state.recentReports,
shouldShow: true,
indexOffset: 0,
},
{
data: this.state.personalDetails,
shouldShow: true,
indexOffset: this.state.recentReports.length,
},
];

if (this.state.userToInvite) {
sections.push(({
Expand Down Expand Up @@ -169,16 +175,16 @@ class SearchPage extends Component {
<View style={[styles.flex1, styles.w100, styles.pRelative]}>
<FullScreenLoadingIndicator visible={!didScreenTransitionEnd} />
{didScreenTransitionEnd && (
<OptionsSelector
sections={sections}
value={this.state.searchValue}
onSelectRow={this.selectReport}
onChangeText={this.onChangeText}
headerMessage={headerMessage}
hideSectionHeaders
hideAdditionalOptionStates
showTitleTooltip
/>
<OptionsSelector
sections={sections}
value={this.state.searchValue}
onSelectRow={this.selectReport}
onChangeText={this.onChangeText}
headerMessage={headerMessage}
hideSectionHeaders
hideAdditionalOptionStates
showTitleTooltip
/>
)}
</View>
<KeyboardSpacer />
Expand Down