forked from tetherto/pearpass-app-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.jsx
More file actions
121 lines (109 loc) · 3.35 KB
/
index.jsx
File metadata and controls
121 lines (109 loc) · 3.35 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
import { useMemo } from 'react'
import { useLingui } from '@lingui/react/macro'
import { AUTHENTICATOR_ENABLED } from '@tetherto/pearpass-lib-constants'
import {
NavbarListItem,
useBottomSheetClose,
useTheme
} from '@tetherto/pearpass-lib-ui-kit'
import { TwoFactorAuthenticationOutlined } from '@tetherto/pearpass-lib-ui-kit/icons'
import {
RECORD_TYPES,
useRecordCountsByType
} from '@tetherto/pearpass-lib-vault'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { useSharedFilter } from '../../context/SharedFilterContext'
import { useRecordMenuItems } from '../../hooks/useRecordMenuItems'
import { SheetHeader } from '../BottomSheet/SheetHeader'
import { Layout } from '../Layout'
/**
* @typedef {Object} BottomSheetCategorySelectorContentProps
* @property {string} [recordType]
* @property {(type: string) => void} [onSelect]
* @property {string[]} [exclude]
* @property {string} [title]
* @property {'filter' | 'add-item'} [variant]
*/
/**
* @param {BottomSheetCategorySelectorContentProps} [props]
*/
export const BottomSheetCategorySelectorContent = (props = {}) => {
const { recordType, onSelect, exclude, title, variant = 'filter' } = props
const { t } = useLingui()
const { theme } = useTheme()
const collapse = useBottomSheetClose()
const { state } = useSharedFilter()
const { bottom } = useSafeAreaInsets()
const isAddItemVariant = variant === 'add-item'
const menuItems = useRecordMenuItems({
exclude: exclude ?? (isAddItemVariant ? ['all'] : ['password'])
})
const selectorItems = useMemo(() => {
if (!isAddItemVariant) return menuItems
return [
...menuItems.map((item) =>
item.type === RECORD_TYPES.CREDIT_CARD
? { ...item, name: t`Credit Card` }
: item
),
...(AUTHENTICATOR_ENABLED
? [
{
name: t`Authenticator Code`,
type: RECORD_TYPES.OTP,
icon: TwoFactorAuthenticationOutlined
}
]
: [])
]
}, [isAddItemVariant, menuItems, t])
const { data: recordCountsByType } = useRecordCountsByType({
variables: {
filters: {
folder:
state?.folder !== 'allFolder' && state?.folder !== 'favorite'
? state?.folder
: '',
...(state?.isFavorite ? { isFavorite: true } : {})
}
}
})
const handleSelect = (type) => {
onSelect?.(type)
collapse()
}
return (
<Layout
mode="sheet"
scrollable
contentStyle={{ padding: 0, paddingBottom: bottom }}
header={
<SheetHeader
title={title ?? (isAddItemVariant ? t`Add Item` : t`Categories`)}
onClose={collapse}
/>
}
>
{selectorItems.map((item, index) => {
const Icon = item.icon
return (
<NavbarListItem
key={item.type}
label={item.name}
count={
isAddItemVariant ? undefined : recordCountsByType?.[item.type]
}
selected={!isAddItemVariant && recordType === item.type}
platform="mobile"
showDivider={index < selectorItems.length - 1}
onClick={() => handleSelect(item.type)}
icon={
Icon ? <Icon color={theme.colors.colorTextPrimary} /> : undefined
}
iconSize={16}
/>
)
})}
</Layout>
)
}