Some validation, fixes

This commit is contained in:
Eric Bailey
2024-02-13 18:00:41 -06:00
parent da735f4894
commit 46076c4afb
2 changed files with 24 additions and 5 deletions
@@ -1,8 +1,8 @@
import React from 'react'
import {View} from 'react-native'
import {useLingui} from '@lingui/react'
import {msg} from '@lingui/macro'
import {LABEL_GROUPS, AppBskyModerationDefs} from '@atproto/api'
// import {msg} from '@lingui/macro'
import {LABEL_GROUPS} from '@atproto/api'
// TODO
import {ModPrefItem} from '@atproto/api/dist/client/types/app/bsky/actor/defs'
@@ -24,7 +24,7 @@ export function PreferenceRow({
const {_} = useLingui()
const labelGroupStrings = useLabelGroupStrings()
const groupInfoStrings = labelGroupStrings[labelGroup]
const {mutateAsync, variables} = useModServiceLabelGroupEnableMutation()
const {mutateAsync, variables, reset} = useModServiceLabelGroupEnableMutation()
const enabled =
variables?.enabled ??
!modservicePreferences?.disabledLabelGroups?.includes(labelGroup)
@@ -37,10 +37,12 @@ export function PreferenceRow({
group: labelGroup,
enabled: !enabled,
})
reset() // Important: clears query `variables`
} catch (e: any) {
// TODO
console.error(e)
}
}, [mutateAsync, enabled])
}, [mutateAsync, enabled, modservicePreferences, labelGroup, reset])
return (
<View
+18 -1
View File
@@ -1,3 +1,4 @@
import {z} from 'zod'
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
import {getAgent} from '#/state/session'
@@ -20,6 +21,12 @@ export function useModServiceSubscriptionMutation() {
return useMutation({
async mutationFn({did, subscribe}: {did: string; subscribe: boolean}) {
// TODO
z.object({
did: z.string(),
subscribe: z.boolean(),
}).parse({did, subscribe})
if (subscribe) {
await getAgent().addModService(did)
} else {
@@ -39,6 +46,11 @@ export function useModServiceEnableMutation() {
return useMutation({
async mutationFn({did, enabled}: {did: string; enabled: boolean}) {
// TODO
z.object({
did: z.string(),
enabled: z.boolean(),
}).parse({did, enabled})
await getAgent().setModServiceEnabled(did, enabled)
},
onSuccess() {
@@ -54,7 +66,12 @@ export function useModServiceLabelGroupEnableMutation() {
return useMutation({
async mutationFn({did, group, enabled}: {did: string; group: string, enabled: boolean}) {
console.log('useModServiceLabelGroupEnableMutation', did, group, enabled)
// TODO
z.object({
did: z.string(),
group: z.string(),
enabled: z.boolean(),
}).parse({did, group, enabled})
await getAgent().setModServiceLabelGroupEnabled(did, group, enabled)
},
onSuccess() {