Skip to content

Commit f336afd

Browse files
committed
restore removed code
1 parent 75fc0a8 commit f336afd

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

Mobile-Expensify

src/pages/home/report/ReportActionsList.tsx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
2222
import {isSafari} from '@libs/Browser';
2323
import DateUtils from '@libs/DateUtils';
2424
import {getChatFSAttributes, parseFSAttributes} from '@libs/Fullstory';
25+
import durationHighlightItem from '@libs/Navigation/helpers/getDurationHighlightItem';
2526
import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator';
2627
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
2728
import Navigation from '@libs/Navigation/Navigation';
@@ -180,6 +181,7 @@ function ReportActionsList({
180181
const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}`, {canBeMissing: true});
181182
const [userBillingFundID] = useOnyx(ONYXKEYS.NVP_BILLING_FUND_ID, {canBeMissing: true});
182183
const [isScrollToBottomEnabled, setIsScrollToBottomEnabled] = useState(false);
184+
const [actionIdToHighlight, setActionIdToHighlight] = useState('');
183185

184186
useEffect(() => {
185187
const unsubscribe = Visibility.onVisibilityChange(() => {
@@ -373,7 +375,7 @@ function ReportActionsList({
373375
return;
374376
}
375377

376-
if (isUnread(report, transactionThreadReport) || (lastAction && isCurrentActionUnread(report, lastAction))) {
378+
if (isUnread(report, transactionThreadReport) || (lastAction && isCurrentActionUnread(report, lastAction, sortedVisibleReportActions))) {
377379
// On desktop, when the notification center is displayed, isVisible will return false.
378380
// Currently, there's no programmatic way to dismiss the notification center panel.
379381
// To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification.
@@ -416,7 +418,7 @@ function ReportActionsList({
416418
}, [lastAction, prevSortedVisibleReportActionsObjects, reportScrollManager]);
417419

418420
const scrollToBottomForCurrentUserAction = useCallback(
419-
(isFromCurrentUser: boolean) => {
421+
(isFromCurrentUser: boolean, action?: OnyxTypes.ReportAction) => {
420422
InteractionManager.runAfterInteractions(() => {
421423
// If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
422424
// they are now in the list.
@@ -432,14 +434,42 @@ function ReportActionsList({
432434
});
433435
return;
434436
}
437+
const index = sortedVisibleReportActions.findIndex((item) => keyExtractor(item) === action?.reportActionID);
438+
if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW) {
439+
if (index > 0) {
440+
setTimeout(() => {
441+
reportScrollManager.scrollToIndex(index);
442+
}, 100);
443+
} else {
444+
setIsFloatingMessageCounterVisible(false);
445+
reportScrollManager.scrollToBottom();
446+
}
447+
if (action?.reportActionID) {
448+
setActionIdToHighlight(action.reportActionID);
449+
}
450+
} else {
451+
setIsFloatingMessageCounterVisible(false);
452+
reportScrollManager.scrollToBottom();
453+
}
435454

436-
setIsFloatingMessageCounterVisible(false);
437-
reportScrollManager.scrollToBottom();
438455
setIsScrollToBottomEnabled(true);
439456
});
440457
},
441458
[report.reportID, reportScrollManager, setIsFloatingMessageCounterVisible, sortedVisibleReportActions],
442459
);
460+
461+
// Clear the highlighted report action after scrolling and highlighting
462+
useEffect(() => {
463+
if (actionIdToHighlight === '') {
464+
return;
465+
}
466+
// Time highlight is the same as SearchPage
467+
const timer = setTimeout(() => {
468+
setActionIdToHighlight('');
469+
}, durationHighlightItem);
470+
return () => clearTimeout(timer);
471+
}, [actionIdToHighlight]);
472+
443473
useEffect(() => {
444474
// Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function?
445475
// Answer: On web, when navigating to another report screen, the previous report screen doesn't get unmounted,

0 commit comments

Comments
 (0)