mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
27 lines
889 B
TypeScript
27 lines
889 B
TypeScript
import { Api } from '@jellyfin/sdk';
|
|
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { useApi } from 'hooks/useApi';
|
|
import type { AxiosRequestConfig } from 'axios';
|
|
|
|
export const QUERY_KEY = 'NamedConfiguration';
|
|
|
|
interface NamedConfiguration {
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
export const fetchNamedConfiguration = async (api: Api, key: string, options?: AxiosRequestConfig) => {
|
|
const response = await getConfigurationApi(api).getNamedConfiguration({ key }, options);
|
|
|
|
return response.data as unknown as NamedConfiguration;
|
|
};
|
|
|
|
export const useNamedConfiguration = (key: string) => {
|
|
const { api } = useApi();
|
|
|
|
return useQuery({
|
|
queryKey: [ QUERY_KEY ],
|
|
queryFn: ({ signal }) => fetchNamedConfiguration(api!, key, { signal }),
|
|
enabled: !!api
|
|
});
|
|
};
|