diff --git a/packages/pl-hooks/lib/hooks/accounts/use-directory.ts b/packages/pl-hooks/lib/hooks/account-lists/use-directory.ts similarity index 64% rename from packages/pl-hooks/lib/hooks/accounts/use-directory.ts rename to packages/pl-hooks/lib/hooks/account-lists/use-directory.ts index e6b5e2321..e9e1dc926 100644 --- a/packages/pl-hooks/lib/hooks/accounts/use-directory.ts +++ b/packages/pl-hooks/lib/hooks/account-lists/use-directory.ts @@ -8,26 +8,20 @@ const useDirectory = (order: 'active' | 'new', local: boolean = false) => { const { client } = usePlHooksApiClient(); const queryClient = usePlHooksQueryClient(); - const directoryQuery = useInfiniteQuery({ + return useInfiniteQuery({ queryKey: ['accountsLists', 'directory', order, local], - queryFn: ({ pageParam }) => client.instance.profileDirectory({ + queryFn: ({ pageParam: offset }) => client.instance.profileDirectory({ order, local, - offset: pageParam ? data?.length : 0, + offset, }).then((accounts) => { importEntities({ accounts }); return accounts.map(({ id }) => id); }), - initialPageParam: [''], - getNextPageParam: (page) => page.length ? page : undefined, + initialPageParam: 0, + getNextPageParam: (_, allPages) => allPages.at(-1)?.length === 0 ? undefined : allPages.flat().length, + select: (data) => data?.pages.flat(), }, queryClient); - - const data: Array | undefined = directoryQuery.data?.pages.flat(); - - return { - ...directoryQuery, - data, - }; }; export { useDirectory }; diff --git a/packages/pl-hooks/lib/main.ts b/packages/pl-hooks/lib/main.ts index 8a9a0cb6c..b460f92bb 100644 --- a/packages/pl-hooks/lib/main.ts +++ b/packages/pl-hooks/lib/main.ts @@ -4,7 +4,7 @@ export * from './contexts/query-client'; export * from './hooks/accounts/use-account'; export * from './hooks/accounts/use-account-lookup'; export * from './hooks/accounts/use-account-relationship'; -export * from './hooks/accounts/use-directory'; +export * from './hooks/account-lists/use-directory'; export * from './hooks/instance/use-instance'; export * from './hooks/instance/use-translation-languages'; export * from './hooks/markers/use-markers';