-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathSidebarLinks.tsx
108 lines (92 loc) · 4.5 KB
/
SidebarLinks.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import React, {memo, useCallback, useEffect, useMemo} from 'react';
import {InteractionManager, 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 LHNOptionsList from '@components/LHNOptionsList/LHNOptionsList';
import OptionsListSkeletonView from '@components/OptionsListSkeletonView';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import * as App from '@userActions/App';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Report} from '@src/types/onyx';
type SidebarLinksProps = {
/** Safe area insets required for mobile devices margins */
insets: EdgeInsets;
/** List of options to display */
optionListItems: string[];
/** Whether the reports are loading. When false it means they are ready to be used. */
isLoading: OnyxEntry<boolean>;
/** The chat priority mode */
priorityMode?: OnyxEntry<ValueOf<typeof CONST.PRIORITY_MODE>>;
/** Method to change currently active report */
isActiveReport: (reportID: string) => boolean;
/** ID of currently active workspace */
// eslint-disable-next-line react/no-unused-prop-types -- its used in withOnyx
activeWorkspaceID: string | undefined;
};
function SidebarLinks({insets, optionListItems, isLoading, priorityMode = CONST.PRIORITY_MODE.DEFAULT, isActiveReport}: SidebarLinksProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {updateLocale} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
useEffect(() => {
App.confirmReadyToOpenApp();
}, []);
useEffect(() => {
InteractionManager.runAfterInteractions(() => {
requestAnimationFrame(() => {
updateLocale();
});
});
ReportActionContextMenu.hideContextMenu(false);
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);
/**
* Show Report page with selected report id
*/
const showReportPage = useCallback(
(option: Report) => {
// Prevent opening Report page when clicking LHN row quickly after clicking FAB icon
// or when clicking the active LHN row on large screens
// or when continuously clicking different LHNs, only apply to small screen
// since getTopmostReportId always returns on other devices
const reportActionID = Navigation.getTopmostReportActionId();
if ((option.reportID === Navigation.getTopmostReportId() && !reportActionID) || (shouldUseNarrowLayout && isActiveReport(option.reportID) && !reportActionID)) {
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(option.reportID));
},
[shouldUseNarrowLayout, isActiveReport],
);
const viewMode = priorityMode === CONST.PRIORITY_MODE.GSD ? CONST.OPTION_MODE.COMPACT : CONST.OPTION_MODE.DEFAULT;
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
const contentContainerStyles = useMemo(() => StyleSheet.flatten([styles.sidebarListContainer, {paddingBottom: StyleUtils.getSafeAreaMargins(insets).marginBottom}]), [insets]);
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={App.setSidebarLoaded}
/>
{!!isLoading && optionListItems?.length === 0 && (
<View style={[StyleSheet.absoluteFillObject, styles.appBG]}>
<OptionsListSkeletonView shouldAnimate />
</View>
)}
</View>
</View>
);
}
SidebarLinks.displayName = 'SidebarLinks';
export default memo(SidebarLinks);