diff --git a/app/soapbox/features/groups/components/discover/search/search.tsx b/app/soapbox/features/groups/components/discover/search/search.tsx index 4e3308353..647f10fb5 100644 --- a/app/soapbox/features/groups/components/discover/search/search.tsx +++ b/app/soapbox/features/groups/components/discover/search/search.tsx @@ -26,7 +26,7 @@ export default (props: Props) => { const debouncedValueToSave = debounce(searchValue as string, 1000); const groupSearchResult = useGroupSearch(debouncedValue); - const { groups, isFetching, isFetched, isError } = groupSearchResult; + const { groups, isLoading, isFetched, isError } = groupSearchResult; const hasSearchResults = isFetched && groups.length > 0; const hasNoSearchResults = isFetched && groups.length === 0; @@ -37,7 +37,7 @@ export default (props: Props) => { } }, [debouncedValueToSave]); - if (isFetching) { + if (isLoading) { return ( diff --git a/app/soapbox/queries/groups/search.ts b/app/soapbox/queries/groups/search.ts deleted file mode 100644 index 3da166cc2..000000000 --- a/app/soapbox/queries/groups/search.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { useInfiniteQuery } from '@tanstack/react-query'; - -import { getNextLink } from 'soapbox/api'; -import { useApi, useFeatures } from 'soapbox/hooks'; -import { normalizeGroup } from 'soapbox/normalizers'; -import { Group } from 'soapbox/types/entities'; -import { flattenPages, PaginatedResult } from 'soapbox/utils/queries'; - -const GroupSearchKeys = { - search: (query?: string) => query ? ['groups', 'search', query] : ['groups', 'search'] as const, -}; - -type PageParam = { - link: string -} - -const useGroupSearch = (search?: string) => { - const api = useApi(); - const features = useFeatures(); - - const getSearchResults = async (pageParam: PageParam): Promise> => { - const nextPageLink = pageParam?.link; - const uri = nextPageLink || '/api/v1/groups/search'; - const response = await api.get(uri, { - params: search ? { - q: search, - } : undefined, - }); - const { data } = response; - - const link = getNextLink(response); - const hasMore = !!link; - const result = data.map(normalizeGroup); - - return { - result, - hasMore, - link, - }; - }; - - const queryInfo = useInfiniteQuery( - GroupSearchKeys.search(search), - ({ pageParam }) => getSearchResults(pageParam), - { - keepPreviousData: true, - enabled: features.groups && !!search, - getNextPageParam: (config) => { - if (config.hasMore) { - return { link: config.link }; - } - - return undefined; - }, - }); - - const data = flattenPages(queryInfo.data); - - return { - ...queryInfo, - groups: data || [], - }; -}; - -export { - useGroupSearch, -};