forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Get rid of IS_LOADING_REPORT_DATA Onyx flag #22
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
31b53a5
get rid of IS_LOADING_REPORT_DATA Onyx flag.
martasudol 717fabd
get rid of IS_LOADING_REPORT_DATA Onyx flag.
martasudol 5be1876
prettier & eslint
martasudol 3d036ca
prettier & eslint
martasudol b9137ee
General wrapper hook & dedicated hooks
martasudol 9ce3ea7
prettier & eslint
martasudol b7a4f77
memoization
martasudol af6a570
prettier
martasudol 7fb2fa6
Merge branch 'main' into remove-is-loading-report-data-onyx-flag
martasudol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import {useMemo} from 'react'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** | ||
| * Hook that determines if any of the specified commands are currently being processed | ||
| * | ||
| * Monitors persisted requests queue for the provided commands that are not initiated offline. | ||
| * | ||
| * @param commands - Array of command strings to monitor | ||
| * @returns boolean indicating if any of the specified commands are currently loading | ||
| */ | ||
| export default function useCommandsLoading(commands: string[]): boolean { | ||
| const [req] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {canBeMissing: false}); | ||
|
|
||
| const commandsSet = useMemo(() => new Set(commands), [commands]); | ||
|
|
||
| return req?.some((request) => commandsSet.has(request.command) && !request.initiatedOffline) ?? false; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,28 @@ | ||
| import {WRITE_COMMANDS} from '@libs/API/types'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import useCommandsLoading from './useCommandsLoading'; | ||
| 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]); | ||
| // Commands that should trigger loading bar visibility | ||
| const LOADING_BAR_COMMANDS = [WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT]; | ||
|
|
||
| /** | ||
| * Hook that determines whether LoadingBar should be visible based on active queue requests | ||
| * Shows LoadingBar when OpenReport/OpenApp/ReconnectApp requests are being processed | ||
| * Hook that determines when the loading bar should be visible | ||
| * | ||
| * Monitors persisted requests queue for OpenApp, ReconnectApp, and OpenReport commands | ||
| * that trigger report data fetching from the server. The loading bar is hidden when offline | ||
| * to provide better UX since users can't interact with loading content while offline. | ||
| * | ||
| * @returns boolean indicating if the loading bar should be visible | ||
| */ | ||
| export default function useLoadingBarVisibility(): boolean { | ||
| const [req] = useOnyx(ONYXKEYS.PERSISTED_REQUESTS, {canBeMissing: false}); | ||
| const [network] = useOnyx(ONYXKEYS.NETWORK, {canBeMissing: false}); | ||
| const hasRelevantCommands = useCommandsLoading(LOADING_BAR_COMMANDS); | ||
|
|
||
| // Don't show loading bar if currently offline | ||
| // Loading bar should not be shown when offline since users can't interact with loading content | ||
| if (network?.isOffline) { | ||
| return false; | ||
| } | ||
|
|
||
| return req?.some((request) => RELEVANT_COMMANDS.has(request.command) && !request.initiatedOffline) ?? false; | ||
| return hasRelevantCommands; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import {WRITE_COMMANDS} from '@libs/API/types'; | ||
| import useCommandsLoading from './useCommandsLoading'; | ||
|
|
||
| // Commands that should trigger report data loading states | ||
| const REPORT_DATA_COMMANDS = [WRITE_COMMANDS.OPEN_APP, WRITE_COMMANDS.RECONNECT_APP, WRITE_COMMANDS.OPEN_REPORT]; | ||
|
|
||
| /** | ||
| * Hook that determines if report data is currently being loaded | ||
| * | ||
| * Monitors persisted requests queue for OpenApp, ReconnectApp, and OpenReport commands | ||
| * that trigger report data fetching from the server. This hook ignores offline state | ||
| * and is primarily used for full-screen loading indicators. | ||
| * | ||
| * @returns boolean indicating if report data is currently loading | ||
| */ | ||
| export default function useReportDataLoading(): boolean { | ||
| return useCommandsLoading(REPORT_DATA_COMMANDS); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.