|
| 1 | +import type {ComponentProps} from 'react'; |
| 2 | +import React from 'react'; |
| 3 | +import NavigationDeferredMount from '@components/NavigationDeferredMount'; |
| 4 | +import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton'; |
| 5 | +import useResponsiveLayout from '@hooks/useResponsiveLayout'; |
| 6 | +import useThemeStyles from '@hooks/useThemeStyles'; |
| 7 | +import {endSpanWithAttributes} from '@libs/telemetry/activeSpans'; |
| 8 | +import {endSubmitFollowUpActionSpan, getPendingSubmitFollowUpAction} from '@libs/telemetry/submitFollowUpAction'; |
| 9 | +import CONST from '@src/CONST'; |
| 10 | +import Search from './index'; |
| 11 | + |
| 12 | +const REASON_ATTRIBUTES = {context: 'SearchPage.NavigationDeferred'} as const; |
| 13 | + |
| 14 | +function handleSkeletonLayout() { |
| 15 | + endSpanWithAttributes(CONST.TELEMETRY.SPAN_NAVIGATE_TO_REPORTS, {[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: true}); |
| 16 | + |
| 17 | + // Skeleton paint is the first user-perceivable signal that the submit destination |
| 18 | + // (Search) is up. End the submit-to-destination-visible span here for any pending |
| 19 | + // action that targets Search. DISMISS_MODAL_AND_OPEN_REPORT is excluded because |
| 20 | + // that flow's destination is the report, not Search. |
| 21 | + const pending = getPendingSubmitFollowUpAction(); |
| 22 | + if (pending && pending.followUpAction !== CONST.TELEMETRY.SUBMIT_FOLLOW_UP_ACTION.DISMISS_MODAL_AND_OPEN_REPORT) { |
| 23 | + endSubmitFollowUpActionSpan(pending.followUpAction, undefined, {[CONST.TELEMETRY.ATTRIBUTE_IS_WARM]: true}); |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +function SearchWithNavigationDeferredMount(props: ComponentProps<typeof Search>) { |
| 28 | + const styles = useThemeStyles(); |
| 29 | + const {shouldUseNarrowLayout} = useResponsiveLayout(); |
| 30 | + const containerStyle = shouldUseNarrowLayout ? styles.searchListContentContainerStyles(!!props.hasFilterBars) : styles.mt3; |
| 31 | + |
| 32 | + return ( |
| 33 | + <NavigationDeferredMount |
| 34 | + waitForUpcomingTransition={false} |
| 35 | + placeholder={ |
| 36 | + <SearchRowSkeleton |
| 37 | + shouldAnimate |
| 38 | + onLayout={handleSkeletonLayout} |
| 39 | + containerStyle={containerStyle} |
| 40 | + reasonAttributes={REASON_ATTRIBUTES} |
| 41 | + /> |
| 42 | + } |
| 43 | + > |
| 44 | + <Search {...props} /> |
| 45 | + </NavigationDeferredMount> |
| 46 | + ); |
| 47 | +} |
| 48 | + |
| 49 | +export default SearchWithNavigationDeferredMount; |
0 commit comments