Skip to content

Commit 036b7d6

Browse files
refactor: extract LHNEmptyState, conditionally render from SidebarLinks
1 parent fb62baa commit 036b7d6

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react';
2+
import {View} from 'react-native';
3+
import type {BlockingViewProps} from '@components/BlockingViews/BlockingView';
4+
import BlockingView from '@components/BlockingViews/BlockingView';
5+
import Icon from '@components/Icon';
6+
import TextBlock from '@components/TextBlock';
7+
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
8+
import useLocalize from '@hooks/useLocalize';
9+
import useTheme from '@hooks/useTheme';
10+
import useThemeStyles from '@hooks/useThemeStyles';
11+
import variables from '@styles/variables';
12+
import useEmptyLHNIllustration from './useEmptyLHNIllustration';
13+
14+
function LHNEmptyState() {
15+
const theme = useTheme();
16+
const styles = useThemeStyles();
17+
const {translate} = useLocalize();
18+
const expensifyIcons = useMemoizedLazyExpensifyIcons(['MagnifyingGlass', 'Plus']);
19+
const emptyLHNIllustration = useEmptyLHNIllustration();
20+
21+
const subtitle = (
22+
<View style={[styles.alignItemsCenter, styles.flexRow, styles.justifyContentCenter, styles.flexWrap, styles.textAlignCenter]}>
23+
<TextBlock
24+
color={theme.textSupporting}
25+
textStyles={[styles.textAlignCenter, styles.textNormal]}
26+
text={translate('common.emptyLHN.subtitleText1')}
27+
/>
28+
<Icon
29+
src={expensifyIcons.MagnifyingGlass}
30+
width={variables.emptyLHNIconWidth}
31+
height={variables.emptyLHNIconHeight}
32+
fill={theme.icon}
33+
small
34+
additionalStyles={styles.mh1}
35+
/>
36+
<TextBlock
37+
color={theme.textSupporting}
38+
textStyles={[styles.textAlignCenter, styles.textNormal]}
39+
text={translate('common.emptyLHN.subtitleText2')}
40+
/>
41+
<Icon
42+
src={expensifyIcons.Plus}
43+
width={variables.emptyLHNIconWidth}
44+
height={variables.emptyLHNIconHeight}
45+
fill={theme.icon}
46+
small
47+
additionalStyles={styles.mh1}
48+
/>
49+
<TextBlock
50+
color={theme.textSupporting}
51+
textStyles={[styles.textAlignCenter, styles.textNormal]}
52+
text={translate('common.emptyLHN.subtitleText3')}
53+
/>
54+
</View>
55+
);
56+
57+
return (
58+
<BlockingView
59+
// eslint-disable-next-line react/jsx-props-no-spreading
60+
{...(emptyLHNIllustration as BlockingViewProps)}
61+
title={translate('common.emptyLHN.title')}
62+
CustomSubtitle={subtitle}
63+
accessibilityLabel={translate('common.emptyLHN.title')}
64+
/>
65+
);
66+
}
67+
68+
export default LHNEmptyState;

src/pages/inbox/sidebar/SidebarLinks.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import {StyleSheet, View} from 'react-native';
33
import type {OnyxEntry} from 'react-native-onyx';
44
import type {EdgeInsets} from 'react-native-safe-area-context';
55
import type {ValueOf} from 'type-fest';
6+
import LHNEmptyState from '@components/LHNOptionsList/LHNEmptyState';
67
import LHNOptionsList from '@components/LHNOptionsList/LHNOptionsList';
78
import OptionsListSkeletonView from '@components/OptionsListSkeletonView';
9+
import useConfirmReadyToOpenApp from '@hooks/useConfirmReadyToOpenApp';
810
import useOnyx from '@hooks/useOnyx';
911
import useResponsiveLayout from '@hooks/useResponsiveLayout';
1012
import useStyleUtils from '@hooks/useStyleUtils';
@@ -40,6 +42,8 @@ function SidebarLinks({insets, optionListItems, priorityMode = CONST.PRIORITY_MO
4042
const {shouldUseNarrowLayout} = useResponsiveLayout();
4143
const [isLoadingReportData = true] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA);
4244

45+
useConfirmReadyToOpenApp();
46+
4347
useEffect(() => {
4448
ReportActionContextMenu.hideContextMenu(false);
4549
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -84,18 +88,26 @@ function SidebarLinks({insets, optionListItems, priorityMode = CONST.PRIORITY_MO
8488
// eslint-disable-next-line react-hooks/exhaustive-deps
8589
const contentContainerStyles = useMemo(() => StyleSheet.flatten([styles.pt2, {paddingBottom: StyleUtils.getSafeAreaMargins(insets).marginBottom}]), [insets]);
8690

91+
const shouldShowEmptyLHN = optionListItems.length === 0 && !isLoadingReportData;
92+
8793
return (
8894
<View style={[styles.flex1, styles.h100]}>
8995
<View style={[styles.pRelative, styles.flex1]}>
90-
<LHNOptionsList
91-
style={styles.flex1}
92-
contentContainerStyles={contentContainerStyles}
93-
data={optionListItems}
94-
onSelectRow={showReportPage}
95-
shouldDisableFocusOptions={shouldUseNarrowLayout}
96-
optionMode={viewMode}
97-
onFirstItemRendered={setSidebarLoaded}
98-
/>
96+
{shouldShowEmptyLHN ? (
97+
<View style={[styles.flex1, styles.emptyLHNWrapper]}>
98+
<LHNEmptyState />
99+
</View>
100+
) : (
101+
<LHNOptionsList
102+
style={styles.flex1}
103+
contentContainerStyles={contentContainerStyles}
104+
data={optionListItems}
105+
onSelectRow={showReportPage}
106+
shouldDisableFocusOptions={shouldUseNarrowLayout}
107+
optionMode={viewMode}
108+
onFirstItemRendered={setSidebarLoaded}
109+
/>
110+
)}
99111
{isLoadingReportData && optionListItems?.length === 0 && (
100112
<View style={[StyleSheet.absoluteFill, styles.appBG, styles.mt3]}>
101113
<OptionsListSkeletonView

0 commit comments

Comments
 (0)