mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Refactor: viewitemcontainer
This commit is contained in:
parent
550ad476af
commit
c61df2eb92
28 changed files with 520 additions and 1001 deletions
|
@ -1,12 +1,11 @@
|
|||
import type { ItemsApiGetItemsRequest } from '@jellyfin/sdk/lib/generated-client';
|
||||
import { AxiosRequestConfig } from 'axios';
|
||||
|
||||
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind';
|
||||
import type { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind';
|
||||
import { ImageType } from '@jellyfin/sdk/lib/generated-client/models/image-type';
|
||||
import { ItemFields } from '@jellyfin/sdk/lib/generated-client/models/item-fields';
|
||||
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 { getArtistsApi } from '@jellyfin/sdk/lib/utils/api/artists-api';
|
||||
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';
|
||||
|
@ -14,11 +13,14 @@ 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 { AxiosRequestConfig } from 'axios';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { JellyfinApiContext, useApi } from './useApi';
|
||||
import { getAlphaPickerQuery, getFieldsQuery, getFiltersQuery, getLimitQuery } from 'utils/items';
|
||||
import { Sections, SectionsViewType } from 'types/suggestionsSections';
|
||||
import { ParentId } from 'types/library';
|
||||
import { LibraryViewSettings, ParentId } from 'types/library';
|
||||
import { LibraryTab } from 'types/libraryTab';
|
||||
|
||||
const fetchGetItem = async (
|
||||
currentApi: JellyfinApiContext,
|
||||
|
@ -291,7 +293,7 @@ export const useGetGenres = (itemType: BaseItemKind, parentId: ParentId) => {
|
|||
const fetchGetStudios = async (
|
||||
currentApi: JellyfinApiContext,
|
||||
parentId: ParentId,
|
||||
itemType: BaseItemKind,
|
||||
itemType: BaseItemKind[],
|
||||
options?: AxiosRequestConfig
|
||||
) => {
|
||||
const { api, user } = currentApi;
|
||||
|
@ -299,7 +301,7 @@ const fetchGetStudios = async (
|
|||
const response = await getStudiosApi(api).getStudios(
|
||||
{
|
||||
userId: user.Id,
|
||||
includeItemTypes: [itemType],
|
||||
includeItemTypes: itemType,
|
||||
fields: [
|
||||
ItemFields.DateCreated,
|
||||
ItemFields.PrimaryImageAspectRatio
|
||||
|
@ -316,7 +318,7 @@ const fetchGetStudios = async (
|
|||
}
|
||||
};
|
||||
|
||||
export const useGetStudios = (parentId: ParentId, itemType: BaseItemKind) => {
|
||||
export const useGetStudios = (parentId: ParentId, itemType: BaseItemKind[]) => {
|
||||
const currentApi = useApi();
|
||||
return useQuery({
|
||||
queryKey: ['Studios', parentId, itemType],
|
||||
|
@ -329,7 +331,7 @@ export const useGetStudios = (parentId: ParentId, itemType: BaseItemKind) => {
|
|||
const fetchGetQueryFiltersLegacy = async (
|
||||
currentApi: JellyfinApiContext,
|
||||
parentId: ParentId,
|
||||
itemType: BaseItemKind,
|
||||
itemType: BaseItemKind[],
|
||||
options?: AxiosRequestConfig
|
||||
) => {
|
||||
const { api, user } = currentApi;
|
||||
|
@ -338,7 +340,7 @@ const fetchGetQueryFiltersLegacy = async (
|
|||
{
|
||||
userId: user.Id,
|
||||
parentId: parentId ?? undefined,
|
||||
includeItemTypes: [itemType]
|
||||
includeItemTypes: itemType
|
||||
},
|
||||
{
|
||||
signal: options?.signal
|
||||
|
@ -350,7 +352,7 @@ const fetchGetQueryFiltersLegacy = async (
|
|||
|
||||
export const useGetQueryFiltersLegacy = (
|
||||
parentId: ParentId,
|
||||
itemType: BaseItemKind
|
||||
itemType: BaseItemKind[]
|
||||
) => {
|
||||
const currentApi = useApi();
|
||||
return useQuery({
|
||||
|
@ -362,3 +364,148 @@ export const useGetQueryFiltersLegacy = (
|
|||
enabled: !!parentId
|
||||
});
|
||||
};
|
||||
|
||||
const fetchGetItemsViewByType = async (
|
||||
currentApi: JellyfinApiContext,
|
||||
viewType: LibraryTab,
|
||||
parentId: ParentId,
|
||||
itemType: BaseItemKind[],
|
||||
libraryViewSettings: LibraryViewSettings,
|
||||
options?: AxiosRequestConfig
|
||||
) => {
|
||||
const { api, user } = currentApi;
|
||||
if (api && user?.Id) {
|
||||
let response;
|
||||
switch (viewType) {
|
||||
case LibraryTab.AlbumArtists: {
|
||||
response = await getArtistsApi(api).getAlbumArtists(
|
||||
{
|
||||
userId: user.Id,
|
||||
parentId: parentId ?? undefined,
|
||||
enableImageTypes: [libraryViewSettings.ImageType, ImageType.Backdrop],
|
||||
...getFieldsQuery(viewType, libraryViewSettings),
|
||||
...getFiltersQuery(viewType, libraryViewSettings),
|
||||
...getLimitQuery(),
|
||||
...getAlphaPickerQuery(libraryViewSettings),
|
||||
sortBy: [libraryViewSettings.SortBy],
|
||||
sortOrder: [libraryViewSettings.SortOrder],
|
||||
includeItemTypes: itemType,
|
||||
startIndex: libraryViewSettings.StartIndex
|
||||
},
|
||||
{
|
||||
signal: options?.signal
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
case LibraryTab.Artists: {
|
||||
response = await getArtistsApi(api).getArtists(
|
||||
{
|
||||
userId: user.Id,
|
||||
parentId: parentId ?? undefined,
|
||||
enableImageTypes: [libraryViewSettings.ImageType, ImageType.Backdrop],
|
||||
...getFieldsQuery(viewType, libraryViewSettings),
|
||||
...getFiltersQuery(viewType, libraryViewSettings),
|
||||
...getLimitQuery(),
|
||||
...getAlphaPickerQuery(libraryViewSettings),
|
||||
sortBy: [libraryViewSettings.SortBy],
|
||||
sortOrder: [libraryViewSettings.SortOrder],
|
||||
includeItemTypes: itemType,
|
||||
startIndex: libraryViewSettings.StartIndex
|
||||
},
|
||||
{
|
||||
signal: options?.signal
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
case LibraryTab.Networks:
|
||||
response = await getStudiosApi(api).getStudios(
|
||||
{
|
||||
userId: user.Id,
|
||||
parentId: parentId ?? undefined,
|
||||
...getFieldsQuery(viewType, libraryViewSettings),
|
||||
includeItemTypes: itemType,
|
||||
enableImageTypes: [ImageType.Thumb],
|
||||
startIndex: libraryViewSettings.StartIndex
|
||||
},
|
||||
{
|
||||
signal: options?.signal
|
||||
}
|
||||
);
|
||||
break;
|
||||
default: {
|
||||
response = await getItemsApi(api).getItems(
|
||||
{
|
||||
userId: user.Id,
|
||||
recursive: true,
|
||||
imageTypeLimit: 1,
|
||||
parentId: parentId ?? undefined,
|
||||
enableImageTypes: [libraryViewSettings.ImageType, ImageType.Backdrop],
|
||||
...getFieldsQuery(viewType, libraryViewSettings),
|
||||
...getFiltersQuery(viewType, libraryViewSettings),
|
||||
...getLimitQuery(),
|
||||
...getAlphaPickerQuery(libraryViewSettings),
|
||||
isFavorite: viewType === LibraryTab.Favorites ? true : undefined,
|
||||
sortBy: [libraryViewSettings.SortBy],
|
||||
sortOrder: [libraryViewSettings.SortOrder],
|
||||
includeItemTypes: itemType,
|
||||
startIndex: libraryViewSettings.StartIndex
|
||||
},
|
||||
{
|
||||
signal: options?.signal
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
export const useGetItemsViewByType = (
|
||||
viewType: LibraryTab,
|
||||
parentId: ParentId,
|
||||
itemType: BaseItemKind[],
|
||||
libraryViewSettings: LibraryViewSettings
|
||||
) => {
|
||||
const currentApi = useApi();
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'ItemsViewByType',
|
||||
viewType,
|
||||
parentId,
|
||||
itemType,
|
||||
libraryViewSettings
|
||||
],
|
||||
queryFn: ({ signal }) =>
|
||||
fetchGetItemsViewByType(
|
||||
currentApi,
|
||||
viewType,
|
||||
parentId,
|
||||
itemType,
|
||||
libraryViewSettings,
|
||||
{ signal }
|
||||
),
|
||||
refetchOnWindowFocus: false,
|
||||
keepPreviousData : true,
|
||||
enabled:
|
||||
[
|
||||
LibraryTab.Movies,
|
||||
LibraryTab.Favorites,
|
||||
LibraryTab.Collections,
|
||||
LibraryTab.Trailers,
|
||||
LibraryTab.Series,
|
||||
LibraryTab.Episodes,
|
||||
LibraryTab.Networks,
|
||||
LibraryTab.Albums,
|
||||
LibraryTab.AlbumArtists,
|
||||
LibraryTab.Artists,
|
||||
LibraryTab.Playlists,
|
||||
LibraryTab.Songs,
|
||||
LibraryTab.Books,
|
||||
LibraryTab.Photos,
|
||||
LibraryTab.Videos
|
||||
].includes(viewType) && !!parentId
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue