diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-04-03 03:21:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-02 17:21:15 -0700 |
commit | 87da619aaa92e0ec762e68c13b24e58a25da10a8 (patch) | |
tree | 4da902d3ca43a226f6da8e5c090ab33c2df3297a /src/state/queries | |
parent | 8d1f97b5ffac5d86762f1d4e9384ff3097acbc52 (diff) | |
download | voidsky-87da619aaa92e0ec762e68c13b24e58a25da10a8.tar.zst |
[Explore] Base (#8053)
* migrate to #/screens * rm unneeded import * block drawer gesture on recent profiles * rm recommendations (#8056) * [Explore] Disable Trending videos (#8054) * remove giant header * disable * [Explore] Dynamic module ordering (#8066) * Dynamic module ordering * [Explore] New headers, metrics (#8067) * new sticky headers * improve spacing between modules * view metric on modules * update metrics names * [Explore] Suggested accounts module (#8072) * use modern profile card, update load more * add tab bar * tabbed suggested accounts * [Explore] Discover feeds module (#8073) * cap number of feeds to 3 * change feed pin button * Apply suggestions from code review Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * restore statsig to log events * filter out followed profiles, make suer enough are loaded (#8090) * [Explore] Trending topics (#8055) * redesigned trending topics * rm borders on web * get post count / age / ranking from api * spacing tweaks * fetch more topics then slice * use api data for avis/category * rm top border * Integrate new SDK, part out components * Clean up * Use status field * Bump SDK * Send up interests and langs --------- Co-authored-by: Eric Bailey <git@esb.lol> * Clean up module spacing and borders (cherry picked from commit 63d19b6c2d67e226e0e14709b1047a1f88b3ce1c) (cherry picked from commit 62d7d394ab1dc31b40b9c2cf59075adbf94737a1) * Switch back border ordering (cherry picked from commit 34e3789f8b410132c1390df3c2bb8257630ebdd9) * [Explore] Starter Packs (#8095) * Temp WIP (cherry picked from commit 43b5d7b1e64b3adb1ed162262d0310e0bf026c18) * New SP card * Load state * Revert change * Cleanup * Interests and caching * Count total * Format * Caching * [Explore] Feed previews module (#8075) * wip new hook * get fetching working, maybe * get feed previews rendering! * fix header height * working pin button * extract out FeedLink * add loader * only make preview:header sticky * Fix headers * Header tweaks * Fix moderation filter * Fix threading --------- Co-authored-by: Eric Bailey <git@esb.lol> * Space it out * Fix query key * Mock new endpoint, filter saved feeds * Make sure we're pinning, lower cache time * add news category * Remove log * Improve suggested accounts load state * Integrate new app view endpoint * fragment * Update src/screens/Search/modules/ExploreTrendingTopics.tsx Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * Update src/screens/Search/modules/ExploreTrendingTopics.tsx Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> * lint * maybe fix this --------- Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com> Co-authored-by: Eric Bailey <git@esb.lol> Co-authored-by: Hailey <me@haileyok.com>
Diffstat (limited to 'src/state/queries')
-rw-r--r-- | src/state/queries/actor-search.ts | 23 | ||||
-rw-r--r-- | src/state/queries/trending/useGetSuggestedFeedsQuery.ts | 48 | ||||
-rw-r--r-- | src/state/queries/trending/useGetTrendsQuery.ts | 59 | ||||
-rw-r--r-- | src/state/queries/useSuggestedStarterPacksQuery.ts | 38 |
4 files changed, 161 insertions, 7 deletions
diff --git a/src/state/queries/actor-search.ts b/src/state/queries/actor-search.ts index 6d6c46e04..0b5de2303 100644 --- a/src/state/queries/actor-search.ts +++ b/src/state/queries/actor-search.ts @@ -1,9 +1,12 @@ -import {AppBskyActorDefs, AppBskyActorSearchActors} from '@atproto/api' import { - InfiniteData, + type AppBskyActorDefs, + type AppBskyActorSearchActors, +} from '@atproto/api' +import { + type InfiniteData, keepPreviousData, - QueryClient, - QueryKey, + type QueryClient, + type QueryKey, useInfiniteQuery, useQuery, } from '@tanstack/react-query' @@ -15,7 +18,11 @@ const RQKEY_ROOT = 'actor-search' export const RQKEY = (query: string) => [RQKEY_ROOT, query] const RQKEY_ROOT_PAGINATED = `${RQKEY_ROOT}_paginated` -export const RQKEY_PAGINATED = (query: string) => [RQKEY_ROOT_PAGINATED, query] +export const RQKEY_PAGINATED = (query: string, limit?: number) => [ + RQKEY_ROOT_PAGINATED, + query, + limit, +] export function useActorSearch({ query, @@ -42,10 +49,12 @@ export function useActorSearchPaginated({ query, enabled, maintainData, + limit = 25, }: { query: string enabled?: boolean maintainData?: boolean + limit?: number }) { const agent = useAgent() return useInfiniteQuery< @@ -56,11 +65,11 @@ export function useActorSearchPaginated({ string | undefined >({ staleTime: STALE.MINUTES.FIVE, - queryKey: RQKEY_PAGINATED(query), + queryKey: RQKEY_PAGINATED(query, limit), queryFn: async ({pageParam}) => { const res = await agent.searchActors({ q: query, - limit: 25, + limit, cursor: pageParam, }) return res.data diff --git a/src/state/queries/trending/useGetSuggestedFeedsQuery.ts b/src/state/queries/trending/useGetSuggestedFeedsQuery.ts new file mode 100644 index 000000000..16522f5c9 --- /dev/null +++ b/src/state/queries/trending/useGetSuggestedFeedsQuery.ts @@ -0,0 +1,48 @@ +import {useQuery} from '@tanstack/react-query' + +import { + aggregateUserInterests, + createBskyTopicsHeader, +} from '#/lib/api/feed/utils' +import {getContentLanguages} from '#/state/preferences/languages' +import {STALE} from '#/state/queries' +import {usePreferencesQuery} from '#/state/queries/preferences' +import {useAgent} from '#/state/session' + +export const DEFAULT_LIMIT = 5 + +export const createGetTrendsQueryKey = () => ['suggested-feeds'] + +export function useGetSuggestedFeedsQuery() { + const agent = useAgent() + const {data: preferences} = usePreferencesQuery() + const savedFeeds = preferences?.savedFeeds + + return useQuery({ + enabled: !!savedFeeds, + refetchOnWindowFocus: true, + staleTime: STALE.MINUTES.ONE, + queryKey: createGetTrendsQueryKey(), + queryFn: async () => { + const contentLangs = getContentLanguages().join(',') + const {data} = await agent.app.bsky.unspecced.getSuggestedFeeds( + { + limit: DEFAULT_LIMIT, + }, + { + headers: { + ...createBskyTopicsHeader(aggregateUserInterests(preferences)), + 'Accept-Language': contentLangs, + }, + }, + ) + + return { + feeds: data.feeds.filter(feed => { + const isSaved = !!savedFeeds?.find(s => s.value === feed.uri) + return !isSaved + }), + } + }, + }) +} diff --git a/src/state/queries/trending/useGetTrendsQuery.ts b/src/state/queries/trending/useGetTrendsQuery.ts new file mode 100644 index 000000000..d96bf0603 --- /dev/null +++ b/src/state/queries/trending/useGetTrendsQuery.ts @@ -0,0 +1,59 @@ +import React from 'react' +import {type AppBskyUnspeccedGetTrends} from '@atproto/api' +import {hasMutedWord} from '@atproto/api/dist/moderation/mutewords' +import {useQuery} from '@tanstack/react-query' + +import { + aggregateUserInterests, + createBskyTopicsHeader, +} from '#/lib/api/feed/utils' +import {getContentLanguages} from '#/state/preferences/languages' +import {STALE} from '#/state/queries' +import {usePreferencesQuery} from '#/state/queries/preferences' +import {useAgent} from '#/state/session' + +export const DEFAULT_LIMIT = 5 + +export const createGetTrendsQueryKey = () => ['trends'] + +export function useGetTrendsQuery() { + const agent = useAgent() + const {data: preferences} = usePreferencesQuery() + const mutedWords = React.useMemo(() => { + return preferences?.moderationPrefs?.mutedWords || [] + }, [preferences?.moderationPrefs]) + + return useQuery({ + refetchOnWindowFocus: true, + staleTime: STALE.MINUTES.THREE, + queryKey: createGetTrendsQueryKey(), + queryFn: async () => { + const contentLangs = getContentLanguages().join(',') + const {data} = await agent.app.bsky.unspecced.getTrends( + { + limit: DEFAULT_LIMIT, + }, + { + headers: { + ...createBskyTopicsHeader(aggregateUserInterests(preferences)), + 'Accept-Language': contentLangs, + }, + }, + ) + return data + }, + select: React.useCallback( + (data: AppBskyUnspeccedGetTrends.OutputSchema) => { + return { + trends: (data.trends ?? []).filter(t => { + return !hasMutedWord({ + mutedWords, + text: t.topic + ' ' + t.displayName + ' ' + t.category, + }) + }), + } + }, + [mutedWords], + ), + }) +} diff --git a/src/state/queries/useSuggestedStarterPacksQuery.ts b/src/state/queries/useSuggestedStarterPacksQuery.ts new file mode 100644 index 000000000..18fe6439e --- /dev/null +++ b/src/state/queries/useSuggestedStarterPacksQuery.ts @@ -0,0 +1,38 @@ +import {useQuery} from '@tanstack/react-query' + +import { + aggregateUserInterests, + createBskyTopicsHeader, +} from '#/lib/api/feed/utils' +import {getContentLanguages} from '#/state/preferences/languages' +import {STALE} from '#/state/queries' +import {usePreferencesQuery} from '#/state/queries/preferences' +import {useAgent} from '#/state/session' + +export const createSuggestedStarterPacksQueryKey = () => [ + 'suggested-starter-packs', +] + +export function useSuggestedStarterPacksQuery() { + const agent = useAgent() + const {data: preferences} = usePreferencesQuery() + const contentLangs = getContentLanguages().join(',') + + return useQuery({ + refetchOnWindowFocus: true, + staleTime: STALE.MINUTES.ONE, + queryKey: createSuggestedStarterPacksQueryKey(), + async queryFn() { + const {data} = await agent.app.bsky.unspecced.getSuggestedStarterPacks( + undefined, + { + headers: { + ...createBskyTopicsHeader(aggregateUserInterests(preferences)), + 'Accept-Language': contentLangs, + }, + }, + ) + return data + }, + }) +} |