1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Add Filter setting components

This commit is contained in:
grafixeyehero 2023-07-09 01:43:08 +03:00
parent 5598f49c32
commit 3ae27e05c7
14 changed files with 1392 additions and 8 deletions

View file

@ -7,9 +7,11 @@ import { ItemFields } from '@jellyfin/sdk/lib/generated-client/models/item-field
import { ItemFilter } from '@jellyfin/sdk/lib/generated-client/models/item-filter';
import { SortOrder } from '@jellyfin/sdk/lib/generated-client/models/sort-order';
import { ItemSortBy } from '@jellyfin/sdk/lib/models/api/item-sort-by';
import { getFilterApi } from '@jellyfin/sdk/lib/utils/api/filter-api';
import { getGenresApi } from '@jellyfin/sdk/lib/utils/api/genres-api';
import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api';
import { getMoviesApi } from '@jellyfin/sdk/lib/utils/api/movies-api';
import { getStudiosApi } from '@jellyfin/sdk/lib/utils/api/studios-api';
import { getTvShowsApi } from '@jellyfin/sdk/lib/utils/api/tv-shows-api';
import { getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api/user-library-api';
import { useQuery } from '@tanstack/react-query';
@ -19,7 +21,7 @@ import { Sections, SectionsViewType } from 'types/suggestionsSections';
const fetchGetItem = async (
currentApi: JellyfinApiContext,
parentId?: string | null,
parentId: string | null | undefined,
options?: AxiosRequestConfig
) => {
const { api, user } = currentApi;
@ -37,7 +39,7 @@ const fetchGetItem = async (
}
};
export const useGetItem = (parentId?: string | null) => {
export const useGetItem = (parentId: string | null | undefined) => {
const currentApi = useApi();
return useQuery({
queryKey: ['Item', parentId],
@ -83,7 +85,7 @@ export const useGetItems = (parametersOptions: ItemsApiGetItemsRequest) => {
const fetchGetMovieRecommendations = async (
currentApi: JellyfinApiContext,
parentId?: string | null,
parentId: string | null | undefined,
options?: AxiosRequestConfig
) => {
const { api, user } = currentApi;
@ -108,7 +110,7 @@ const fetchGetMovieRecommendations = async (
}
};
export const useGetMovieRecommendations = (parentId?: string | null) => {
export const useGetMovieRecommendations = (parentId: string | null | undefined) => {
const currentApi = useApi();
return useQuery({
queryKey: ['MovieRecommendations', parentId],
@ -121,7 +123,7 @@ export const useGetMovieRecommendations = (parentId?: string | null) => {
const fetchGetItemsBySuggestionsType = async (
currentApi: JellyfinApiContext,
sections: Sections,
parentId?: string | null,
parentId: string | null | undefined,
options?: AxiosRequestConfig
) => {
const { api, user } = currentApi;
@ -234,7 +236,7 @@ const fetchGetItemsBySuggestionsType = async (
export const useGetItemsBySectionType = (
sections: Sections,
parentId?: string | null
parentId: string | null | undefined
) => {
const currentApi = useApi();
return useQuery({
@ -253,7 +255,7 @@ export const useGetItemsBySectionType = (
const fetchGetGenres = async (
currentApi: JellyfinApiContext,
itemType: BaseItemKind,
parentId?: string | null,
parentId: string | null | undefined,
options?: AxiosRequestConfig
) => {
const { api, user } = currentApi;
@ -275,7 +277,7 @@ const fetchGetGenres = async (
}
};
export const useGetGenres = (itemType: BaseItemKind, parentId?: string | null) => {
export const useGetGenres = (itemType: BaseItemKind, parentId: string | null | undefined) => {
const currentApi = useApi();
return useQuery({
queryKey: ['Genres', parentId],
@ -284,3 +286,78 @@ export const useGetGenres = (itemType: BaseItemKind, parentId?: string | null) =
enabled: !!parentId
});
};
const fetchGetStudios = async (
currentApi: JellyfinApiContext,
parentId: string | null | undefined,
itemType: BaseItemKind,
options?: AxiosRequestConfig
) => {
const { api, user } = currentApi;
if (api && user?.Id) {
const response = await getStudiosApi(api).getStudios(
{
userId: user.Id,
includeItemTypes: [itemType],
fields: [
ItemFields.DateCreated,
ItemFields.PrimaryImageAspectRatio
],
enableImageTypes: [ImageType.Thumb],
parentId: parentId ?? undefined,
enableTotalRecordCount: false
},
{
signal: options?.signal
}
);
return response.data;
}
};
export const useGetStudios = (parentId: string | null | undefined, itemType: BaseItemKind) => {
const currentApi = useApi();
return useQuery({
queryKey: ['Studios', parentId, itemType],
queryFn: ({ signal }) =>
fetchGetStudios(currentApi, parentId, itemType, { signal }),
enabled: !!parentId
});
};
const fetchGetQueryFiltersLegacy = async (
currentApi: JellyfinApiContext,
parentId: string | null | undefined,
itemType: BaseItemKind,
options?: AxiosRequestConfig
) => {
const { api, user } = currentApi;
if (api && user?.Id) {
const response = await getFilterApi(api).getQueryFiltersLegacy(
{
userId: user.Id,
parentId: parentId ?? undefined,
includeItemTypes: [itemType]
},
{
signal: options?.signal
}
);
return response.data;
}
};
export const useGetQueryFiltersLegacy = (
parentId: string | null | undefined,
itemType: BaseItemKind
) => {
const currentApi = useApi();
return useQuery({
queryKey: ['QueryFiltersLegacy', parentId, itemType],
queryFn: ({ signal }) =>
fetchGetQueryFiltersLegacy(currentApi, parentId, itemType, {
signal
}),
enabled: !!parentId
});
};