Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions src/components/LHNOptionsList/LHNEmptyState.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, {useEffect} from 'react';
import {View} from 'react-native';
import type {BlockingViewProps} from '@components/BlockingViews/BlockingView';
import BlockingView from '@components/BlockingViews/BlockingView';
import Icon from '@components/Icon';
import TextBlock from '@components/TextBlock';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Log from '@libs/Log';
import variables from '@styles/variables';
import ONYXKEYS from '@src/ONYXKEYS';
import useEmptyLHNIllustration from './useEmptyLHNIllustration';

function LHNEmptyState() {
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const expensifyIcons = useMemoizedLazyExpensifyIcons(['MagnifyingGlass', 'Plus']);
const emptyLHNIllustration = useEmptyLHNIllustration();
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const [policy] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);

useEffect(() => {
Log.info('Woohoo! All caught up. Was rendered', false, {
reportsCount: Object.keys(reports ?? {}).length,
policyCount: Object.keys(policy ?? {}).length,
personalDetailsCount: Object.keys(personalDetails ?? {}).length,
Comment on lines +28 to +31

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.

Should we log this only once on first time render? Now it's logged every time reports, policy or personalDetails is updated.
This was existing logic so not a blocker.

});
}, [reports, policy, personalDetails]);

const subtitle = (
<View style={[styles.alignItemsCenter, styles.flexRow, styles.justifyContentCenter, styles.flexWrap, styles.textAlignCenter]}>
<TextBlock
color={theme.textSupporting}
textStyles={[styles.textAlignCenter, styles.textNormal]}
text={translate('common.emptyLHN.subtitleText1')}
/>
<Icon
src={expensifyIcons.MagnifyingGlass}
width={variables.emptyLHNIconWidth}
height={variables.emptyLHNIconHeight}
fill={theme.icon}
small
additionalStyles={styles.mh1}
/>
<TextBlock
color={theme.textSupporting}
textStyles={[styles.textAlignCenter, styles.textNormal]}
text={translate('common.emptyLHN.subtitleText2')}
/>
<Icon
src={expensifyIcons.Plus}
width={variables.emptyLHNIconWidth}
height={variables.emptyLHNIconHeight}
fill={theme.icon}
small
additionalStyles={styles.mh1}
/>
<TextBlock
color={theme.textSupporting}
textStyles={[styles.textAlignCenter, styles.textNormal]}
text={translate('common.emptyLHN.subtitleText3')}
/>
</View>
);

return (
<BlockingView
// eslint-disable-next-line react/jsx-props-no-spreading
{...(emptyLHNIllustration as BlockingViewProps)}
title={translate('common.emptyLHN.title')}
CustomSubtitle={subtitle}
accessibilityLabel={translate('common.emptyLHN.title')}
/>
);
}

export default LHNEmptyState;
127 changes: 20 additions & 107 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@ import {FlashList} from '@shopify/flash-list';
import type {ReactElement} from 'react';
import React, {memo, useCallback, useContext, useEffect, useMemo, useRef} from 'react';
import {StyleSheet, View} from 'react-native';
import type {BlockingViewProps} from '@components/BlockingViews/BlockingView';
import BlockingView from '@components/BlockingViews/BlockingView';
import Icon from '@components/Icon';
import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider';
import TextBlock from '@components/TextBlock';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePrevious from '@hooks/usePrevious';
import useReportAttributes from '@hooks/useReportAttributes';
import useRootNavigationState from '@hooks/useRootNavigationState';
import useScrollEventEmitter from '@hooks/useScrollEventEmitter';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import getPlatform from '@libs/getPlatform';
import Log from '@libs/Log';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
Expand All @@ -32,7 +25,6 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject';
import OptionRowLHNData from './OptionRowLHNData';
import OptionRowRendererComponent from './OptionRowRendererComponent';
import type {LHNOptionsListProps, RenderItemProps} from './types';
import useEmptyLHNIllustration from './useEmptyLHNIllustration';

const keyExtractor = (item: Report) => `report_${item.reportID}`;
const platform = getPlatform();
Expand All @@ -44,8 +36,6 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
const flashListRef = useRef<FlashListRef<Report>>(null);
const route = useRoute();
const isScreenFocused = useIsFocused();
const expensifyIcons = useMemoizedLazyExpensifyIcons(['MagnifyingGlass', 'Plus']);

const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const reportAttributes = useReportAttributes();
const [policy] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
Expand All @@ -55,13 +45,10 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
const [isFullscreenVisible] = useOnyx(ONYXKEYS.FULLSCREEN_VISIBILITY);
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();

const theme = useTheme();
const styles = useThemeStyles();
const {translate, localeCompare} = useLocalize();
const isReportsSplitNavigatorLast = useRootNavigationState((state) => state?.routes?.at(-1)?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR);
const shouldShowEmptyLHN = data.length === 0;
const estimatedItemSize = optionMode === CONST.OPTION_MODE.COMPACT ? variables.optionRowHeightCompact : variables.optionRowHeight;
const emptyLHNIllustration = useEmptyLHNIllustration();

