Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ad07324
LoadingBar rendering improvements
martasudol May 29, 2025
7ef7b12
prettier & eslint
martasudol May 29, 2025
c0d830a
prettier & eslint
martasudol May 29, 2025
6dc8637
prettier & eslint
martasudol May 29, 2025
5b40950
use queueFlushedData
martasudol May 30, 2025
2058dca
use ongoingRequest instead of currentRequestCommand
martasudol May 30, 2025
c7a5e40
set for relevant commands
martasudol May 30, 2025
8da7669
removed notifyQueueStateChange call after clearing
martasudol May 30, 2025
6aa3601
avoiding rerenders
martasudol May 30, 2025
d65371b
prettier
martasudol May 30, 2025
ebb3b1e
reverted `IS_LOADING_REPORT_DATA` changes
martasudol Jun 2, 2025
3596271
Merge branch 'main' into loading-bar-rendering-conditions-improvement
martasudol Jun 2, 2025
73416b1
pr comments
martasudol Jun 3, 2025
4130fb0
listens for persisted requests instead of directly for sequential queue
martasudol Jun 9, 2025
8b75c81
eslint
martasudol Jun 9, 2025
7108d2d
Merge branch 'main' into loading-bar-rendering-conditions-improvement
martasudol Jun 11, 2025
0173685
rename isLoadingReportData to shouldShowLoadingBar
martasudol Jun 12, 2025
a48c857
Merge branch 'main' into loading-bar-rendering-conditions-improvement
martasudol Jun 13, 2025
18ddecf
prettier & eslint
martasudol Jun 13, 2025
9f219c9
Onyx.set usage instead of in-memory let
martasudol Jun 18, 2025
8f884f8
Merge branch 'main' into loading-bar-rendering-conditions-improvement
martasudol Jun 18, 2025
a5c5d57
onyx.set
martasudol Jun 18, 2025
0b9b843
use ongoing requests Onyx key to handle requests from Pusher
martasudol Jun 20, 2025
c7f47a1
Merge branch 'main' into loading-bar-rendering-conditions-improvement
martasudol Jun 20, 2025
5774d7a
add ReadNewestAction to relevant commands
martasudol Jun 23, 2025
9bed9c7
replace useOnyx with network key with useNetwork hook
martasudol Jun 24, 2025
bff9461
Update src/hooks/useLoadingBarVisibility.ts
martasudol Jun 25, 2025
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
5 changes: 3 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {ActivityIndicator, InteractionManager, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -295,7 +296,7 @@ function MoneyReportHeader({
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(moneyRequestReport, shouldShowPayButton);
const isAnyTransactionOnHold = hasHeldExpensesReportUtils(moneyRequestReport?.reportID);
const {isDelegateAccessRestricted, showDelegateNoAccessModal} = useContext(DelegateNoAccessContext);
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
const shouldShowLoadingBar = useLoadingBarVisibility();

const isReportInRHP = route.name === SCREENS.SEARCH.REPORT_RHP;
const shouldDisplaySearchRouter = !isReportInRHP || isSmallScreenWidth;
Expand Down Expand Up @@ -997,7 +998,7 @@ function MoneyReportHeader({
)}
</View>
)}
<LoadingBar shouldShow={(isLoadingReportData && shouldUseNarrowLayout) ?? false} />
<LoadingBar shouldShow={shouldShowLoadingBar && shouldUseNarrowLayout} />
{isHoldMenuVisible && requestType !== undefined && (
<ProcessMoneyReportHoldMenu
nonHeldAmount={!hasOnlyHeldExpenses && hasValidNonHeldAmount ? nonHeldAmount : undefined}
Expand Down
5 changes: 3 additions & 2 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
Expand Down Expand Up @@ -82,7 +83,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const [downloadErrorModalVisible, setDownloadErrorModalVisible] = useState(false);
const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true, canBeMissing: false});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
const shouldShowLoadingBar = useLoadingBarVisibility();
const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult);
const styles = useThemeStyles();
const theme = useTheme();
Expand Down Expand Up @@ -308,7 +309,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
/>
</View>
)}
<LoadingBar shouldShow={(isLoadingReportData && shouldUseNarrowLayout) ?? false} />
<LoadingBar shouldShow={shouldShowLoadingBar && shouldUseNarrowLayout} />
<DecisionModal
title={translate('common.downloadFailedTitle')}
prompt={translate('common.downloadFailedDescription')}
Expand Down
5 changes: 3 additions & 2 deletions src/components/Navigation/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {PressableWithoutFeedback} from '@components/Pressable';
import SearchButton from '@components/Search/SearchRouter/SearchButton';
import HelpButton from '@components/SidePanel/HelpComponents/HelpButton';
import Text from '@components/Text';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import SignInButton from '@pages/home/sidebar/SignInButton';
Expand All @@ -25,7 +26,7 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB
const styles = useThemeStyles();
const {translate} = useLocalize();
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: (sessionValue) => sessionValue && {authTokenType: sessionValue.authTokenType}, canBeMissing: true});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
const shouldShowLoadingBarForReports = useLoadingBarVisibility();
const isAnonymousUser = isAnonymousUserUtil(session);

