pl-hooks: improvements
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
parent
ae77b678b4
commit
9f8b9a783c
2 changed files with 7 additions and 13 deletions
|
@ -8,26 +8,20 @@ const useDirectory = (order: 'active' | 'new', local: boolean = false) => {
|
||||||
const { client } = usePlHooksApiClient();
|
const { client } = usePlHooksApiClient();
|
||||||
const queryClient = usePlHooksQueryClient();
|
const queryClient = usePlHooksQueryClient();
|
||||||
|
|
||||||
const directoryQuery = useInfiniteQuery({
|
return useInfiniteQuery({
|
||||||
queryKey: ['accountsLists', 'directory', order, local],
|
queryKey: ['accountsLists', 'directory', order, local],
|
||||||
queryFn: ({ pageParam }) => client.instance.profileDirectory({
|
queryFn: ({ pageParam: offset }) => client.instance.profileDirectory({
|
||||||
order,
|
order,
|
||||||
local,
|
local,
|
||||||
offset: pageParam ? data?.length : 0,
|
offset,
|
||||||
}).then((accounts) => {
|
}).then((accounts) => {
|
||||||
importEntities({ accounts });
|
importEntities({ accounts });
|
||||||
return accounts.map(({ id }) => id);
|
return accounts.map(({ id }) => id);
|
||||||
}),
|
}),
|
||||||
initialPageParam: [''],
|
initialPageParam: 0,
|
||||||
getNextPageParam: (page) => page.length ? page : undefined,
|
getNextPageParam: (_, allPages) => allPages.at(-1)?.length === 0 ? undefined : allPages.flat().length,
|
||||||
|
select: (data) => data?.pages.flat(),
|
||||||
}, queryClient);
|
}, queryClient);
|
||||||
|
|
||||||
const data: Array<string> | undefined = directoryQuery.data?.pages.flat();
|
|
||||||
|
|
||||||
return {
|
|
||||||
...directoryQuery,
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { useDirectory };
|
export { useDirectory };
|
|
@ -4,7 +4,7 @@ export * from './contexts/query-client';
|
||||||
export * from './hooks/accounts/use-account';
|
export * from './hooks/accounts/use-account';
|
||||||
export * from './hooks/accounts/use-account-lookup';
|
export * from './hooks/accounts/use-account-lookup';
|
||||||
export * from './hooks/accounts/use-account-relationship';
|
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-instance';
|
||||||
export * from './hooks/instance/use-translation-languages';
|
export * from './hooks/instance/use-translation-languages';
|
||||||
export * from './hooks/markers/use-markers';
|
export * from './hooks/markers/use-markers';
|
||||||
|
|
Loading…
Reference in a new issue