Hook up data
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import {z} from 'zod'
|
||||
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
||||
import {AppBskyModerationDefs} from '@atproto/api'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {preferencesQueryKey} from '#/state/queries/preferences'
|
||||
|
||||
export const modServiceInfoQueryKey = (did: string) => ['mod-service-info', did]
|
||||
export const modServicesInfoQueryKey = (dids: string[]) => [
|
||||
'mod-service-info',
|
||||
dids,
|
||||
]
|
||||
|
||||
export function useModServiceInfoQuery({did}: {did: string}) {
|
||||
return useQuery({
|
||||
@@ -16,6 +21,31 @@ export function useModServiceInfoQuery({did}: {did: string}) {
|
||||
})
|
||||
}
|
||||
|
||||
export function useModServicesInfoQuery({dids}: {dids: string[]}) {
|
||||
return useQuery({
|
||||
queryKey: modServicesInfoQueryKey(dids),
|
||||
queryFn: async () => {
|
||||
const views: AppBskyModerationDefs.ModServiceViewDetailed[] = []
|
||||
|
||||
await Promise.all(
|
||||
dids.map(did => {
|
||||
return getAgent()
|
||||
.app.bsky.moderation.getService({did})
|
||||
.then(res => {
|
||||
views.push(res.data)
|
||||
})
|
||||
.catch(e => {
|
||||
console.error(e)
|
||||
return null
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
return views
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useModServiceSubscriptionMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
@@ -65,7 +95,15 @@ export function useModServiceLabelGroupEnableMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
async mutationFn({did, group, enabled}: {did: string; group: string, enabled: boolean}) {
|
||||
async mutationFn({
|
||||
did,
|
||||
group,
|
||||
enabled,
|
||||
}: {
|
||||
did: string
|
||||
group: string
|
||||
enabled: boolean
|
||||
}) {
|
||||
// TODO
|
||||
z.object({
|
||||
did: z.string(),
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import {useMemo} from 'react'
|
||||
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
||||
import {LabelPreference, BskyFeedViewPreference} from '@atproto/api'
|
||||
import {
|
||||
LabelPreference,
|
||||
BskyFeedViewPreference,
|
||||
LabelGroupDefinition,
|
||||
} from '@atproto/api'
|
||||
|
||||
import {track} from '#/lib/analytics/analytics'
|
||||
import {getAge} from '#/lib/strings/time'
|
||||
@@ -111,6 +115,26 @@ export function usePreferencesSetContentLabelMutation() {
|
||||
})
|
||||
}
|
||||
|
||||
export function useSetContentLabelMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
labelGroup,
|
||||
visibility,
|
||||
}: {
|
||||
labelGroup: LabelGroupDefinition['id']
|
||||
visibility: LabelPreference
|
||||
}) => {
|
||||
await getAgent().setContentLabelPref(labelGroup, visibility)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function usePreferencesSetAdultContentMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user