Skip to content

Commit

Permalink
immediately update lhn list when changing priority mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Jan 18, 2024
1 parent d910b92 commit e46d522
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pages/home/sidebar/SidebarLinksData.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {withNetwork} from '@components/OnyxProvider';
import withCurrentReportID from '@components/withCurrentReportID';
import withNavigationFocus from '@components/withNavigationFocus';
import useLocalize from '@hooks/useLocalize';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import compose from '@libs/compose';
import SidebarUtils from '@libs/SidebarUtils';
Expand Down Expand Up @@ -69,6 +70,7 @@ const defaultProps = {
function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingApp, onLinkClick, policies, priorityMode, network}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const prevPriorityMode = usePrevious(priorityMode);

const reportIDsRef = useRef(null);
const isLoading = isLoadingApp;
Expand All @@ -79,13 +81,14 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr
return reportIDsRef.current;
}

// We need to update existing reports only once while loading because they are updated several times during loading and causes this regression: https://github.com/Expensify/App/issues/24596#issuecomment-1681679531
// However, if the user is offline, we need to update the reports unconditionally, since the loading of report data might be stuck in this case.
if (!isLoading || !reportIDsRef.current || network.isOffline) {
// 1. We need to update existing reports only once while loading because they are updated several times during loading and causes this regression: https://github.com/Expensify/App/issues/24596#issuecomment-1681679531
// 2. If the user is offline, we need to update the reports unconditionally, since the loading of report data might be stuck in this case.
// 3. Changing priority mode to Most Recent will call OpenApp. If there is an existing reports and the priority mode is updated, we want to immediately update the list instead of waiting the OpenApp request to complete
if (!isLoading || !reportIDsRef.current || network.isOffline || (reportIDsRef.current && prevPriorityMode !== priorityMode)) {
reportIDsRef.current = reportIDs;
}
return reportIDsRef.current || [];
}, [allReportActions, betas, chatReports, policies, priorityMode, isLoading, network.isOffline]);
}, [allReportActions, betas, chatReports, policies, prevPriorityMode, priorityMode, isLoading, network.isOffline]);

// We need to make sure the current report is in the list of reports, but we do not want
// to have to re-generate the list every time the currentReportID changes. To do that
Expand Down

0 comments on commit e46d522

Please sign in to comment.