Skip to content

Commit

Permalink
cleaned up report actions, fixed issue with pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
JediWattson committed Nov 19, 2022
1 parent 7abd76e commit f738465
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 54 deletions.
34 changes: 4 additions & 30 deletions src/components/AttachmentCarousel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const defaultProps = {
sourceURL: '',
report: {
isLoadingMoreReportActions: false,
reportId: '',
reportID: '',
},
reportActions: {},
onNavigate: () => {},
Expand All @@ -50,7 +50,6 @@ class AttachmentCarousel extends React.Component {

this.canUseTouchScreen = canUseTouchScreen();
this.makeStateWithReports = this.makeStateWithReports.bind(this);
this.loadMoreChats = this.loadMoreChats.bind(this);
this.cycleThroughAttachments = this.cycleThroughAttachments.bind(this);
this.onShowArrow = this.onShowArrow.bind(this);

Expand Down Expand Up @@ -126,31 +125,6 @@ class AttachmentCarousel extends React.Component {
});
}

/**
* Retrieves the next set of report actions for the chat once we are nearing the end of what we are currently
* displaying.
*/
loadMoreChats() {
// Only fetch more if we are not already fetching so that we don't initiate duplicate requests.
if (this.props.report.isLoadingMoreReportActions) {
return;
}

const minSequenceNumber = _.chain(this.props.reportActions)
.pluck('sequenceNumber')
.min()
.value();

if (minSequenceNumber === 0) {
return;
}

// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments, unless we're near the beginning, in which
// case just get everything starting from 0.
const oldestActionSequenceNumber = Math.max(minSequenceNumber - CONST.REPORT.ACTIONS.LIMIT, 0);
Report.readOldestAction(this.props.report.reportID, oldestActionSequenceNumber);
}

/**
* increments or decrements the index to get another selected item
* @param {Number} deltaSlide
Expand All @@ -163,16 +137,16 @@ class AttachmentCarousel extends React.Component {
this.setState(({attachments, page}) => {
const nextIndex = page + deltaSlide;
if (nextIndex < 10) {
this.loadMoreChats();
Report.loadMoreActions(this.props.report.reportID, this.props.reportActions, this.props.report.isLoadingMoreReportActions);
}
const {sourceURL, file} = this.getAttachment(attachments[nextIndex]);
this.props.onNavigate({sourceURL, file});
return {
page: nextIndex,
sourceURL,
file,
isBackDisabled: nextIndex === 0,
isForwardDisabled: nextIndex === attachments.length - 1,
isBackDisabled: nextIndex === attachments.length - 1,
isForwardDisabled: nextIndex === 0,
};
});
}
Expand Down
30 changes: 24 additions & 6 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,17 +613,35 @@ function reconnect(reportID) {
}

/**
* Gets the older actions that have not been read yet.
* Normally happens when you scroll up on a chat, and the actions have not been read yet.
* Retrieves the next set of report actions for the chat once we are nearing the end of what we are currently
* displaying.
*
* @param {String} reportID
* @param {Number} oldestActionSequenceNumber
* @param {Object} reportActions
* @param {Boolean} isLoadingMoreReportActions
*/
function readOldestAction(reportID, oldestActionSequenceNumber) {
function loadMoreActions(reportID, reportActions, isLoadingMoreReportActions) {
// Only fetch more if we are not already fetching so that we don't initiate duplicate requests.
if (isLoadingMoreReportActions) {
return;
}

const minSequenceNumber = _.chain(reportActions)
.pluck('sequenceNumber')
.min()
.value();

if (minSequenceNumber === 0) {
return;
}

// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments, unless we're near the beginning, in which
// case just get everything starting from 0.
const reportActionsOffset = Math.max(minSequenceNumber - CONST.REPORT.ACTIONS.LIMIT, 0);
API.read('ReadOldestAction',
{
reportID,
reportActionsOffset: oldestActionSequenceNumber,
reportActionsOffset,
},
{
optimisticData: [{
Expand Down Expand Up @@ -1366,7 +1384,7 @@ export {
setIsComposerFullSize,
markCommentAsUnread,
readNewestAction,
readOldestAction,
loadMoreActions,
openReport,
navigateToAndOpenReport,
openPaymentDetailsPage,
Expand Down
19 changes: 1 addition & 18 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,24 +280,7 @@ class ReportActionsView extends React.Component {
* displaying.
*/
loadMoreChats() {
// Only fetch more if we are not already fetching so that we don't initiate duplicate requests.
if (this.props.report.isLoadingMoreReportActions) {
return;
}

const minSequenceNumber = _.chain(this.props.reportActions)
.pluck('sequenceNumber')
.min()
.value();

if (minSequenceNumber === 0) {
return;
}

// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments, unless we're near the beginning, in which
// case just get everything starting from 0.
const oldestActionSequenceNumber = Math.max(minSequenceNumber - CONST.REPORT.ACTIONS.LIMIT, 0);
Report.readOldestAction(this.props.report.reportID, oldestActionSequenceNumber);
Report.loadMoreActions(this.props.report.reportID, this.props.reportActions, this.props.report.isLoadingMoreReportActions);
}

scrollToUnreadMsgAndMarkReportAsRead() {
Expand Down

0 comments on commit f738465

Please sign in to comment.