Hook up real data
This commit is contained in:
@@ -2,10 +2,12 @@ import React from 'react'
|
|||||||
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'
|
||||||
|
|
||||||
// TEMP
|
|
||||||
import {makeSearchLink} from '#/lib/routes/links'
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {usePreferencesQuery} from '#/state/queries/preferences'
|
import {usePreferencesQuery} from '#/state/queries/preferences'
|
||||||
|
import {useAgent} from '#/state/session'
|
||||||
|
|
||||||
|
const HOST = ``
|
||||||
|
const TOKEN = ``
|
||||||
|
|
||||||
export type TrendingTopic = {
|
export type TrendingTopic = {
|
||||||
topic: string
|
topic: string
|
||||||
@@ -14,11 +16,12 @@ export type TrendingTopic = {
|
|||||||
link: string
|
link: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_LIMIT = 12
|
export const DEFAULT_LIMIT = 14
|
||||||
|
|
||||||
export const trendingTopicsQueryKey = ['trending-topics']
|
export const trendingTopicsQueryKey = ['trending-topics']
|
||||||
|
|
||||||
export function useTrendingTopics() {
|
export function useTrendingTopics() {
|
||||||
|
const agent = useAgent()
|
||||||
const {data: preferences} = usePreferencesQuery()
|
const {data: preferences} = usePreferencesQuery()
|
||||||
const mutedWords = React.useMemo(() => {
|
const mutedWords = React.useMemo(() => {
|
||||||
return preferences?.moderationPrefs?.mutedWords || []
|
return preferences?.moderationPrefs?.mutedWords || []
|
||||||
@@ -29,62 +32,23 @@ export function useTrendingTopics() {
|
|||||||
staleTime: STALE.MINUTES.THIRTY,
|
staleTime: STALE.MINUTES.THIRTY,
|
||||||
queryKey: trendingTopicsQueryKey,
|
queryKey: trendingTopicsQueryKey,
|
||||||
async queryFn() {
|
async queryFn() {
|
||||||
/*
|
const params = new URLSearchParams()
|
||||||
try {
|
params.set('viewer', agent.session?.did || '')
|
||||||
const params = new URLSearchParams()
|
params.set('limit', String(DEFAULT_LIMIT))
|
||||||
params.set('viewer', agent.session?.did || '')
|
const res = await fetch(`${HOST}?${params.toString()}`, {
|
||||||
const res = await fetch(
|
headers: {
|
||||||
``,
|
Authorization: `Bearer ${TOKEN}`,
|
||||||
{
|
},
|
||||||
headers: {
|
})
|
||||||
Authorization:
|
|
||||||
'Bearer ',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error('Failed to fetch trending topics')
|
throw new Error('Failed to fetch trending topics')
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await res.json()
|
const {topics, recommended} = (await res.json()) as {
|
||||||
return data.topics
|
topics: TrendingTopic[]
|
||||||
} catch (e) {
|
recommended: TrendingTopic[]
|
||||||
console.error(e)
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
const topics: TrendingTopic[] = [
|
|
||||||
{
|
|
||||||
topic: '#atproto',
|
|
||||||
displayName: '#atproto',
|
|
||||||
description: '',
|
|
||||||
link: '/hashtag/atproto',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
topic: 'South Korea',
|
|
||||||
displayName: 'South Korea',
|
|
||||||
description: '',
|
|
||||||
link: makeSearchLink({query: 'South Korea'}),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
topic: 'Paul Frazee',
|
|
||||||
displayName: 'Paul Frazee',
|
|
||||||
description: '',
|
|
||||||
link: 'at://did:plc:ragtjsm2j2vknwkz3zp4oxrd/app.bsky.actor.profile/self',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
topic: 'Wired',
|
|
||||||
displayName: 'Wired',
|
|
||||||
description: '',
|
|
||||||
link: makeSearchLink({query: 'Wired'}),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
topic: 'Quiet Posters',
|
|
||||||
displayName: 'Quiet Posters',
|
|
||||||
description: '',
|
|
||||||
link: 'at://did:plc:vpkhqolt662uhesyj6nxm7ys/app.bsky.feed.generator/infreq',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
return {
|
return {
|
||||||
topics: topics.filter(t => {
|
topics: topics.filter(t => {
|
||||||
return !hasMutedWord({
|
return !hasMutedWord({
|
||||||
@@ -92,7 +56,12 @@ export function useTrendingTopics() {
|
|||||||
text: t.topic + ' ' + t.displayName + ' ' + t.description,
|
text: t.topic + ' ' + t.displayName + ' ' + t.description,
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
recommended: [],
|
recommended: recommended.filter(t => {
|
||||||
|
return !hasMutedWord({
|
||||||
|
mutedWords,
|
||||||
|
text: t.topic + ' ' + t.displayName + ' ' + t.description,
|
||||||
|
})
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
/*
|
/*
|
||||||
* Only English during beta period
|
* Only English during beta period
|
||||||
*/
|
*/
|
||||||
if (!langPrefs.contentLanguages.includes('en')) {
|
if (
|
||||||
|
!!langPrefs.contentLanguages.length &&
|
||||||
|
!langPrefs.contentLanguages.includes('en')
|
||||||
|
) {
|
||||||
return {enabled: false}
|
return {enabled: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +51,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
/*
|
/*
|
||||||
* Service is enabled, but also check statsig in case we're rolling back.
|
* Service is enabled, but also check statsig in case we're rolling back.
|
||||||
*/
|
*/
|
||||||
const gateEnabled = gate('trending_topics_beta')
|
const gateEnabled = __DEV__ || gate('trending_topics_beta')
|
||||||
const _enabled = enabled && gateEnabled
|
const _enabled = enabled && gateEnabled
|
||||||
|
|
||||||
// update cache
|
// update cache
|
||||||
|
|||||||
Reference in New Issue
Block a user