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
|
@ -7,15 +7,10 @@ import { useQuery } from '@tanstack/react-query';
|
||||||
import { useApi } from 'hooks/useApi';
|
import { useApi } from 'hooks/useApi';
|
||||||
|
|
||||||
const fetchLogEntries = async (
|
const fetchLogEntries = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
requestParams?: ActivityLogApiGetLogEntriesRequest,
|
requestParams?: ActivityLogApiGetLogEntriesRequest,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchLogEntries] No API instance available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getActivityLogApi(api).getLogEntries(requestParams, {
|
const response = await getActivityLogApi(api).getLogEntries(requestParams, {
|
||||||
signal: options?.signal
|
signal: options?.signal
|
||||||
});
|
});
|
||||||
|
@ -30,7 +25,7 @@ export const useLogEntries = (
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['ActivityLogEntries', requestParams],
|
queryKey: ['ActivityLogEntries', requestParams],
|
||||||
queryFn: ({ signal }) =>
|
queryFn: ({ signal }) =>
|
||||||
fetchLogEntries(api, requestParams, { signal }),
|
fetchLogEntries(api!, requestParams, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,14 +8,9 @@ import { useApi } from 'hooks/useApi';
|
||||||
export const QUERY_KEY = 'BrandingOptions';
|
export const QUERY_KEY = 'BrandingOptions';
|
||||||
|
|
||||||
const fetchBrandingOptions = async (
|
const fetchBrandingOptions = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.error('[fetchBrandingOptions] no Api instance provided');
|
|
||||||
throw new Error('No Api instance provided to fetchBrandingOptions');
|
|
||||||
}
|
|
||||||
|
|
||||||
return getBrandingApi(api)
|
return getBrandingApi(api)
|
||||||
.getBrandingOptions(options)
|
.getBrandingOptions(options)
|
||||||
.then(({ data }) => data);
|
.then(({ data }) => data);
|
||||||
|
@ -25,7 +20,7 @@ export const getBrandingOptionsQuery = (
|
||||||
api?: Api
|
api?: Api
|
||||||
) => queryOptions({
|
) => queryOptions({
|
||||||
queryKey: [ QUERY_KEY ],
|
queryKey: [ QUERY_KEY ],
|
||||||
queryFn: ({ signal }) => fetchBrandingOptions(api, { signal }),
|
queryFn: ({ signal }) => fetchBrandingOptions(api!, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ export const useDeleteDevice = () => {
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: DevicesApiDeleteDeviceRequest) => (
|
mutationFn: (params: DevicesApiDeleteDeviceRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getDevicesApi(api!)
|
getDevicesApi(api!)
|
||||||
.deleteDevice(params)
|
.deleteDevice(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -9,15 +9,10 @@ import { useApi } from 'hooks/useApi';
|
||||||
export const QUERY_KEY = 'Devices';
|
export const QUERY_KEY = 'Devices';
|
||||||
|
|
||||||
const fetchDevices = async (
|
const fetchDevices = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
requestParams?: DevicesApiGetDevicesRequest,
|
requestParams?: DevicesApiGetDevicesRequest,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchDevices] No API instance available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getDevicesApi(api).getDevices(requestParams, {
|
const response = await getDevicesApi(api).getDevices(requestParams, {
|
||||||
signal: options?.signal
|
signal: options?.signal
|
||||||
});
|
});
|
||||||
|
@ -32,7 +27,7 @@ export const useDevices = (
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [QUERY_KEY, requestParams],
|
queryKey: [QUERY_KEY, requestParams],
|
||||||
queryFn: ({ signal }) =>
|
queryFn: ({ signal }) =>
|
||||||
fetchDevices(api, requestParams, { signal }),
|
fetchDevices(api!, requestParams, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,6 @@ export const useUpdateDevice = () => {
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: DevicesApiUpdateDeviceOptionsRequest) => (
|
mutationFn: (params: DevicesApiUpdateDeviceOptionsRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getDevicesApi(api!)
|
getDevicesApi(api!)
|
||||||
.updateDeviceOptions(params)
|
.updateDeviceOptions(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
import { Api } from '@jellyfin/sdk';
|
import { Api } from '@jellyfin/sdk';
|
||||||
import { getApiKeyApi } from '@jellyfin/sdk/lib/utils/api/api-key-api';
|
import { getApiKeyApi } from '@jellyfin/sdk/lib/utils/api/api-key-api';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { AxiosRequestConfig } from 'axios';
|
||||||
import { useApi } from 'hooks/useApi';
|
import { useApi } from 'hooks/useApi';
|
||||||
|
|
||||||
export const QUERY_KEY = 'ApiKeys';
|
export const QUERY_KEY = 'ApiKeys';
|
||||||
|
|
||||||
const fetchApiKeys = async (api?: Api) => {
|
const fetchApiKeys = async (api: Api, options?: AxiosRequestConfig) => {
|
||||||
if (!api) {
|
const response = await getApiKeyApi(api).getKeys(options);
|
||||||
console.error('[useApiKeys] Failed to create Api instance');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getApiKeyApi(api).getKeys();
|
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
@ -21,7 +17,7 @@ export const useApiKeys = () => {
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [ QUERY_KEY ],
|
queryKey: [ QUERY_KEY ],
|
||||||
queryFn: () => fetchApiKeys(api),
|
queryFn: ({ signal }) => fetchApiKeys(api!, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,6 @@ export const useCreateKey = () => {
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: ApiKeyApiCreateKeyRequest) => (
|
mutationFn: (params: ApiKeyApiCreateKeyRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getApiKeyApi(api!)
|
getApiKeyApi(api!)
|
||||||
.createKey(params)
|
.createKey(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -10,7 +10,6 @@ export const useRevokeKey = () => {
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: ApiKeyApiRevokeKeyRequest) => (
|
mutationFn: (params: ApiKeyApiRevokeKeyRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getApiKeyApi(api!)
|
getApiKeyApi(api!)
|
||||||
.revokeKey(params)
|
.revokeKey(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -4,13 +4,8 @@ import { useQuery } from '@tanstack/react-query';
|
||||||
import { useApi } from 'hooks/useApi';
|
import { useApi } from 'hooks/useApi';
|
||||||
import type { AxiosRequestConfig } from 'axios';
|
import type { AxiosRequestConfig } from 'axios';
|
||||||
|
|
||||||
const fetchServerLogs = async (api?: Api, options?: AxiosRequestConfig) => {
|
const fetchServerLogs = async (api: Api, options?: AxiosRequestConfig) => {
|
||||||
if (!api) {
|
const response = await getSystemApi(api!).getServerLogs(options);
|
||||||
console.error('[useServerLogs] No API instance available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getSystemApi(api).getServerLogs(options);
|
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
@ -20,7 +15,7 @@ export const useServerLogs = () => {
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [ 'ServerLogs' ],
|
queryKey: [ 'ServerLogs' ],
|
||||||
queryFn: ({ signal }) => fetchServerLogs(api, { signal }),
|
queryFn: ({ signal }) => fetchServerLogs(api!, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,15 +9,10 @@ import { useApi } from 'hooks/useApi';
|
||||||
import { QueryKey } from './queryKey';
|
import { QueryKey } from './queryKey';
|
||||||
|
|
||||||
const fetchConfigurationPages = async (
|
const fetchConfigurationPages = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
params?: DashboardApiGetConfigurationPagesRequest,
|
params?: DashboardApiGetConfigurationPagesRequest,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchConfigurationPages] No API instance available');
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getDashboardApi(api)
|
const response = await getDashboardApi(api)
|
||||||
.getConfigurationPages(params, options);
|
.getConfigurationPages(params, options);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -28,7 +23,7 @@ const getConfigurationPagesQuery = (
|
||||||
params?: DashboardApiGetConfigurationPagesRequest
|
params?: DashboardApiGetConfigurationPagesRequest
|
||||||
) => queryOptions({
|
) => queryOptions({
|
||||||
queryKey: [ QueryKey.ConfigurationPages, params?.enableInMainMenu ],
|
queryKey: [ QueryKey.ConfigurationPages, params?.enableInMainMenu ],
|
||||||
queryFn: ({ signal }) => fetchConfigurationPages(api, params, { signal }),
|
queryFn: ({ signal }) => fetchConfigurationPages(api!, params, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ export const useDisablePlugin = () => {
|
||||||
const { api } = useApi();
|
const { api } = useApi();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: PluginsApiDisablePluginRequest) => (
|
mutationFn: (params: PluginsApiDisablePluginRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getPluginsApi(api!)
|
getPluginsApi(api!)
|
||||||
.disablePlugin(params)
|
.disablePlugin(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -11,7 +11,6 @@ export const useEnablePlugin = () => {
|
||||||
const { api } = useApi();
|
const { api } = useApi();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: PluginsApiEnablePluginRequest) => (
|
mutationFn: (params: PluginsApiEnablePluginRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getPluginsApi(api!)
|
getPluginsApi(api!)
|
||||||
.enablePlugin(params)
|
.enablePlugin(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -11,7 +11,6 @@ export const useInstallPackage = () => {
|
||||||
const { api } = useApi();
|
const { api } = useApi();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: PackageApiInstallPackageRequest) => (
|
mutationFn: (params: PackageApiInstallPackageRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getPackageApi(api!)
|
getPackageApi(api!)
|
||||||
.installPackage(params)
|
.installPackage(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -9,34 +9,24 @@ import { useApi } from 'hooks/useApi';
|
||||||
import { QueryKey } from './queryKey';
|
import { QueryKey } from './queryKey';
|
||||||
|
|
||||||
const fetchPackageInfo = async (
|
const fetchPackageInfo = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
params?: PackageApiGetPackageInfoRequest,
|
params: PackageApiGetPackageInfoRequest,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchPackageInfo] No API instance available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!params) {
|
|
||||||
console.warn('[fetchPackageInfo] Missing request params');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getPackageApi(api)
|
const response = await getPackageApi(api)
|
||||||
.getPackageInfo(params, options);
|
.getPackageInfo(params, options);
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPackageInfoQuery = (
|
const getPackageInfoQuery = (
|
||||||
api?: Api,
|
api: Api | undefined,
|
||||||
params?: PackageApiGetPackageInfoRequest
|
params?: PackageApiGetPackageInfoRequest
|
||||||
) => queryOptions({
|
) => queryOptions({
|
||||||
// Don't retry since requests for plugins not available in repos fail
|
// Don't retry since requests for plugins not available in repos fail
|
||||||
retry: false,
|
retry: false,
|
||||||
queryKey: [ QueryKey.PackageInfo, params?.name, params?.assemblyGuid ],
|
queryKey: [ QueryKey.PackageInfo, params?.name, params?.assemblyGuid ],
|
||||||
queryFn: ({ signal }) => fetchPackageInfo(api, params, { signal }),
|
queryFn: ({ signal }) => fetchPackageInfo(api!, params!, { signal }),
|
||||||
enabled: !!api && !!params?.name
|
enabled: !!params && !!api && !!params.name
|
||||||
});
|
});
|
||||||
|
|
||||||
export const usePackageInfo = (
|
export const usePackageInfo = (
|
||||||
|
|
|
@ -8,14 +8,9 @@ import { useApi } from 'hooks/useApi';
|
||||||
import { QueryKey } from './queryKey';
|
import { QueryKey } from './queryKey';
|
||||||
|
|
||||||
const fetchPlugins = async (
|
const fetchPlugins = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchPlugins] No API instance available');
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getPluginsApi(api)
|
const response = await getPluginsApi(api)
|
||||||
.getPlugins(options);
|
.getPlugins(options);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -25,7 +20,7 @@ const getPluginsQuery = (
|
||||||
api?: Api
|
api?: Api
|
||||||
) => queryOptions({
|
) => queryOptions({
|
||||||
queryKey: [ QueryKey.Plugins ],
|
queryKey: [ QueryKey.Plugins ],
|
||||||
queryFn: ({ signal }) => fetchPlugins(api, { signal }),
|
queryFn: ({ signal }) => fetchPlugins(api!, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ export const useUninstallPlugin = () => {
|
||||||
const { api } = useApi();
|
const { api } = useApi();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: PluginsApiUninstallPluginByVersionRequest) => (
|
mutationFn: (params: PluginsApiUninstallPluginByVersionRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getPluginsApi(api!)
|
getPluginsApi(api!)
|
||||||
.uninstallPluginByVersion(params)
|
.uninstallPluginByVersion(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -10,7 +10,6 @@ export const useStartTask = () => {
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: ScheduledTasksApiStartTaskRequest) => (
|
mutationFn: (params: ScheduledTasksApiStartTaskRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getScheduledTasksApi(api!)
|
getScheduledTasksApi(api!)
|
||||||
.startTask(params)
|
.startTask(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -10,7 +10,6 @@ export const useStopTask = () => {
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (params: ScheduledTasksApiStartTaskRequest) => (
|
mutationFn: (params: ScheduledTasksApiStartTaskRequest) => (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
getScheduledTasksApi(api!)
|
getScheduledTasksApi(api!)
|
||||||
.stopTask(params)
|
.stopTask(params)
|
||||||
),
|
),
|
||||||
|
|
|
@ -9,15 +9,10 @@ import { useApi } from 'hooks/useApi';
|
||||||
export const QUERY_KEY = 'Tasks';
|
export const QUERY_KEY = 'Tasks';
|
||||||
|
|
||||||
const fetchTasks = async (
|
const fetchTasks = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
params?: ScheduledTasksApiGetTasksRequest,
|
params?: ScheduledTasksApiGetTasksRequest,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchTasks] No API instance available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getScheduledTasksApi(api).getTasks(params, options);
|
const response = await getScheduledTasksApi(api).getTasks(params, options);
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -29,7 +24,7 @@ export const useTasks = (params?: ScheduledTasksApiGetTasksRequest) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [QUERY_KEY],
|
queryKey: [QUERY_KEY],
|
||||||
queryFn: ({ signal }) =>
|
queryFn: ({ signal }) =>
|
||||||
fetchTasks(api, params, { signal }),
|
fetchTasks(api!, params, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,8 +17,8 @@ async function mirrorIfEnabled(serverId: string, itemId: string) {
|
||||||
try {
|
try {
|
||||||
const item = await queryClient.fetchQuery(getItemQuery(
|
const item = await queryClient.fetchQuery(getItemQuery(
|
||||||
api,
|
api,
|
||||||
userId,
|
itemId,
|
||||||
itemId));
|
userId));
|
||||||
|
|
||||||
playbackManager.displayContent({
|
playbackManager.displayContent({
|
||||||
ItemName: item.Name,
|
ItemName: item.Name,
|
||||||
|
|
|
@ -142,7 +142,7 @@ class AppRouter {
|
||||||
const userId = apiClient.getCurrentUserId();
|
const userId = apiClient.getCurrentUserId();
|
||||||
|
|
||||||
queryClient
|
queryClient
|
||||||
.fetchQuery(getItemQuery(api, userId, item))
|
.fetchQuery(getItemQuery(api, item, userId))
|
||||||
.then(itemObject => {
|
.then(itemObject => {
|
||||||
this.showItem(itemObject, options);
|
this.showItem(itemObject, options);
|
||||||
})
|
})
|
||||||
|
|
|
@ -84,8 +84,9 @@ async function loadThemeMedia(serverId, itemId) {
|
||||||
try {
|
try {
|
||||||
const item = await queryClient.fetchQuery(getItemQuery(
|
const item = await queryClient.fetchQuery(getItemQuery(
|
||||||
api,
|
api,
|
||||||
userId,
|
itemId,
|
||||||
itemId));
|
userId
|
||||||
|
));
|
||||||
|
|
||||||
if (item.CollectionType) {
|
if (item.CollectionType) {
|
||||||
stopIfPlaying();
|
stopIfPlaying();
|
||||||
|
|
|
@ -7,26 +7,23 @@ import { useApi } from './useApi';
|
||||||
import type { ItemDto } from 'types/base/models/item-dto';
|
import type { ItemDto } from 'types/base/models/item-dto';
|
||||||
|
|
||||||
const fetchItem = async (
|
const fetchItem = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
userId?: string,
|
itemId: string,
|
||||||
itemId?: string,
|
userId: string,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) throw new Error('No API instance available');
|
|
||||||
if (!itemId) throw new Error('No item ID provided');
|
|
||||||
|
|
||||||
const response = await getUserLibraryApi(api)
|
const response = await getUserLibraryApi(api)
|
||||||
.getItem({ userId, itemId }, options);
|
.getItem({ userId, itemId }, options);
|
||||||
return response.data as ItemDto;
|
return response.data as ItemDto;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getItemQuery = (
|
export const getItemQuery = (
|
||||||
api?: Api,
|
api: Api | undefined,
|
||||||
userId?: string,
|
itemId?: string,
|
||||||
itemId?: string
|
userId?: string
|
||||||
) => queryOptions({
|
) => queryOptions({
|
||||||
queryKey: [ 'User', userId, 'Items', itemId ],
|
queryKey: [ 'User', userId, 'Items', itemId ],
|
||||||
queryFn: ({ signal }) => fetchItem(api, userId, itemId, { signal }),
|
queryFn: ({ signal }) => fetchItem(api!, itemId!, userId!, { signal }),
|
||||||
staleTime: 1000, // 1 second
|
staleTime: 1000, // 1 second
|
||||||
enabled: !!api && !!userId && !!itemId
|
enabled: !!api && !!userId && !!itemId
|
||||||
});
|
});
|
||||||
|
@ -36,5 +33,5 @@ export const useItem = (
|
||||||
) => {
|
) => {
|
||||||
const apiContext = useApi();
|
const apiContext = useApi();
|
||||||
const { api, user } = apiContext;
|
const { api, user } = apiContext;
|
||||||
return useQuery(getItemQuery(api, user?.Id, itemId));
|
return useQuery(getItemQuery(api, itemId, user?.Id));
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,14 +6,9 @@ import type { AxiosRequestConfig } from 'axios';
|
||||||
import { useApi } from './useApi';
|
import { useApi } from './useApi';
|
||||||
|
|
||||||
const fetchSyncPlayGroups = async (
|
const fetchSyncPlayGroups = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchSyncPlayGroups] No API instance available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getSyncPlayApi(api)
|
const response = await getSyncPlayApi(api)
|
||||||
.syncPlayGetGroups(options);
|
.syncPlayGetGroups(options);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -23,7 +18,7 @@ export const useSyncPlayGroups = () => {
|
||||||
const { api } = useApi();
|
const { api } = useApi();
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [ 'SyncPlay', 'Groups' ],
|
queryKey: [ 'SyncPlay', 'Groups' ],
|
||||||
queryFn: ({ signal }) => fetchSyncPlayGroups(api, { signal }),
|
queryFn: ({ signal }) => fetchSyncPlayGroups(api!, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,14 +6,9 @@ import type { AxiosRequestConfig } from 'axios';
|
||||||
import { useApi } from './useApi';
|
import { useApi } from './useApi';
|
||||||
|
|
||||||
const fetchSystemInfo = async (
|
const fetchSystemInfo = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchSystemInfo] No API instance available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getSystemApi(api)
|
const response = await getSystemApi(api)
|
||||||
.getSystemInfo(options);
|
.getSystemInfo(options);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -23,7 +18,7 @@ export const getSystemInfoQuery = (
|
||||||
api?: Api
|
api?: Api
|
||||||
) => queryOptions({
|
) => queryOptions({
|
||||||
queryKey: [ 'SystemInfo' ],
|
queryKey: [ 'SystemInfo' ],
|
||||||
queryFn: ({ signal }) => fetchSystemInfo(api, { signal, headers: { 'Cache-Control': 'no-cache' } }),
|
queryFn: ({ signal }) => fetchSystemInfo(api!, { signal, headers: { 'Cache-Control': 'no-cache' } }),
|
||||||
// Allow for query reuse in legacy javascript.
|
// Allow for query reuse in legacy javascript.
|
||||||
staleTime: 1000, // 1 second
|
staleTime: 1000, // 1 second
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
|
|
|
@ -7,14 +7,11 @@ import type { AxiosRequestConfig } from 'axios';
|
||||||
import { useApi } from './useApi';
|
import { useApi } from './useApi';
|
||||||
|
|
||||||
const fetchUserViews = async (
|
const fetchUserViews = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
userId?: string,
|
userId: string,
|
||||||
params?: UserViewsApiGetUserViewsRequest,
|
params?: UserViewsApiGetUserViewsRequest,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) throw new Error('No API instance available');
|
|
||||||
if (!userId) throw new Error('No User ID provided');
|
|
||||||
|
|
||||||
const response = await getUserViewsApi(api)
|
const response = await getUserViewsApi(api)
|
||||||
.getUserViews({ ...params, userId }, options);
|
.getUserViews({ ...params, userId }, options);
|
||||||
return response.data;
|
return response.data;
|
||||||
|
@ -26,7 +23,7 @@ export const getUserViewsQuery = (
|
||||||
params?: UserViewsApiGetUserViewsRequest
|
params?: UserViewsApiGetUserViewsRequest
|
||||||
) => queryOptions({
|
) => queryOptions({
|
||||||
queryKey: [ 'User', userId, 'Views', params ],
|
queryKey: [ 'User', userId, 'Views', params ],
|
||||||
queryFn: ({ signal }) => fetchUserViews(api, userId, params, { signal }),
|
queryFn: ({ signal }) => fetchUserViews(api!, userId!, params, { signal }),
|
||||||
// On initial page load we request user views 3x. Setting a 1 second stale time
|
// On initial page load we request user views 3x. Setting a 1 second stale time
|
||||||
// allows a single request to be made to resolve all 3.
|
// allows a single request to be made to resolve all 3.
|
||||||
staleTime: 1000, // 1 second
|
staleTime: 1000, // 1 second
|
||||||
|
|
|
@ -9,15 +9,10 @@ import { useApi } from './useApi';
|
||||||
export type UsersRecords = Record<string, UserDto>;
|
export type UsersRecords = Record<string, UserDto>;
|
||||||
|
|
||||||
const fetchUsers = async (
|
const fetchUsers = async (
|
||||||
api?: Api,
|
api: Api,
|
||||||
requestParams?: UserApiGetUsersRequest,
|
requestParams?: UserApiGetUsersRequest,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => {
|
) => {
|
||||||
if (!api) {
|
|
||||||
console.warn('[fetchUsers] No API instance available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await getUserApi(api).getUsers(requestParams, {
|
const response = await getUserApi(api).getUsers(requestParams, {
|
||||||
signal: options?.signal
|
signal: options?.signal
|
||||||
});
|
});
|
||||||
|
@ -30,7 +25,7 @@ export const useUsers = (requestParams?: UserApiGetUsersRequest) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ['Users'],
|
queryKey: ['Users'],
|
||||||
queryFn: ({ signal }) =>
|
queryFn: ({ signal }) =>
|
||||||
fetchUsers(api, requestParams, { signal }),
|
fetchUsers(api!, requestParams, { signal }),
|
||||||
enabled: !!api
|
enabled: !!api
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,6 @@ export function includesAny(list: string | string[] | null | undefined, search:
|
||||||
|
|
||||||
search = search.filter(i => i);
|
search = search.filter(i => i);
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
||||||
if (search.some(s => list!.includes(s))) {
|
if (search.some(s => list!.includes(s))) {
|
||||||
return !inverseMatch;
|
return !inverseMatch;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue