Skip to content

Commit cfb0be8

Browse files
estrattonbaileyhaileyok
authored andcommitted
Update muted words dialog with expiresAt and actorTarget (#4801)
* WIP not working dropdown * Update MutedWords dialog * Add i18n formatDistance * Comments * Handle text wrapping * Update label copy Co-authored-by: Hailey <[email protected]> * Fix alignment * Improve translation output * Revert toggle changes * Better types for useFormatDistance * Tweaks * Integrate new sdk version into TagMenu * Use ampersand Co-authored-by: surfdude29 <[email protected]> * Bump SDK --------- Co-authored-by: Hailey <[email protected]> Co-authored-by: surfdude29 <[email protected]> (cherry picked from commit b0e130a)
1 parent abfa4bb commit cfb0be8

File tree

5 files changed

+427
-122
lines changed

5 files changed

+427
-122
lines changed

src/components/TagMenu/index.tsx

+35-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import React from 'react'
22
import {View} from 'react-native'
3-
import {useNavigation} from '@react-navigation/native'
4-
import {useLingui} from '@lingui/react'
53
import {msg, Trans} from '@lingui/macro'
4+
import {useLingui} from '@lingui/react'
5+
import {useNavigation} from '@react-navigation/native'
66

7-
import {atoms as a, native, useTheme} from '#/alf'
8-
import * as Dialog from '#/components/Dialog'
9-
import {Text} from '#/components/Typography'
10-
import {Button, ButtonText} from '#/components/Button'
11-
import {MagnifyingGlass2_Stroke2_Corner0_Rounded as Search} from '#/components/icons/MagnifyingGlass2'
12-
import {Person_Stroke2_Corner0_Rounded as Person} from '#/components/icons/Person'
13-
import {Mute_Stroke2_Corner0_Rounded as Mute} from '#/components/icons/Mute'
14-
import {Divider} from '#/components/Divider'
15-
import {Link} from '#/components/Link'
167
import {makeSearchLink} from '#/lib/routes/links'
178
import {NavigationProp} from '#/lib/routes/types'
9+
import {isInvalidHandle} from '#/lib/strings/handles'
1810
import {
1911
usePreferencesQuery,
12+
useRemoveMutedWordsMutation,
2013
useUpsertMutedWordsMutation,
21-
useRemoveMutedWordMutation,
2214
} from '#/state/queries/preferences'
15+
import {atoms as a, native, useTheme} from '#/alf'
16+
import {Button, ButtonText} from '#/components/Button'
17+
import * as Dialog from '#/components/Dialog'
18+
import {Divider} from '#/components/Divider'
19+
import {MagnifyingGlass2_Stroke2_Corner0_Rounded as Search} from '#/components/icons/MagnifyingGlass2'
20+
import {Mute_Stroke2_Corner0_Rounded as Mute} from '#/components/icons/Mute'
21+
import {Person_Stroke2_Corner0_Rounded as Person} from '#/components/icons/Person'
22+
import {Link} from '#/components/Link'
2323
import {Loader} from '#/components/Loader'
24-
import {isInvalidHandle} from '#/lib/strings/handles'
24+
import {Text} from '#/components/Typography'
2525

2626
export function useTagMenuControl() {
2727
return Dialog.useDialogControl()
@@ -52,10 +52,10 @@ export function TagMenu({
5252
reset: resetUpsert,
5353
} = useUpsertMutedWordsMutation()
5454
const {
55-
mutateAsync: removeMutedWord,
55+
mutateAsync: removeMutedWords,
5656
variables: optimisticRemove,
5757
reset: resetRemove,
58-
} = useRemoveMutedWordMutation()
58+
} = useRemoveMutedWordsMutation()
5959
const displayTag = '#' + tag
6060

6161
const isMuted = Boolean(
@@ -65,9 +65,20 @@ export function TagMenu({
6565
optimisticUpsert?.find(
6666
m => m.value === tag && m.targets.includes('tag'),
6767
)) &&
68-
!(optimisticRemove?.value === tag),
68+
!optimisticRemove?.find(m => m?.value === tag),
6969
)
7070

71+
/*
72+
* Mute word records that exactly match the tag in question.
73+
*/
74+
const removeableMuteWords = React.useMemo(() => {
75+
return (
76+
preferences?.moderationPrefs.mutedWords?.filter(word => {
77+
return word.value === tag
78+
}) || []
79+
)
80+
}, [tag, preferences?.moderationPrefs?.mutedWords])
81+
7182
return (
7283
<>
7384
{children}
@@ -212,13 +223,16 @@ export function TagMenu({
212223
control.close(() => {
213224
if (isMuted) {
214225
resetUpsert()
215-
removeMutedWord({
216-
value: tag,
217-
targets: ['tag'],
218-
})
226+
removeMutedWords(removeableMuteWords)
219227
} else {
220228
resetRemove()
221-
upsertMutedWord([{value: tag, targets: ['tag']}])
229+
upsertMutedWord([
230+
{
231+
value: tag,
232+
targets: ['tag'],
233+
actorTarget: 'all',
234+
},
235+
])
222236
}
223237
})
224238
}}>

src/components/TagMenu/index.web.tsx

+25-11
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import {msg} from '@lingui/macro'
33
import {useLingui} from '@lingui/react'
44
import {useNavigation} from '@react-navigation/native'
55

6-
import {isInvalidHandle} from '#/lib/strings/handles'
7-
import {EventStopper} from '#/view/com/util/EventStopper'
8-
import {NativeDropdown} from '#/view/com/util/forms/NativeDropdown'
96
import {NavigationProp} from '#/lib/routes/types'
7+
import {isInvalidHandle} from '#/lib/strings/handles'
8+
import {enforceLen} from '#/lib/strings/helpers'
109
import {
1110
usePreferencesQuery,
11+
useRemoveMutedWordsMutation,
1212
useUpsertMutedWordsMutation,
13-
useRemoveMutedWordMutation,
1413
} from '#/state/queries/preferences'
15-
import {enforceLen} from '#/lib/strings/helpers'
14+
import {EventStopper} from '#/view/com/util/EventStopper'
15+
import {NativeDropdown} from '#/view/com/util/forms/NativeDropdown'
1616
import {web} from '#/alf'
1717
import * as Dialog from '#/components/Dialog'
1818

@@ -47,19 +47,30 @@ export function TagMenu({
4747
const {data: preferences} = usePreferencesQuery()
4848
const {mutateAsync: upsertMutedWord, variables: optimisticUpsert} =
4949
useUpsertMutedWordsMutation()
50-
const {mutateAsync: removeMutedWord, variables: optimisticRemove} =
51-
useRemoveMutedWordMutation()
50+
const {mutateAsync: removeMutedWords, variables: optimisticRemove} =
51+
useRemoveMutedWordsMutation()
5252
const isMuted = Boolean(
5353
(preferences?.moderationPrefs.mutedWords?.find(
5454
m => m.value === tag && m.targets.includes('tag'),
5555
) ??
5656
optimisticUpsert?.find(
5757
m => m.value === tag && m.targets.includes('tag'),
5858
)) &&
59-
!(optimisticRemove?.value === tag),
59+
!optimisticRemove?.find(m => m?.value === tag),
6060
)
6161
const truncatedTag = '#' + enforceLen(tag, 15, true, 'middle')
6262

63+
/*
64+
* Mute word records that exactly match the tag in question.
65+
*/
66+
const removeableMuteWords = React.useMemo(() => {
67+
return (
68+
preferences?.moderationPrefs.mutedWords?.filter(word => {
69+
return word.value === tag
70+
}) || []
71+
)
72+
}, [tag, preferences?.moderationPrefs?.mutedWords])
73+
6374
const dropdownItems = React.useMemo(() => {
6475
return [
6576
{
@@ -105,9 +116,11 @@ export function TagMenu({
105116
: _(msg`Mute ${truncatedTag}`),
106117
onPress() {
107118
if (isMuted) {
108-
removeMutedWord({value: tag, targets: ['tag']})
119+
removeMutedWords(removeableMuteWords)
109120
} else {
110-
upsertMutedWord([{value: tag, targets: ['tag']}])
121+
upsertMutedWord([
122+
{value: tag, targets: ['tag'], actorTarget: 'all'},
123+
])
111124
}
112125
},
113126
testID: 'tagMenuMute',
@@ -129,7 +142,8 @@ export function TagMenu({
129142
tag,
130143
truncatedTag,
131144
upsertMutedWord,
132-
removeMutedWord,
145+
removeMutedWords,
146+
removeableMuteWords,
133147
])
134148

135149
return (

0 commit comments

Comments
 (0)