mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Use react query to fetch syncplay groups
This commit is contained in:
parent
55a2ca3590
commit
e46330c70d
2 changed files with 28 additions and 22 deletions
24
src/hooks/useSyncPlayGroups.ts
Normal file
24
src/hooks/useSyncPlayGroups.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
import { JellyfinApiContext, useApi } from './useApi';
|
||||
import { getSyncPlayApi } from '@jellyfin/sdk/lib/utils/api/sync-play-api';
|
||||
import { AxiosRequestConfig } from 'axios';
|
||||
|
||||
const fetchSyncPlayGroups = async (
|
||||
currentApi: JellyfinApiContext,
|
||||
options?: AxiosRequestConfig
|
||||
) => {
|
||||
const { api } = currentApi;
|
||||
if (!api) throw new Error('No API instance available');
|
||||
|
||||
const response = await getSyncPlayApi(api)
|
||||
.syncPlayGetGroups(options);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const useSyncPlayGroups = () => {
|
||||
const currentApi = useApi();
|
||||
return useQuery({
|
||||
queryKey: [ 'SyncPlay', 'Groups' ],
|
||||
queryFn: ({ signal }) => fetchSyncPlayGroups(currentApi, { signal })
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue