mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Add abort signal to api hooks
This commit is contained in:
parent
9bb2541ad8
commit
6a8fdc7e81
2 changed files with 8 additions and 6 deletions
|
@ -2,14 +2,15 @@ import { Api } from '@jellyfin/sdk';
|
||||||
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
|
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useApi } from 'hooks/useApi';
|
import { useApi } from 'hooks/useApi';
|
||||||
|
import type { AxiosRequestConfig } from 'axios';
|
||||||
|
|
||||||
const fetchLogEntries = async (api?: Api) => {
|
const fetchLogEntries = async (api?: Api, options?: AxiosRequestConfig) => {
|
||||||
if (!api) {
|
if (!api) {
|
||||||
console.error('[useLogEntries] No API instance available');
|
console.error('[useLogEntries] No API instance available');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await getSystemApi(api).getServerLogs();
|
const response = await getSystemApi(api).getServerLogs(options);
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
@ -19,7 +20,7 @@ export const useLogEntries = () => {
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [ 'LogEntries' ],
|
queryKey: [ 'LogEntries' ],
|
||||||
queryFn: () => fetchLogEntries(api),
|
queryFn: ({ signal }) => fetchLogEntries(api, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,14 +2,15 @@ import { Api } from '@jellyfin/sdk';
|
||||||
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
|
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useApi } from 'hooks/useApi';
|
import { useApi } from 'hooks/useApi';
|
||||||
|
import type { AxiosRequestConfig } from 'axios';
|
||||||
|
|
||||||
export const fetchLogOptions = async (api?: Api) => {
|
export const fetchLogOptions = async (api?: Api, options?: AxiosRequestConfig) => {
|
||||||
if (!api) {
|
if (!api) {
|
||||||
console.error('[useLogOptions] No API instance available');
|
console.error('[useLogOptions] No API instance available');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await getConfigurationApi(api).getConfiguration();
|
const response = await getConfigurationApi(api).getConfiguration(options);
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
@ -19,7 +20,7 @@ export const useLogOptions = () => {
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['LogOptions'],
|
queryKey: ['LogOptions'],
|
||||||
queryFn: () => fetchLogOptions(api),
|
queryFn: ({ signal }) => fetchLogOptions(api, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue