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/30868: Incorrect group displayed #31424

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7804843
fix incorrect group displayed
DylanDylann Nov 16, 2023
4f5a617
fix merge main
DylanDylann Nov 21, 2023
2252f7c
fix merge main
DylanDylann Nov 23, 2023
cb0782f
fix does not update timestamp with empty report
DylanDylann Nov 27, 2023
c32c0c9
fix merge conflict
DylanDylann Nov 28, 2023
7988973
fix lint
DylanDylann Nov 28, 2023
87f5f0e
fix add comment
DylanDylann Nov 30, 2023
cadc716
fix add comment
DylanDylann Nov 30, 2023
dd11d73
Merge branch 'Expensify:main' into fix/30868-difference-group-chat-ap…
DylanDylann Dec 1, 2023
87c8aae
fix merge main
DylanDylann Dec 1, 2023
410e3d4
fix add comments to logic
DylanDylann Dec 1, 2023
5a89b41
fix additional space
DylanDylann Dec 1, 2023
3355279
fix try to fix performance issue
DylanDylann Dec 1, 2023
a41c14c
Merge branch 'main' into fix/30868-difference-group-chat-appear-when-…
DylanDylann Dec 2, 2023
1ed435f
fix merge main
DylanDylann Dec 5, 2023
6ac934c
fix try to fix performance regression
DylanDylann Dec 5, 2023
9ae4d5b
fix remove space
DylanDylann Dec 5, 2023
8423ed6
fix update when going back
DylanDylann Dec 5, 2023
7cd02ab
fix jest test 1
DylanDylann Dec 5, 2023
4da0520
fix jest test 1
DylanDylann Dec 5, 2023
07f8ea5
fix disable update timestamp when back
DylanDylann Dec 5, 2023
37f11e5
fix performance regression
DylanDylann Dec 5, 2023
34dc79f
fix reassure error
DylanDylann Dec 6, 2023
32400c4
fix reassure regression
DylanDylann Dec 6, 2023
df2ab5e
fix merge main
DylanDylann Dec 12, 2023
83d3864
fix merge main
DylanDylann Dec 15, 2023
b80d70e
fix merge main
DylanDylann Dec 15, 2023
e64c615
fix remove console log
DylanDylann Dec 15, 2023
1f8552c
fix remove comment
DylanDylann Dec 15, 2023
17a67d7
fix lint
DylanDylann Dec 15, 2023
fe8dfde
Merge branch 'main' into fix/30868-difference-group-chat-appear-when-…
DylanDylann Dec 20, 2023
06dfd19
fix filter function
DylanDylann Dec 21, 2023
3959145
fix sort function
DylanDylann Dec 21, 2023
9feb1d2
fix lint issue
DylanDylann Dec 21, 2023
3240264
fix comment
DylanDylann Dec 26, 2023
d9dd286
fix add comment to prop
DylanDylann Dec 29, 2023
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
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,10 @@ function isDraftExpenseReport(report: OnyxEntry<Report>): boolean {
*/
function sortReportsByLastRead(reports: OnyxCollection<Report>): Array<OnyxEntry<Report>> {
MonilBhavsar marked this conversation as resolved.
Show resolved Hide resolved
return Object.values(reports ?? {})
.filter((report) => !!report?.reportID && !!report?.lastReadTime)
.filter((report) => !!report?.reportID && (!!report?.lastVisitTime || !!report?.lastReadTime))
.sort((a, b) => {
const aTime = new Date(a?.lastReadTime ?? '');
const bTime = new Date(b?.lastReadTime ?? '');
const aTime = new Date(a?.lastVisitTime ?? a?.lastReadTime ?? '');
const bTime = new Date(b?.lastVisitTime ?? b?.lastReadTime ?? '');

return aTime.valueOf() - bTime.valueOf();
});
Expand Down
12 changes: 12 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,17 @@ function searchInServer(searchInput) {
debouncedSearchInServer(searchInput);
}

/**
* @param {String} reportID
*/

DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
function updateLastVisitTime(reportID) {
if (!ReportUtils.isValidReportIDFromPath(reportID)) {
return;
}
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {lastVisitTime: DateUtils.getDBTime()});
}

export {
searchInServer,
addComment,
Expand Down Expand Up @@ -2563,4 +2574,5 @@ export {
openRoomMembersPage,
savePrivateNotesDraft,
getDraftPrivateNote,
updateLastVisitTime,
};
15 changes: 13 additions & 2 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useIsFocused} from '@react-navigation/native';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
Expand Down Expand Up @@ -165,6 +166,18 @@ function ReportScreen({
const [scrollPosition, setScrollPosition] = useState({});

const reportID = getReportID(route);

const isFocused = useIsFocused();

// We need to update the lastVisitTime every time the report is focused
// because lastReadTime does not have up-to-date time stamp every time the user visits a report.
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
if (!report.reportID || !isFocused) {
return;
}
Report.updateLastVisitTime(report.reportID);
}, [report.reportID, isFocused]);

DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
const {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report);
const screenWrapperStyle = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}];

Expand Down Expand Up @@ -237,7 +250,6 @@ function ReportScreen({

const fetchReportIfNeeded = useCallback(() => {
const reportIDFromPath = getReportID(route);

// Report ID will be empty when the reports collection is empty.
// This could happen when we are loading the collection for the first time after logging in.
if (!ReportUtils.isValidReportIDFromPath(reportIDFromPath)) {
Expand All @@ -250,7 +262,6 @@ function ReportScreen({
if (report.reportID && report.reportID === getReportID(route) && !isLoadingInitialReportActions) {
return;
}

Report.openReport(reportIDFromPath);
}, [report.reportID, route, isLoadingInitialReportActions]);

Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type Report = {
/** The last time the report was visited */
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
lastReadTime?: string;

/** The time of the last visit of the report */
lastVisitTime?: string;

/** The sequence number of the last report visit */
lastReadSequenceNumber?: number;

Expand Down
Loading