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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
import {Pressable, ScrollView, View} from 'react-native'
import {moderateProfile, type ModerationOpts} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {createHitslop, HITSLOP_10} from '#/lib/constants'
import {makeProfileLink} from '#/lib/routes/links'
import {sanitizeDisplayName} from '#/lib/strings/display-names'
import {sanitizeHandle} from '#/lib/strings/handles'
import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {UserAvatar} from '#/view/com/util/UserAvatar'
import {BlockDrawerGesture} from '#/view/shell/BlockDrawerGesture'
import {atoms as a} from '#/alf'
import {Button, ButtonIcon} from '#/components/Button'
import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times'
import * as Layout from '#/components/Layout'
import {Link} from '#/components/Link'
import {Text} from '#/components/Typography'
import {useSimpleVerificationState} from '#/components/verification'
import {VerificationCheck} from '#/components/verification/VerificationCheck'
import type * as bsky from '#/types/bsky'
export function SearchHistory({
searchHistory,
selectedProfiles,
onItemClick,
onProfileClick,
onRemoveItemClick,
onRemoveProfileClick,
}: {
searchHistory: string[]
selectedProfiles: bsky.profile.AnyProfileView[]
onItemClick: (item: string) => void
onProfileClick: (profile: bsky.profile.AnyProfileView) => void
onRemoveItemClick: (item: string) => void
onRemoveProfileClick: (profile: bsky.profile.AnyProfileView) => void
}) {
const {_} = useLingui()
const moderationOpts = useModerationOpts()
return (
<Layout.Content
keyboardDismissMode="interactive"
keyboardShouldPersistTaps="handled">
<View style={[a.w_full, a.gap_md]}>
{(searchHistory.length > 0 || selectedProfiles.length > 0) && (
<View style={[a.px_lg, a.pt_sm]}>
<Text style={[a.text_md, a.font_bold]}>
<Trans>Recent Searches</Trans>
</Text>
</View>
)}
{selectedProfiles.length > 0 && (
<View>
<BlockDrawerGesture>
<ScrollView
horizontal
keyboardShouldPersistTaps="handled"
showsHorizontalScrollIndicator={false}
contentContainerStyle={[
a.px_lg,
a.flex_row,
a.flex_nowrap,
a.gap_xl,
]}>
{moderationOpts &&
selectedProfiles.map(profile => (
<RecentProfileItem
key={profile.did}
profile={profile}
moderationOpts={moderationOpts}
onPress={() => onProfileClick(profile)}
onRemove={() => onRemoveProfileClick(profile)}
/>
))}
</ScrollView>
</BlockDrawerGesture>
</View>
)}
{searchHistory.length > 0 && (
<View style={[a.px_lg, a.pt_sm]}>
{searchHistory.slice(0, 5).map((historyItem, index) => (
<View key={index} style={[a.flex_row, a.align_center]}>
<Pressable
accessibilityRole="button"
onPress={() => onItemClick(historyItem)}
hitSlop={HITSLOP_10}
style={[a.flex_1, a.py_sm]}>
<Text style={[a.text_md]}>{historyItem}</Text>
</Pressable>
<Button
label={_(msg`Remove ${historyItem}`)}
onPress={() => onRemoveItemClick(historyItem)}
size="small"
variant="ghost"
color="secondary"
shape="round">
<ButtonIcon icon={XIcon} />
</Button>
</View>
))}
</View>
)}
</View>
</Layout.Content>
)
}
function RecentProfileItem({
profile,
moderationOpts,
onPress,
onRemove,
}: {
profile: bsky.profile.AnyProfileView
moderationOpts: ModerationOpts
onPress: () => void
onRemove: () => void
}) {
const {_} = useLingui()
const width = 80
const moderation = moderateProfile(profile, moderationOpts)
const name = sanitizeDisplayName(
profile.displayName || sanitizeHandle(profile.handle),
moderation.ui('displayName'),
)
const verification = useSimpleVerificationState({profile})
return (
<View style={[a.relative]}>
<Link
to={makeProfileLink(profile)}
label={profile.handle}
onPress={onPress}
style={[
a.flex_col,
a.align_center,
a.gap_xs,
{
width,
},
]}>
<UserAvatar
avatar={profile.avatar}
type={profile.associated?.labeler ? 'labeler' : 'user'}
size={width - 8}
moderation={moderation.ui('avatar')}
/>
<View style={[a.flex_row, a.align_center, a.justify_center, a.w_full]}>
<Text emoji style={[a.text_xs, a.leading_snug]} numberOfLines={1}>
{name}
</Text>
{verification.showBadge && (
<View style={[a.pl_2xs]}>
<VerificationCheck
width={10}
verifier={verification.role === 'verifier'}
/>
</View>
)}
</View>
</Link>
<Button
label={_(msg`Remove profile`)}
hitSlop={createHitslop(6)}
size="tiny"
variant="outline"
color="secondary"
shape="round"
onPress={onRemove}
style={[
a.absolute,
{
top: 0,
right: 0,
height: 18,
width: 18,
},
]}>
<ButtonIcon icon={XIcon} />
</Button>
</View>
)
}
|