pl-hooks: improvements

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk 2024-11-30 20:30:37 +01:00
parent ae77b678b4
commit 9f8b9a783c
2 changed files with 7 additions and 13 deletions

View file

@ -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<string> | undefined = directoryQuery.data?.pages.flat();
return {
...directoryQuery,
data,
};
};
export { useDirectory };

View file

@ -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';