Skip to content

Commit

Permalink
fix: get unread marker from visible actions
Browse files Browse the repository at this point in the history
  • Loading branch information
sangar-1028 committed Jan 4, 2024
1 parent 8e64689 commit a070efa
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ function ReportActionsList({
const lastVisibleActionCreatedRef = useRef(report.lastVisibleActionCreated);
const lastReadTimeRef = useRef(report.lastReadTime);

const sortedVisibleReportActions = _.filter(sortedReportActions, (s) => isOffline || s.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || s.errors);
const sortedVisibleReportActions = useMemo(
() => _.filter(sortedReportActions, (s) => isOffline || s.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || s.errors),
[sortedReportActions, isOffline],
);
const lastActionIndex = lodashGet(sortedVisibleReportActions, [0, 'reportActionID']);
const reportActionSize = useRef(sortedVisibleReportActions.length);

Expand Down Expand Up @@ -348,7 +351,7 @@ function ReportActionsList({
(reportAction, index) => {
let shouldDisplay = false;
if (!currentUnreadMarker) {
const nextMessage = sortedReportActions[index + 1];
const nextMessage = sortedVisibleReportActions[index + 1];
const isCurrentMessageUnread = isMessageUnread(reportAction, lastReadTimeRef.current);
shouldDisplay = isCurrentMessageUnread && (!nextMessage || !isMessageUnread(nextMessage, lastReadTimeRef.current)) && !ReportActionsUtils.shouldHideNewMarker(reportAction);
if (shouldDisplay && !messageManuallyMarkedUnread) {
Expand All @@ -367,15 +370,15 @@ function ReportActionsList({

return shouldDisplay;
},
[currentUnreadMarker, sortedReportActions, report.reportID, messageManuallyMarkedUnread],
[currentUnreadMarker, sortedVisibleReportActions, report.reportID, messageManuallyMarkedUnread],
);

useEffect(() => {
// Iterate through the report actions and set appropriate unread marker.
// This is to avoid a warning of:
// Cannot update a component (ReportActionsList) while rendering a different component (CellRenderer).
let markerFound = false;
_.each(sortedReportActions, (reportAction, index) => {
_.each(sortedVisibleReportActions, (reportAction, index) => {
if (!shouldDisplayNewMarker(reportAction, index)) {
return;
}
Expand All @@ -388,7 +391,7 @@ function ReportActionsList({
if (!markerFound) {
setCurrentUnreadMarker(null);
}
}, [sortedReportActions, report.lastReadTime, report.reportID, messageManuallyMarkedUnread, shouldDisplayNewMarker, currentUnreadMarker]);
}, [sortedVisibleReportActions, report.lastReadTime, report.reportID, messageManuallyMarkedUnread, shouldDisplayNewMarker, currentUnreadMarker]);

const renderItem = useCallback(
({item: reportAction, index}) => (
Expand Down

0 comments on commit a070efa

Please sign in to comment.