const firstReportIDWithGBRorRBR = useMemo(() => {
const firstReportWithGBRorRBR = data.find((report) => {
Expand Down Expand Up @@ -90,58 +77,6 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
// Hides the tooltip when the user is scrolling and displays it once scrolling stops.
const triggerScrollEvent = useScrollEventEmitter();

const emptyLHNSubtitle = useMemo(
() => (
<View style={[styles.alignItemsCenter, styles.flexRow, styles.justifyContentCenter, styles.flexWrap, styles.textAlignCenter]}>
<TextBlock
color={theme.textSupporting}
textStyles={[styles.textAlignCenter, styles.textNormal]}
text={translate('common.emptyLHN.subtitleText1')}
/>
<Icon
src={expensifyIcons.MagnifyingGlass}
width={variables.emptyLHNIconWidth}
height={variables.emptyLHNIconHeight}
fill={theme.icon}
small
additionalStyles={styles.mh1}
/>
<TextBlock
color={theme.textSupporting}
textStyles={[styles.textAlignCenter, styles.textNormal]}
text={translate('common.emptyLHN.subtitleText2')}
/>
<Icon
src={expensifyIcons.Plus}
width={variables.emptyLHNIconWidth}
height={variables.emptyLHNIconHeight}
fill={theme.icon}
small
additionalStyles={styles.mh1}
/>
<TextBlock
color={theme.textSupporting}
textStyles={[styles.textAlignCenter, styles.textNormal]}
text={translate('common.emptyLHN.subtitleText3')}
/>
</View>
),
[
styles.alignItemsCenter,
styles.flexRow,
styles.justifyContentCenter,
styles.flexWrap,
styles.textAlignCenter,
styles.mh1,
theme.icon,
theme.textSupporting,
styles.textNormal,
translate,
expensifyIcons.MagnifyingGlass,
expensifyIcons.Plus,
],
);

/**
* Function which renders a row in the list
*/
Expand Down Expand Up @@ -260,49 +195,27 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
});
}, [getScrollOffset, route]);

// eslint-disable-next-line rulesdir/prefer-early-return
useEffect(() => {
if (shouldShowEmptyLHN) {
Log.info('Woohoo! All caught up. Was rendered', false, {
reportsCount: Object.keys(reports ?? {}).length,
policyCount: Object.keys(policy ?? {}).length,
personalDetailsCount: Object.keys(personalDetails ?? {}).length,
reportsIDsFromUseReportsCount: data.length,
});
}
}, [data.length, shouldShowEmptyLHN, reports, policy, personalDetails]);

return (
<View style={[style ?? styles.flex1, shouldShowEmptyLHN ? styles.emptyLHNWrapper : undefined]}>
{shouldShowEmptyLHN ? (
<BlockingView
// eslint-disable-next-line react/jsx-props-no-spreading
{...(emptyLHNIllustration as BlockingViewProps)}
title={translate('common.emptyLHN.title')}
CustomSubtitle={emptyLHNSubtitle}
accessibilityLabel={translate('common.emptyLHN.title')}
/>
) : (
<FlashList
ref={flashListRef}
indicatorStyle="white"
keyboardShouldPersistTaps="always"
CellRendererComponent={OptionRowRendererComponent}
contentContainerStyle={StyleSheet.flatten(contentContainerStyles)}
data={data}
testID="lhn-options-list"
keyExtractor={keyExtractor}
renderItem={renderItem}
extraData={extraData}
showsVerticalScrollIndicator={false}
onLayout={onLayout}
onScroll={onScroll}
initialScrollIndex={isWeb ? getScrollIndex(route) : undefined}
maintainVisibleContentPosition={{disabled: true}}
drawDistance={250}
removeClippedSubviews
/>
)}
<View style={style ?? styles.flex1}>
<FlashList
ref={flashListRef}
indicatorStyle="white"
keyboardShouldPersistTaps="always"
CellRendererComponent={OptionRowRendererComponent}
contentContainerStyle={StyleSheet.flatten(contentContainerStyles)}
data={data}
testID="lhn-options-list"
keyExtractor={keyExtractor}
renderItem={renderItem}
extraData={extraData}
showsVerticalScrollIndicator={false}
onLayout={onLayout}
onScroll={onScroll}
initialScrollIndex={isWeb ? getScrollIndex(route) : undefined}
maintainVisibleContentPosition={{disabled: true}}
drawDistance={250}
removeClippedSubviews
/>
</View>
);
}
Expand Down
27 changes: 18 additions & 9 deletions src/pages/inbox/sidebar/SidebarLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {StyleSheet, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {EdgeInsets} from 'react-native-safe-area-context';
import type {ValueOf} from 'type-fest';
import LHNEmptyState from '@components/LHNOptionsList/LHNEmptyState';
import LHNOptionsList from '@components/LHNOptionsList/LHNOptionsList';
import OptionsListSkeletonView from '@components/OptionsListSkeletonView';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -84,18 +85,26 @@ function SidebarLinks({insets, optionListItems, priorityMode = CONST.PRIORITY_MO
// eslint-disable-next-line react-hooks/exhaustive-deps
const contentContainerStyles = useMemo(() => StyleSheet.flatten([styles.pt2, {paddingBottom: StyleUtils.getSafeAreaMargins(insets).marginBottom}]), [insets]);

const shouldShowEmptyLHN = optionListItems.length === 0;

return (
<View style={[styles.flex1, styles.h100]}>
<View style={[styles.pRelative, styles.flex1]}>
<LHNOptionsList
style={styles.flex1}
contentContainerStyles={contentContainerStyles}
data={optionListItems}
onSelectRow={showReportPage}
shouldDisableFocusOptions={shouldUseNarrowLayout}
optionMode={viewMode}
onFirstItemRendered={setSidebarLoaded}
/>
{shouldShowEmptyLHN ? (
<View style={[styles.flex1, styles.emptyLHNWrapper]}>
<LHNEmptyState />
</View>
) : (
<LHNOptionsList
style={styles.flex1}
contentContainerStyles={contentContainerStyles}
data={optionListItems}
onSelectRow={showReportPage}
shouldDisableFocusOptions={shouldUseNarrowLayout}
optionMode={viewMode}
onFirstItemRendered={setSidebarLoaded}
/>
)}
{isLoadingReportData && optionListItems?.length === 0 && (
<View style={[StyleSheet.absoluteFill, styles.appBG, styles.mt3]}>
<OptionsListSkeletonView
Expand Down
Loading