Handle service config, enablement, load states, update lex contract

This commit is contained in:
Eric Bailey
2024-12-16 17:08:56 -06:00
parent 9d7ebe3ee7
commit 2097b67ff0
11 changed files with 289 additions and 172 deletions
+35
View File
@@ -0,0 +1,35 @@
import {useQuery} from '@tanstack/react-query'
import {useAgent} from '#/state/session'
type ServiceConfig = {
checkEmailConfirmed: boolean
trendingTopicsEnabled: boolean
trendingTopicsLangs: string[]
}
export function useServiceConfigQuery() {
const agent = useAgent()
return useQuery<ServiceConfig>({
queryKey: ['service-config'],
queryFn: async () => {
try {
const {data} = await agent.api.app.bsky.unspecced.getConfig()
return {
checkEmailConfirmed: Boolean(data.checkEmailConfirmed),
// TODO
trendingTopicsEnabled: true, // Boolean(data.trendingTopicsEnabled),
// TODO
trendingTopicsLangs: ['en'], // data.trendingTopicsLangs ?? [],
}
} catch (e) {
return {
checkEmailConfirmed: false,
trendingTopicsEnabled: false,
trendingTopicsLangs: [],
}
}
},
staleTime: 5 * 60 * 1000,
})
}
@@ -10,14 +10,38 @@ export type TrendingTopic = {
link: string
}
export const trendingTopicsQueryKey = ['trending-topics']
export const DEFAULT_LIMIT = 12
// TODO ideally handle down-state faster
export const trendingTopicsQueryKey = ['trending-topics']
export function useTrendingTopics() {
return useQuery({
queryKey: trendingTopicsQueryKey,
async queryFn() {
/*
try {
const params = new URLSearchParams()
params.set('viewer', agent.session?.did || '')
const res = await fetch(
``,
{
headers: {
Authorization:
'Bearer ',
},
},
)
if (!res.ok) {
throw new Error('Failed to fetch trending topics')
}
const data = await res.json()
return data.topics
} catch (e) {
console.error(e)
}
*/
const topics: TrendingTopic[] = [
{
topic: '#atproto',
@@ -50,7 +74,10 @@ export function useTrendingTopics() {
link: 'at://did:plc:vpkhqolt662uhesyj6nxm7ys/app.bsky.feed.generator/infreq',
},
]
return topics
return {
topics,
recommended: [],
}
},
})
}