mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Migrate apikeys to React (#6390)
This commit is contained in:
parent
4e750711b7
commit
fa749e4d45
8 changed files with 241 additions and 121 deletions
27
src/apps/dashboard/features/keys/api/useApiKeys.ts
Normal file
27
src/apps/dashboard/features/keys/api/useApiKeys.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { Api } from '@jellyfin/sdk';
|
||||
import { getApiKeyApi } from '@jellyfin/sdk/lib/utils/api/api-key-api';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useApi } from 'hooks/useApi';
|
||||
|
||||
export const QUERY_KEY = 'ApiKeys';
|
||||
|
||||
const fetchApiKeys = async (api?: Api) => {
|
||||
if (!api) {
|
||||
console.error('[useApiKeys] Failed to create Api instance');
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await getApiKeyApi(api).getKeys();
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const useApiKeys = () => {
|
||||
const { api } = useApi();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [ QUERY_KEY ],
|
||||
queryFn: () => fetchApiKeys(api),
|
||||
enabled: !!api
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue