1
1
import React from 'react'
2
2
import { View } from 'react-native'
3
- import { useNavigation } from '@react-navigation/native'
4
- import { useLingui } from '@lingui/react'
5
3
import { msg , Trans } from '@lingui/macro'
4
+ import { useLingui } from '@lingui/react'
5
+ import { useNavigation } from '@react-navigation/native'
6
6
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'
16
7
import { makeSearchLink } from '#/lib/routes/links'
17
8
import { NavigationProp } from '#/lib/routes/types'
9
+ import { isInvalidHandle } from '#/lib/strings/handles'
18
10
import {
19
11
usePreferencesQuery ,
12
+ useRemoveMutedWordsMutation ,
20
13
useUpsertMutedWordsMutation ,
21
- useRemoveMutedWordMutation ,
22
14
} 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'
23
23
import { Loader } from '#/components/Loader'
24
- import { isInvalidHandle } from '#/lib/strings/handles '
24
+ import { Text } from '#/components/Typography '
25
25
26
26
export function useTagMenuControl ( ) {
27
27
return Dialog . useDialogControl ( )
@@ -52,10 +52,10 @@ export function TagMenu({
52
52
reset : resetUpsert ,
53
53
} = useUpsertMutedWordsMutation ( )
54
54
const {
55
- mutateAsync : removeMutedWord ,
55
+ mutateAsync : removeMutedWords ,
56
56
variables : optimisticRemove ,
57
57
reset : resetRemove ,
58
- } = useRemoveMutedWordMutation ( )
58
+ } = useRemoveMutedWordsMutation ( )
59
59
const displayTag = '#' + tag
60
60
61
61
const isMuted = Boolean (
@@ -65,9 +65,20 @@ export function TagMenu({
65
65
optimisticUpsert ?. find (
66
66
m => m . value === tag && m . targets . includes ( 'tag' ) ,
67
67
) ) &&
68
- ! ( optimisticRemove ?. value === tag ) ,
68
+ ! optimisticRemove ?. find ( m => m ?. value === tag ) ,
69
69
)
70
70
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
+
71
82
return (
72
83
< >
73
84
{ children }
@@ -212,13 +223,16 @@ export function TagMenu({
212
223
control . close ( ( ) => {
213
224
if ( isMuted ) {
214
225
resetUpsert ( )
215
- removeMutedWord ( {
216
- value : tag ,
217
- targets : [ 'tag' ] ,
218
- } )
226
+ removeMutedWords ( removeableMuteWords )
219
227
} else {
220
228
resetRemove ( )
221
- upsertMutedWord ( [ { value : tag , targets : [ 'tag' ] } ] )
229
+ upsertMutedWord ( [
230
+ {
231
+ value : tag ,
232
+ targets : [ 'tag' ] ,
233
+ actorTarget : 'all' ,
234
+ } ,
235
+ ] )
222
236
}
223
237
} )
224
238
} } >
0 commit comments