remove non-paginated API, rename other one
This commit is contained in:
@@ -8,7 +8,7 @@ import {popularInterests, useInterestsDisplayNames} from '#/lib/interests'
|
|||||||
import {logEvent} from '#/lib/statsig/statsig'
|
import {logEvent} from '#/lib/statsig/statsig'
|
||||||
import {isWeb} from '#/platform/detection'
|
import {isWeb} from '#/platform/detection'
|
||||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||||
import {useActorSearchPaginated} from '#/state/queries/actor-search'
|
import {useActorSearch} from '#/state/queries/actor-search'
|
||||||
import {usePreferencesQuery} from '#/state/queries/preferences'
|
import {usePreferencesQuery} from '#/state/queries/preferences'
|
||||||
import {useGetSuggestedUsersQuery} from '#/state/queries/trending/useGetSuggestedUsersQuery'
|
import {useGetSuggestedUsersQuery} from '#/state/queries/trending/useGetSuggestedUsersQuery'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
@@ -128,7 +128,7 @@ function DialogInner({guide}: {guide: Follow10ProgressGuide}) {
|
|||||||
isFetching: isFetchingSearchResults,
|
isFetching: isFetchingSearchResults,
|
||||||
error: searchResultsError,
|
error: searchResultsError,
|
||||||
isError: isSearchResultsError,
|
isError: isSearchResultsError,
|
||||||
} = useActorSearchPaginated({
|
} = useActorSearch({
|
||||||
enabled: !!searchText,
|
enabled: !!searchText,
|
||||||
query: searchText,
|
query: searchText,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {logger} from '#/logger'
|
|||||||
import {type MetricEvents} from '#/logger/metrics'
|
import {type MetricEvents} from '#/logger/metrics'
|
||||||
import {useLanguagePrefs} from '#/state/preferences/languages'
|
import {useLanguagePrefs} from '#/state/preferences/languages'
|
||||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||||
import {RQKEY_ROOT_PAGINATED as useActorSearchPaginatedQueryKeyRoot} from '#/state/queries/actor-search'
|
import {RQKEY_ROOT as useActorSearchQueryKeyRoot} from '#/state/queries/actor-search'
|
||||||
import {
|
import {
|
||||||
type FeedPreviewItem,
|
type FeedPreviewItem,
|
||||||
useFeedPreviews,
|
useFeedPreviews,
|
||||||
@@ -308,7 +308,7 @@ export function Explore({
|
|||||||
queryKey: [getSuggestedUsersQueryKeyRoot],
|
queryKey: [getSuggestedUsersQueryKeyRoot],
|
||||||
}),
|
}),
|
||||||
qc.resetQueries({
|
qc.resetQueries({
|
||||||
queryKey: [useActorSearchPaginatedQueryKeyRoot],
|
queryKey: [useActorSearchQueryKeyRoot],
|
||||||
}),
|
}),
|
||||||
qc.resetQueries({
|
qc.resetQueries({
|
||||||
queryKey: createGetSuggestedFeedsQueryKey(),
|
queryKey: createGetSuggestedFeedsQueryKey(),
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {msg, Trans} from '@lingui/macro'
|
|||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {augmentSearchQuery} from '#/lib/strings/helpers'
|
import {augmentSearchQuery} from '#/lib/strings/helpers'
|
||||||
import {useActorSearchPaginated} from '#/state/queries/actor-search'
|
import {useActorSearch} from '#/state/queries/actor-search'
|
||||||
import {usePopularFeedsSearch} from '#/state/queries/feed'
|
import {usePopularFeedsSearch} from '#/state/queries/feed'
|
||||||
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
import {useSearchPostsQuery} from '#/state/queries/search-posts'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
@@ -342,7 +342,7 @@ let SearchScreenUserResults = ({
|
|||||||
fetchNextPage,
|
fetchNextPage,
|
||||||
isFetchingNextPage,
|
isFetchingNextPage,
|
||||||
hasNextPage,
|
hasNextPage,
|
||||||
} = useActorSearchPaginated({
|
} = useActorSearch({
|
||||||
query,
|
query,
|
||||||
enabled: active,
|
enabled: active,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {useMemo} from 'react'
|
import {useMemo} from 'react'
|
||||||
|
|
||||||
import {useInterestsDisplayNames} from '#/lib/interests'
|
import {useInterestsDisplayNames} from '#/lib/interests'
|
||||||
import {useActorSearchPaginated} from '#/state/queries/actor-search'
|
import {useActorSearch} from '#/state/queries/actor-search'
|
||||||
import {useGetSuggestedUsersQuery} from '#/state/queries/trending/useGetSuggestedUsersQuery'
|
import {useGetSuggestedUsersQuery} from '#/state/queries/trending/useGetSuggestedUsersQuery'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +31,7 @@ export function useSuggestedUsers({
|
|||||||
category,
|
category,
|
||||||
overrideInterests,
|
overrideInterests,
|
||||||
})
|
})
|
||||||
const searched = useActorSearchPaginated({
|
const searched = useActorSearch({
|
||||||
enabled: !!search,
|
enabled: !!search,
|
||||||
// use user's app language translation for this value
|
// use user's app language translation for this value
|
||||||
query: category ? interestsDisplayNames[category] : '',
|
query: category ? interestsDisplayNames[category] : '',
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {Trans} from '@lingui/macro'
|
|||||||
import {isNative} from '#/platform/detection'
|
import {isNative} from '#/platform/detection'
|
||||||
import {useA11y} from '#/state/a11y'
|
import {useA11y} from '#/state/a11y'
|
||||||
import {useActorAutocompleteQuery} from '#/state/queries/actor-autocomplete'
|
import {useActorAutocompleteQuery} from '#/state/queries/actor-autocomplete'
|
||||||
import {useActorSearchPaginated} from '#/state/queries/actor-search'
|
import {useActorSearch} from '#/state/queries/actor-search'
|
||||||
import {List} from '#/view/com/util/List'
|
import {List} from '#/view/com/util/List'
|
||||||
import {useWizardState} from '#/screens/StarterPack/Wizard/State'
|
import {useWizardState} from '#/screens/StarterPack/Wizard/State'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
@@ -36,7 +36,7 @@ export function StepProfiles({
|
|||||||
data: topPages,
|
data: topPages,
|
||||||
fetchNextPage,
|
fetchNextPage,
|
||||||
isLoading: isLoadingTopPages,
|
isLoading: isLoadingTopPages,
|
||||||
} = useActorSearchPaginated({
|
} = useActorSearch({
|
||||||
query: encodeURIComponent('*'),
|
query: encodeURIComponent('*'),
|
||||||
})
|
})
|
||||||
const topFollowers = topPages?.pages
|
const topFollowers = topPages?.pages
|
||||||
|
|||||||
@@ -1,25 +1,18 @@
|
|||||||
import {
|
import {type AppBskyActorSearchActors} from '@atproto/api'
|
||||||
type AppBskyActorDefs,
|
|
||||||
type AppBskyActorSearchActors,
|
|
||||||
} from '@atproto/api'
|
|
||||||
import {
|
import {
|
||||||
type InfiniteData,
|
type InfiniteData,
|
||||||
keepPreviousData,
|
keepPreviousData,
|
||||||
type QueryClient,
|
type QueryClient,
|
||||||
type QueryKey,
|
type QueryKey,
|
||||||
useInfiniteQuery,
|
useInfiniteQuery,
|
||||||
useQuery,
|
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {STALE} from '#/state/queries'
|
import {STALE} from '#/state/queries'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
|
|
||||||
const RQKEY_ROOT = 'actor-search'
|
export const RQKEY_ROOT = 'actor-search'
|
||||||
export const RQKEY = (query: string) => [RQKEY_ROOT, query]
|
export const RQKEY = (query: string, limit?: number) => [
|
||||||
|
RQKEY_ROOT,
|
||||||
export const RQKEY_ROOT_PAGINATED = `${RQKEY_ROOT}_paginated`
|
|
||||||
export const RQKEY_PAGINATED = (query: string, limit?: number) => [
|
|
||||||
RQKEY_ROOT_PAGINATED,
|
|
||||||
query,
|
query,
|
||||||
limit,
|
limit,
|
||||||
]
|
]
|
||||||
@@ -27,27 +20,6 @@ export const RQKEY_PAGINATED = (query: string, limit?: number) => [
|
|||||||
export function useActorSearch({
|
export function useActorSearch({
|
||||||
query,
|
query,
|
||||||
enabled,
|
enabled,
|
||||||
}: {
|
|
||||||
query: string
|
|
||||||
enabled?: boolean
|
|
||||||
}) {
|
|
||||||
const agent = useAgent()
|
|
||||||
return useQuery<AppBskyActorDefs.ProfileView[]>({
|
|
||||||
staleTime: STALE.MINUTES.ONE,
|
|
||||||
queryKey: RQKEY(query || ''),
|
|
||||||
async queryFn() {
|
|
||||||
const res = await agent.searchActors({
|
|
||||||
q: query,
|
|
||||||
})
|
|
||||||
return res.data.actors
|
|
||||||
},
|
|
||||||
enabled: enabled && !!query,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useActorSearchPaginated({
|
|
||||||
query,
|
|
||||||
enabled,
|
|
||||||
maintainData,
|
maintainData,
|
||||||
limit = 25,
|
limit = 25,
|
||||||
}: {
|
}: {
|
||||||
@@ -65,7 +37,7 @@ export function useActorSearchPaginated({
|
|||||||
string | undefined
|
string | undefined
|
||||||
>({
|
>({
|
||||||
staleTime: STALE.MINUTES.FIVE,
|
staleTime: STALE.MINUTES.FIVE,
|
||||||
queryKey: RQKEY_PAGINATED(query, limit),
|
queryKey: RQKEY(query, limit),
|
||||||
queryFn: async ({pageParam}) => {
|
queryFn: async ({pageParam}) => {
|
||||||
const res = await agent.searchActors({
|
const res = await agent.searchActors({
|
||||||
q: query,
|
q: query,
|
||||||
@@ -85,28 +57,12 @@ export function* findAllProfilesInQueryData(
|
|||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
did: string,
|
did: string,
|
||||||
) {
|
) {
|
||||||
const queryDatas = queryClient.getQueriesData<AppBskyActorDefs.ProfileView[]>(
|
const queryDatas = queryClient.getQueriesData<
|
||||||
{
|
|
||||||
queryKey: [RQKEY_ROOT],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
for (const [_queryKey, queryData] of queryDatas) {
|
|
||||||
if (!queryData) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for (const actor of queryData) {
|
|
||||||
if (actor.did === did) {
|
|
||||||
yield actor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryDatasPaginated = queryClient.getQueriesData<
|
|
||||||
InfiniteData<AppBskyActorSearchActors.OutputSchema>
|
InfiniteData<AppBskyActorSearchActors.OutputSchema>
|
||||||
>({
|
>({
|
||||||
queryKey: [RQKEY_ROOT_PAGINATED],
|
queryKey: [RQKEY_ROOT],
|
||||||
})
|
})
|
||||||
for (const [_queryKey, queryData] of queryDatasPaginated) {
|
for (const [_queryKey, queryData] of queryDatas) {
|
||||||
if (!queryData) {
|
if (!queryData) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user