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 the new message button doesn't work on some comment linkings #46627

Merged
merged 17 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/PaginationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function mergeAndSortContinuousPages<TResource>(sortedItems: TResource[], pages:
const result = [sortedPages[0]];
for (let i = 1; i < sortedPages.length; i++) {
const page = sortedPages[i];
const prevPage = sortedPages[i - 1];
const prevPage = result[result.length - 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepage (result[result.length - 1]) could be same as page if the result contains only one page

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s77rt What? I don't understand. Could you elaborate please?
Do you mean when the sortedPages.length is 1. If it is 1 it won't even enter the for loop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If result length is 1, then:
page = sortedPages[0]
and
prevPage = sortedPages[0]

page is same as prevPage which is misleading and could cause bugs

Copy link
Contributor Author

@tsa321 tsa321 Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s77rt Maybe I still don't understand.
The i in the for loop starts at 1, not 0, so page = sortedPages[0] is not possible. Consequently, page and prevPage won't be the same.

Am I missing something?

const prevPage = result[result.length - 1]; Here I am using the last updated page of result and not the sortedPages.
The end of result could be only 1 continuous page for for example 10 pages in sortedPages. Because the function merge the pages into one continuous page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right! my bad


// Current page is inside the previous page, skip
if (page.lastIndex <= prevPage.lastIndex && page.lastID !== CONST.PAGINATION_END_ID) {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function ReportActionsView({
const reactionListRef = useContext(ReactionListContext);
const route = useRoute<RouteProp<AuthScreensParamList, typeof SCREENS.REPORT>>();
const reportActionID = route?.params?.reportActionID;
const prevReportActionID = usePrevious(reportActionID);
const didLayout = useRef(false);
const didLoadOlderChats = useRef(false);
const didLoadNewerChats = useRef(false);
Expand Down Expand Up @@ -141,7 +142,7 @@ function ReportActionsView({

// Change the list ID only for comment linking to get the positioning right
const listID = useMemo(() => {
if (!reportActionID) {
if (!reportActionID && !prevReportActionID) {
// Keep the old list ID since we're not in the Comment Linking flow
return listOldID;
}
Expand Down
Loading