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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
import {type AppBskyActorDefs, AppBskyGraphDefs, AtUri} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useNavigation} from '@react-navigation/native'
import {type NavigationProp} from '#/lib/routes/types'
import {shareUrl} from '#/lib/sharing'
import {toShareUrl} from '#/lib/strings/url-helpers'
import {logger} from '#/logger'
import {isWeb} from '#/platform/detection'
import {useModalControls} from '#/state/modals'
import {
useListBlockMutation,
useListDeleteMutation,
useListMuteMutation,
} from '#/state/queries/list'
import {useRemoveFeedMutation} from '#/state/queries/preferences'
import {useSession} from '#/state/session'
import {Button, ButtonIcon} from '#/components/Button'
import {useDialogControl} from '#/components/Dialog'
import {ArrowOutOfBoxModified_Stroke2_Corner2_Rounded as ShareIcon} from '#/components/icons/ArrowOutOfBox'
import {ChainLink_Stroke2_Corner0_Rounded as ChainLink} from '#/components/icons/ChainLink'
import {DotGrid_Stroke2_Corner0_Rounded as DotGridIcon} from '#/components/icons/DotGrid'
import {PencilLine_Stroke2_Corner0_Rounded as PencilLineIcon} from '#/components/icons/Pencil'
import {PersonCheck_Stroke2_Corner0_Rounded as PersonCheckIcon} from '#/components/icons/Person'
import {Pin_Stroke2_Corner0_Rounded as PinIcon} from '#/components/icons/Pin'
import {SpeakerVolumeFull_Stroke2_Corner0_Rounded as UnmuteIcon} from '#/components/icons/Speaker'
import {Trash_Stroke2_Corner0_Rounded as TrashIcon} from '#/components/icons/Trash'
import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning'
import * as Menu from '#/components/Menu'
import {
ReportDialog,
useReportDialogControl,
} from '#/components/moderation/ReportDialog'
import * as Prompt from '#/components/Prompt'
import * as Toast from '#/components/Toast'
export function MoreOptionsMenu({
list,
savedFeedConfig,
}: {
list: AppBskyGraphDefs.ListView
savedFeedConfig?: AppBskyActorDefs.SavedFeed
}) {
const {_} = useLingui()
const {currentAccount} = useSession()
const {openModal} = useModalControls()
const deleteListPromptControl = useDialogControl()
const reportDialogControl = useReportDialogControl()
const navigation = useNavigation<NavigationProp>()
const {mutateAsync: removeSavedFeed} = useRemoveFeedMutation()
const {mutateAsync: deleteList} = useListDeleteMutation()
const {mutateAsync: muteList} = useListMuteMutation()
const {mutateAsync: blockList} = useListBlockMutation()
const isCurateList = list.purpose === AppBskyGraphDefs.CURATELIST
const isModList = list.purpose === AppBskyGraphDefs.MODLIST
const isBlocking = !!list.viewer?.blocked
const isMuting = !!list.viewer?.muted
const isPinned = Boolean(savedFeedConfig?.pinned)
const isOwner = currentAccount?.did === list.creator.did
const onPressShare = () => {
const {rkey} = new AtUri(list.uri)
const url = toShareUrl(`/profile/${list.creator.did}/lists/${rkey}`)
shareUrl(url)
}
const onRemoveFromSavedFeeds = async () => {
if (!savedFeedConfig) return
try {
await removeSavedFeed(savedFeedConfig)
Toast.show(_(msg`Removed from your feeds`))
} catch (e) {
Toast.show(_(msg`There was an issue contacting the server`), {
type: 'error',
})
logger.error('Failed to remove pinned list', {message: e})
}
}
const onPressEdit = () => {
openModal({
name: 'create-or-edit-list',
list,
})
}
const onPressDelete = async () => {
await deleteList({uri: list.uri})
if (savedFeedConfig) {
await removeSavedFeed(savedFeedConfig)
}
Toast.show(_(msg({message: 'List deleted', context: 'toast'})))
if (navigation.canGoBack()) {
navigation.goBack()
} else {
navigation.navigate('Home')
}
}
const onUnpinModList = async () => {
try {
if (!savedFeedConfig) return
await removeSavedFeed(savedFeedConfig)
Toast.show(_(msg`Unpinned list`))
} catch {
Toast.show(_(msg`Failed to unpin list`), {
type: 'error',
})
}
}
const onUnsubscribeMute = async () => {
try {
await muteList({uri: list.uri, mute: false})
Toast.show(_(msg({message: 'List unmuted', context: 'toast'})))
logger.metric(
'moderation:unsubscribedFromList',
{listType: 'mute'},
{statsig: true},
)
} catch {
Toast.show(
_(
msg`There was an issue. Please check your internet connection and try again.`,
),
)
}
}
const onUnsubscribeBlock = async () => {
try {
await blockList({uri: list.uri, block: false})
Toast.show(_(msg({message: 'List unblocked', context: 'toast'})))
logger.metric(
'moderation:unsubscribedFromList',
{listType: 'block'},
{statsig: true},
)
} catch {
Toast.show(
_(
msg`There was an issue. Please check your internet connection and try again.`,
),
)
}
}
return (
<>
<Menu.Root>
<Menu.Trigger label={_(msg`More options`)}>
{({props}) => (
<Button
label={props.accessibilityLabel}
testID="moreOptionsBtn"
size="small"
color="secondary"
shape="round"
{...props}>
<ButtonIcon icon={DotGridIcon} />
</Button>
)}
</Menu.Trigger>
<Menu.Outer>
<Menu.Group>
<Menu.Item
label={isWeb ? _(msg`Copy link to list`) : _(msg`Share via...`)}
onPress={onPressShare}>
<Menu.ItemText>
{isWeb ? (
<Trans>Copy link to list</Trans>
) : (
<Trans>Share via...</Trans>
)}
</Menu.ItemText>
<Menu.ItemIcon
position="right"
icon={isWeb ? ChainLink : ShareIcon}
/>
</Menu.Item>
{savedFeedConfig && (
<Menu.Item
label={_(msg`Remove from my feeds`)}
onPress={onRemoveFromSavedFeeds}>
<Menu.ItemText>
<Trans>Remove from my feeds</Trans>
</Menu.ItemText>
<Menu.ItemIcon position="right" icon={TrashIcon} />
</Menu.Item>
)}
</Menu.Group>
<Menu.Divider />
{isOwner ? (
<Menu.Group>
<Menu.Item
label={_(msg`Edit list details`)}
onPress={onPressEdit}>
<Menu.ItemText>
<Trans>Edit list details</Trans>
</Menu.ItemText>
<Menu.ItemIcon position="right" icon={PencilLineIcon} />
</Menu.Item>
<Menu.Item
label={_(msg`Delete list`)}
onPress={deleteListPromptControl.open}>
<Menu.ItemText>
<Trans>Delete list</Trans>
</Menu.ItemText>
<Menu.ItemIcon position="right" icon={TrashIcon} />
</Menu.Item>
</Menu.Group>
) : (
<Menu.Group>
<Menu.Item
label={_(msg`Report list`)}
onPress={reportDialogControl.open}>
<Menu.ItemText>
<Trans>Report list</Trans>
</Menu.ItemText>
<Menu.ItemIcon position="right" icon={WarningIcon} />
</Menu.Item>
</Menu.Group>
)}
{isModList && isPinned && (
<>
<Menu.Divider />
<Menu.Group>
<Menu.Item
label={_(msg`Unpin moderation list`)}
onPress={onUnpinModList}>
<Menu.ItemText>
<Trans>Unpin moderation list</Trans>
</Menu.ItemText>
<Menu.ItemIcon icon={PinIcon} />
</Menu.Item>
</Menu.Group>
</>
)}
{isCurateList && (isBlocking || isMuting) && (
<>
<Menu.Divider />
<Menu.Group>
{isBlocking && (
<Menu.Item
label={_(msg`Unblock list`)}
onPress={onUnsubscribeBlock}>
<Menu.ItemText>
<Trans>Unblock list</Trans>
</Menu.ItemText>
<Menu.ItemIcon icon={PersonCheckIcon} />
</Menu.Item>
)}
{isMuting && (
<Menu.Item
label={_(msg`Unmute list`)}
onPress={onUnsubscribeMute}>
<Menu.ItemText>
<Trans>Unmute list</Trans>
</Menu.ItemText>
<Menu.ItemIcon icon={UnmuteIcon} />
</Menu.Item>
)}
</Menu.Group>
</>
)}
</Menu.Outer>
</Menu.Root>
<Prompt.Basic
control={deleteListPromptControl}
title={_(msg`Delete this list?`)}
description={_(
msg`If you delete this list, you won't be able to recover it.`,
)}
onConfirm={onPressDelete}
confirmButtonCta={_(msg`Delete`)}
confirmButtonColor="negative"
/>
<ReportDialog
control={reportDialogControl}
subject={{
...list,
$type: 'app.bsky.graph.defs#listView',
}}
/>
</>
)
}
|