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 React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {msg} from '@lingui/macro' // import {msg} from '@lingui/macro'
import {LABEL_GROUPS, AppBskyModerationDefs} from '@atproto/api' import {LABEL_GROUPS} from '@atproto/api'
// TODO // TODO
import {ModPrefItem} from '@atproto/api/dist/client/types/app/bsky/actor/defs' import {ModPrefItem} from '@atproto/api/dist/client/types/app/bsky/actor/defs'
@@ -24,7 +24,7 @@ export function PreferenceRow({
const {_} = useLingui() const {_} = useLingui()
const labelGroupStrings = useLabelGroupStrings() const labelGroupStrings = useLabelGroupStrings()
const groupInfoStrings = labelGroupStrings[labelGroup] const groupInfoStrings = labelGroupStrings[labelGroup]
const {mutateAsync, variables} = useModServiceLabelGroupEnableMutation() const {mutateAsync, variables, reset} = useModServiceLabelGroupEnableMutation()
const enabled = const enabled =
variables?.enabled ?? variables?.enabled ??
!modservicePreferences?.disabledLabelGroups?.includes(labelGroup) !modservicePreferences?.disabledLabelGroups?.includes(labelGroup)
@@ -37,10 +37,12 @@ export function PreferenceRow({
group: labelGroup, group: labelGroup,
enabled: !enabled, enabled: !enabled,
}) })
reset() // Important: clears query `variables`
} catch (e: any) { } catch (e: any) {
// TODO
console.error(e) console.error(e)
} }
}, [mutateAsync, enabled]) }, [mutateAsync, enabled, modservicePreferences, labelGroup, reset])
return ( return (
<View <View
+18 -1
View File
@@ -1,3 +1,4 @@
import {z} from 'zod'
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query' import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
import {getAgent} from '#/state/session' import {getAgent} from '#/state/session'
@@ -20,6 +21,12 @@ export function useModServiceSubscriptionMutation() {
return useMutation({ return useMutation({
async mutationFn({did, subscribe}: {did: string; subscribe: boolean}) { async mutationFn({did, subscribe}: {did: string; subscribe: boolean}) {
// TODO
z.object({
did: z.string(),
subscribe: z.boolean(),
}).parse({did, subscribe})
if (subscribe) { if (subscribe) {
await getAgent().addModService(did) await getAgent().addModService(did)
} else { } else {
@@ -39,6 +46,11 @@ export function useModServiceEnableMutation() {
return useMutation({ return useMutation({
async mutationFn({did, enabled}: {did: string; enabled: boolean}) { 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) await getAgent().setModServiceEnabled(did, enabled)
}, },
onSuccess() { onSuccess() {
@@ -54,7 +66,12 @@ export function useModServiceLabelGroupEnableMutation() {
return useMutation({ return useMutation({
async mutationFn({did, group, enabled}: {did: string; group: string, enabled: boolean}) { 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) await getAgent().setModServiceLabelGroupEnabled(did, group, enabled)
}, },
onSuccess() { onSuccess() {