const displaySignIn = isAnonymousUser;
Expand Down Expand Up @@ -63,7 +64,7 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB
{shouldDisplayHelpButton && <HelpButton />}
{displaySearch && <SearchButton />}
</View>
<LoadingBar shouldShow={(isLoadingReportData ?? false) || shouldShowLoadingBar} />
<LoadingBar shouldShow={shouldShowLoadingBarForReports || shouldShowLoadingBar} />
</View>
);
}
Expand Down
27 changes: 27 additions & 0 deletions src/hooks/useLoadingBarVisibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {WRITE_COMMANDS} from '@libs/API/types';
import ONYXKEYS from '@src/ONYXKEYS';
import useNetwork from './useNetwork';
import useOnyx from './useOnyx';

// Commands that should trigger the LoadingBar to show
const RELEVANT_COMMANDS = new Set<string>([WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT, WRITE_COMMANDS.READ_NEWEST_ACTION]);

/**
* Hook that determines whether LoadingBar should be visible based on active queue requests
* Shows LoadingBar when any of the RELEVANT_COMMANDS are being processed
*/
export default function useLoadingBarVisibility(): boolean {
const [persistedRequests] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {canBeMissing: false});
const [ongoingRequests] = useOnyx(ONYXKEYS.PERSISTED_ONGOING_REQUESTS, {canBeMissing: false});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We set canBeMissing of ONYXKEYS.PERSISTED_ONGOING_REQUESTS to true since since it can be null. (See issue #66591)

Onyx.set(ONYXKEYS.PERSISTED_ONGOING_REQUESTS, null);

const {isOffline} = useNetwork();

// Don't show loading bar if currently offline
if (isOffline) {
return false;
}

const hasPersistedRequests = persistedRequests?.some((request) => RELEVANT_COMMANDS.has(request.command) && !request.initiatedOffline) ?? false;
const hasOngoingRequests = !!ongoingRequests && RELEVANT_COMMANDS.has(ongoingRequests?.command);

return hasPersistedRequests || hasOngoingRequests;
}
5 changes: 3 additions & 2 deletions src/pages/home/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import TaskHeaderActionButton from '@components/TaskHeaderActionButton';
import Text from '@components/Text';
import Tooltip from '@components/Tooltip';
import useHasTeam2025Pricing from '@hooks/useHasTeam2025Pricing';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import usePolicy from '@hooks/usePolicy';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand Down Expand Up @@ -113,7 +114,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID) ?? getNonEmptyStringOnyxID(report?.reportID)}`, {canBeMissing: true});
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: true});
const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {canBeMissing: true});
const shouldShowLoadingBar = useLoadingBarVisibility();
const [firstDayFreeTrial] = useOnyx(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, {canBeMissing: true});
const [lastDayFreeTrial] = useOnyx(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, {canBeMissing: true});
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
Expand Down Expand Up @@ -404,7 +405,7 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
</View>
</View>
)}
<LoadingBar shouldShow={(isLoadingReportData && shouldUseNarrowLayout) ?? false} />
<LoadingBar shouldShow={shouldShowLoadingBar && shouldUseNarrowLayout} />
</View>
{shouldShowEarlyDiscountBanner && (
<EarlyDiscountBanner
Expand Down
Loading