Hook up prod agent

This commit is contained in:
Eric Bailey
2024-12-17 13:15:06 -06:00
parent 7cb9694971
commit eda3c35155
@@ -1,4 +1,5 @@
import React from 'react' import React from 'react'
import {AppBskyUnspeccedDefs} from '@atproto/api'
import {hasMutedWord} from '@atproto/api/dist/moderation/mutewords' import {hasMutedWord} from '@atproto/api/dist/moderation/mutewords'
import {useQuery} from '@tanstack/react-query' import {useQuery} from '@tanstack/react-query'
@@ -6,15 +7,7 @@ import {STALE} from '#/state/queries'
import {usePreferencesQuery} from '#/state/queries/preferences' import {usePreferencesQuery} from '#/state/queries/preferences'
import {useAgent} from '#/state/session' import {useAgent} from '#/state/session'
const HOST = `` export type TrendingTopic = AppBskyUnspeccedDefs.TrendingTopic
const TOKEN = ``
export type TrendingTopic = {
topic: string
displayName: string
description: string
link: string
}
export const DEFAULT_LIMIT = 14 export const DEFAULT_LIMIT = 14
@@ -32,23 +25,11 @@ export function useTrendingTopics() {
staleTime: STALE.MINUTES.THIRTY, staleTime: STALE.MINUTES.THIRTY,
queryKey: trendingTopicsQueryKey, queryKey: trendingTopicsQueryKey,
async queryFn() { async queryFn() {
const params = new URLSearchParams() const {data} = await agent.api.app.bsky.unspecced.getTrendingTopics({
params.set('viewer', agent.session?.did || '') limit: DEFAULT_LIMIT,
params.set('limit', String(DEFAULT_LIMIT))
const res = await fetch(`${HOST}?${params.toString()}`, {
headers: {
Authorization: `Bearer ${TOKEN}`,
},
}) })
if (!res.ok) { const {topics, suggested} = data
throw new Error('Failed to fetch trending topics')
}
const {topics, recommended} = (await res.json()) as {
topics: TrendingTopic[]
recommended: TrendingTopic[]
}
return { return {
topics: topics.filter(t => { topics: topics.filter(t => {
return !hasMutedWord({ return !hasMutedWord({
@@ -56,7 +37,7 @@ export function useTrendingTopics() {
text: t.topic + ' ' + t.displayName + ' ' + t.description, text: t.topic + ' ' + t.displayName + ' ' + t.description,
}) })
}), }),
recommended: recommended.filter(t => { suggested: suggested.filter(t => {
return !hasMutedWord({ return !hasMutedWord({
mutedWords, mutedWords,
text: t.topic + ' ' + t.displayName + ' ' + t.description, text: t.topic + ' ' + t.displayName + ' ' + t.description,