diff --git a/src/components/TagMenu/index.tsx b/src/components/TagMenu/index.tsx index c9ced9a54c..beb34a0dd4 100644 --- a/src/components/TagMenu/index.tsx +++ b/src/components/TagMenu/index.tsx @@ -17,7 +17,7 @@ import {makeSearchLink} from '#/lib/routes/links' import {NavigationProp} from '#/lib/routes/types' import { usePreferencesQuery, - useUpsertMutedWordsMutation, + useAddMutedWordMutation, useRemoveMutedWordMutation, } from '#/state/queries/preferences' import {Loader} from '#/components/Loader' @@ -47,10 +47,10 @@ export function TagMenu({ const {isLoading: isPreferencesLoading, data: preferences} = usePreferencesQuery() const { - mutateAsync: upsertMutedWord, - variables: optimisticUpsert, - reset: resetUpsert, - } = useUpsertMutedWordsMutation() + mutateAsync: addMutedWord, + variables: optimisticAdd, + reset: resetAdd, + } = useAddMutedWordMutation() const { mutateAsync: removeMutedWord, variables: optimisticRemove, @@ -62,9 +62,8 @@ export function TagMenu({ (preferences?.mutedWords?.find( m => m.value === tag && m.targets.includes('tag'), ) ?? - optimisticUpsert?.find( - m => m.value === tag && m.targets.includes('tag'), - )) && + (optimisticAdd?.value === tag && + optimisticAdd.targets.includes('tag'))) && !(optimisticRemove?.value === tag), ) @@ -211,14 +210,14 @@ export function TagMenu({ onPress={() => { control.close(() => { if (isMuted) { - resetUpsert() + resetAdd() removeMutedWord({ value: tag, targets: ['tag'], }) } else { resetRemove() - upsertMutedWord([{value: tag, targets: ['tag']}]) + addMutedWord({value: tag, targets: ['tag']}) } }) }}> diff --git a/src/components/TagMenu/index.web.tsx b/src/components/TagMenu/index.web.tsx index a0dc2bce63..59f0cf34c5 100644 --- a/src/components/TagMenu/index.web.tsx +++ b/src/components/TagMenu/index.web.tsx @@ -9,7 +9,7 @@ import {NativeDropdown} from '#/view/com/util/forms/NativeDropdown' import {NavigationProp} from '#/lib/routes/types' import { usePreferencesQuery, - useUpsertMutedWordsMutation, + useAddMutedWordMutation, useRemoveMutedWordMutation, } from '#/state/queries/preferences' import {enforceLen} from '#/lib/strings/helpers' @@ -45,17 +45,16 @@ export function TagMenu({ const {_} = useLingui() const navigation = useNavigation() const {data: preferences} = usePreferencesQuery() - const {mutateAsync: upsertMutedWord, variables: optimisticUpsert} = - useUpsertMutedWordsMutation() + const {mutateAsync: addMutedWord, variables: optimisticAdd} = + useAddMutedWordMutation() const {mutateAsync: removeMutedWord, variables: optimisticRemove} = useRemoveMutedWordMutation() const isMuted = Boolean( (preferences?.mutedWords?.find( m => m.value === tag && m.targets.includes('tag'), ) ?? - optimisticUpsert?.find( - m => m.value === tag && m.targets.includes('tag'), - )) && + (optimisticAdd?.value === tag && + optimisticAdd.targets.includes('tag'))) && !(optimisticRemove?.value === tag), ) const truncatedTag = '#' + enforceLen(tag, 15, true, 'middle') @@ -107,7 +106,7 @@ export function TagMenu({ if (isMuted) { removeMutedWord({value: tag, targets: ['tag']}) } else { - upsertMutedWord([{value: tag, targets: ['tag']}]) + addMutedWord({value: tag, targets: ['tag']}) } }, testID: 'tagMenuMute', @@ -128,7 +127,7 @@ export function TagMenu({ preferences, tag, truncatedTag, - upsertMutedWord, + addMutedWord, removeMutedWord, ]) diff --git a/src/components/dialogs/MutedWords.tsx b/src/components/dialogs/MutedWords.tsx index 658ba2aae0..5f9236aa1e 100644 --- a/src/components/dialogs/MutedWords.tsx +++ b/src/components/dialogs/MutedWords.tsx @@ -6,7 +6,7 @@ import {AppBskyActorDefs, sanitizeMutedWordValue} from '@atproto/api' import { usePreferencesQuery, - useUpsertMutedWordsMutation, + useAddMutedWordMutation, useRemoveMutedWordMutation, } from '#/state/queries/preferences' import {isNative} from '#/platform/detection' @@ -52,7 +52,7 @@ function MutedWordsInner({}: {control: Dialog.DialogOuterProps['control']}) { data: preferences, error: preferencesError, } = usePreferencesQuery() - const {isPending, mutateAsync: addMutedWord} = useUpsertMutedWordsMutation() + const {isPending, mutateAsync: addMutedWord} = useAddMutedWordMutation() const [field, setField] = React.useState('') const [options, setOptions] = React.useState(['content']) const [error, setError] = React.useState('') @@ -71,7 +71,7 @@ function MutedWordsInner({}: {control: Dialog.DialogOuterProps['control']}) { try { // send raw value and rely on SDK as sanitization source of truth - await addMutedWord([{value: field, targets}]) + await addMutedWord({value: field, targets}) setField('') } catch (e: any) { logger.error(`Failed to save muted word`, {message: e.message}) diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index 37ef10ae0c..2e18da8d2f 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -284,12 +284,12 @@ export function useUnpinFeedMutation() { }) } -export function useUpsertMutedWordsMutation() { +export function useAddMutedWordMutation() { const queryClient = useQueryClient() return useMutation({ - mutationFn: async (mutedWords: AppBskyActorDefs.MutedWord[]) => { - await getAgent().upsertMutedWords(mutedWords) + mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => { + await getAgent().addMutedWord(mutedWord) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey,