diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 963ac5a9f524..5f79c634d930 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -84,13 +84,16 @@ class NewChatPage extends Component { */ getSections(maxParticipantsReached) { const sections = []; + let indexOffset = 0; + if (this.props.isGroupChat) { sections.push({ title: undefined, data: this.state.selectedOptions, shouldShow: !_.isEmpty(this.state.selectedOptions), - indexOffset: 0, + indexOffset, }); + indexOffset += this.state.selectedOptions.length; if (maxParticipantsReached) { return sections; @@ -107,22 +110,24 @@ class NewChatPage extends Component { title: this.props.translate('common.recents'), data: recentReportsWithoutSelected, shouldShow: !_.isEmpty(recentReportsWithoutSelected), - indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0), + indexOffset, }); + indexOffset += recentReportsWithoutSelected.length; sections.push({ title: this.props.translate('common.contacts'), data: personalDetailsWithoutSelected, shouldShow: !_.isEmpty(personalDetailsWithoutSelected), - indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0), + indexOffset, }); + indexOffset += personalDetailsWithoutSelected.length; if (hasUnselectedUserToInvite) { sections.push(({ title: undefined, data: [this.state.userToInvite], shouldShow: true, - indexOffset: 0, + indexOffset, })); } diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 44f5e1e7083e..15b01aed72cd 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -87,20 +87,24 @@ class SearchPage extends Component { */ getSections() { const sections = []; + let indexOffset = 0; + if (this.state.recentReports.length > 0) { sections.push(({ data: this.state.recentReports, shouldShow: true, - indexOffset: 0, + indexOffset, })); + indexOffset += this.state.recentReports.length; } if (this.state.personalDetails.length > 0) { sections.push(({ data: this.state.personalDetails, shouldShow: true, - indexOffset: this.state.recentReports.length, + indexOffset, })); + indexOffset += this.state.recentReports.length; } if (this.state.userToInvite) { @@ -108,7 +112,7 @@ class SearchPage extends Component { undefined, data: [this.state.userToInvite], shouldShow: true, - indexOffset: 0, + indexOffset, })); } diff --git a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js index 5968242bcbac..815c9f5c7551 100755 --- a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js +++ b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js @@ -64,27 +64,30 @@ class IOUParticipantsRequest extends Component { */ getSections() { const sections = []; + let indexOffset = 0; sections.push({ title: this.props.translate('common.recents'), data: this.state.recentReports, shouldShow: !_.isEmpty(this.state.recentReports), - indexOffset: 0, + indexOffset, }); + indexOffset += this.state.recentReports.length; sections.push({ title: this.props.translate('common.contacts'), data: this.state.personalDetails, shouldShow: !_.isEmpty(this.state.personalDetails), - indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0), + indexOffset, }); + indexOffset += this.state.personalDetails.length; if (this.state.userToInvite && !OptionsListUtils.isCurrentUser(this.state.userToInvite)) { sections.push({ undefined, data: [this.state.userToInvite], shouldShow: true, - indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0), + indexOffset, }); } diff --git a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js index eacefbeedceb..ede766410457 100755 --- a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js +++ b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js @@ -87,12 +87,15 @@ class IOUParticipantsSplit extends Component { */ getSections(maxParticipantsReached) { const sections = []; + let indexOffset = 0; + sections.push({ title: undefined, data: this.props.participants, shouldShow: true, - indexOffset: 0, + indexOffset, }); + indexOffset += this.props.participants.length; if (maxParticipantsReached) { return sections; @@ -102,28 +105,24 @@ class IOUParticipantsSplit extends Component { title: this.props.translate('common.recents'), data: this.state.recentReports, shouldShow: !_.isEmpty(this.state.recentReports), - - // takes the sum off the length of all data - // (this.state.selectedOptions) in previous sections - indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0), + indexOffset, }); + indexOffset += this.state.recentReports.length; sections.push({ title: this.props.translate('common.contacts'), data: this.state.personalDetails, shouldShow: !_.isEmpty(this.state.personalDetails), - - // takes the sum off the length of all data - // (this.state.selectedOptions, this.state.recentReports) in previous sections - indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0), + indexOffset, }); + indexOffset += this.state.personalDetails.length; if (this.state.userToInvite && !OptionsListUtils.isCurrentUser(this.state.userToInvite)) { sections.push(({ undefined, data: [this.state.userToInvite], shouldShow: true, - indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0), + indexOffset, })); } diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index 395707142f7a..fbabe111ac26 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -132,12 +132,15 @@ class WorkspaceInvitePage extends React.Component { */ getSections() { const sections = []; + let indexOffset = 0; + sections.push({ title: undefined, data: this.state.selectedOptions, shouldShow: true, - indexOffset: 0, + indexOffset, }); + indexOffset += this.state.selectedOptions.length; // Filtering out selected users from the search results const filterText = _.reduce(this.state.selectedOptions, (str, {login}) => `${str} ${login}`, ''); @@ -148,15 +151,16 @@ class WorkspaceInvitePage extends React.Component { title: this.props.translate('common.contacts'), data: personalDetailsWithoutSelected, shouldShow: !_.isEmpty(personalDetailsWithoutSelected), - indexOffset: _.reduce(sections, (prev, {data}) => prev + data.length, 0), + indexOffset, }); + indexOffset += personalDetailsWithoutSelected.length; if (hasUnselectedUserToInvite) { sections.push(({ title: undefined, data: [this.state.userToInvite], shouldShow: true, - indexOffset: 0, + indexOffset, })); }