mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
refactor activity page to use react query requests
Co-authored-by: Bill Thornton <thornbill@users.noreply.github.com>
This commit is contained in:
parent
656799cce7
commit
710fe641e2
4 changed files with 98 additions and 63 deletions
31
src/hooks/useUsers.tsx
Normal file
31
src/hooks/useUsers.tsx
Normal file
|
@ -0,0 +1,31 @@
|
|||
import type { AxiosRequestConfig } from 'axios';
|
||||
import type { UserApiGetUsersRequest } from '@jellyfin/sdk/lib/generated-client';
|
||||
import { getUserApi } from '@jellyfin/sdk/lib/utils/api/user-api';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { type JellyfinApiContext, useApi } from './useApi';
|
||||
|
||||
export const fetchGetUsers = async (
|
||||
currentApi: JellyfinApiContext,
|
||||
requestParams?: UserApiGetUsersRequest,
|
||||
options?: AxiosRequestConfig
|
||||
) => {
|
||||
const { api } = currentApi;
|
||||
|
||||
if (!api) return;
|
||||
|
||||
const response = await getUserApi(api).getUsers(requestParams, {
|
||||
signal: options?.signal
|
||||
});
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const useUsers = (requestParams?: UserApiGetUsersRequest) => {
|
||||
const currentApi = useApi();
|
||||
return useQuery({
|
||||
queryKey: ['Users'],
|
||||
queryFn: ({ signal }) =>
|
||||
fetchGetUsers(currentApi, requestParams, { signal })
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue