mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Refactor queries to use non-null assert
This commit is contained in:
parent
3df39d659c
commit
2ce9e9f1e0
28 changed files with 47 additions and 127 deletions
|
@ -1,17 +1,13 @@
|
|||
import { Api } from '@jellyfin/sdk';
|
||||
import { getApiKeyApi } from '@jellyfin/sdk/lib/utils/api/api-key-api';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { AxiosRequestConfig } from 'axios';
|
||||
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();
|
||||
const fetchApiKeys = async (api: Api, options?: AxiosRequestConfig) => {
|
||||
const response = await getApiKeyApi(api).getKeys(options);
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
@ -21,7 +17,7 @@ export const useApiKeys = () => {
|
|||
|
||||
return useQuery({
|
||||
queryKey: [ QUERY_KEY ],
|
||||
queryFn: () => fetchApiKeys(api),
|
||||
queryFn: ({ signal }) => fetchApiKeys(api!, { signal }),
|
||||
enabled: !!api
|
||||
});
|
||||
};
|
||||
|
|
|
@ -10,7 +10,6 @@ export const useCreateKey = () => {
|
|||
|
||||
return useMutation({
|
||||
mutationFn: (params: ApiKeyApiCreateKeyRequest) => (
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
getApiKeyApi(api!)
|
||||
.createKey(params)
|
||||
),
|
||||
|
|
|
@ -10,7 +10,6 @@ export const useRevokeKey = () => {
|
|||
|
||||
return useMutation({
|
||||
mutationFn: (params: ApiKeyApiRevokeKeyRequest) => (
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
getApiKeyApi(api!)
|
||||
.revokeKey(params)
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue