Migrate plugins catalog to React
This commit is contained in:
@@ -7,12 +7,24 @@ import type { AxiosRequestConfig } from 'axios';
|
||||
import { useApi } from 'hooks/useApi';
|
||||
|
||||
import { QueryKey } from './queryKey';
|
||||
import { queryClient } from 'utils/query/queryClient';
|
||||
import type { PackageInfo } from '@jellyfin/sdk/lib/generated-client/models/package-info';
|
||||
|
||||
const fetchPackageInfo = async (
|
||||
api: Api,
|
||||
params: PackageApiGetPackageInfoRequest,
|
||||
options?: AxiosRequestConfig
|
||||
) => {
|
||||
const packagesData = queryClient.getQueryData([ QueryKey.Packages ]) as PackageInfo[];
|
||||
if (packagesData && params.assemblyGuid) {
|
||||
// Use cached query to avoid re-fetching
|
||||
const pkg = packagesData.find(v => v.guid === params.assemblyGuid);
|
||||
|
||||
if (pkg) {
|
||||
return pkg;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await getPackageApi(api)
|
||||
.getPackageInfo(params, options);
|
||||
return response.data;
|
||||
@@ -24,7 +36,7 @@ const getPackageInfoQuery = (
|
||||
) => queryOptions({
|
||||
// Don't retry since requests for plugins not available in repos fail
|
||||
retry: false,
|
||||
queryKey: [ QueryKey.PackageInfo, params?.name, params?.assemblyGuid ],
|
||||
queryKey: [ QueryKey.Packages, params?.name, params?.assemblyGuid ],
|
||||
queryFn: ({ signal }) => fetchPackageInfo(api!, params!, { signal }),
|
||||
enabled: !!params && !!api && !!params.name
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user