Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate new SDK methods #3133

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/components/TagMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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),
)

Expand Down Expand Up @@ -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']})
}
})
}}>
Expand Down
15 changes: 7 additions & 8 deletions src/components/TagMenu/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -45,17 +45,16 @@ export function TagMenu({
const {_} = useLingui()
const navigation = useNavigation<NavigationProp>()
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')
Expand Down Expand Up @@ -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',
Expand All @@ -128,7 +127,7 @@ export function TagMenu({
preferences,
tag,
truncatedTag,
upsertMutedWord,
addMutedWord,
removeMutedWord,
])

Expand Down
6 changes: 3 additions & 3 deletions src/components/dialogs/MutedWords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {AppBskyActorDefs, sanitizeMutedWordValue} from '@atproto/api'

import {
usePreferencesQuery,
useUpsertMutedWordsMutation,
useAddMutedWordMutation,
useRemoveMutedWordMutation,
} from '#/state/queries/preferences'
import {isNative} from '#/platform/detection'
Expand Down Expand Up @@ -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('')
Expand All @@ -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})
Expand Down
6 changes: 3 additions & 3 deletions src/state/queries/preferences/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading