diff --git a/app/(auth)/(tabs)/(libraries)/[libraryId].tsx b/app/(auth)/(tabs)/(libraries)/[libraryId].tsx index 563759c1..1051b890 100644 --- a/app/(auth)/(tabs)/(libraries)/[libraryId].tsx +++ b/app/(auth)/(tabs)/(libraries)/[libraryId].tsx @@ -32,6 +32,7 @@ import { import { BaseItemDto, BaseItemDtoQueryResult, + BaseItemKind, } from "@jellyfin/sdk/lib/generated-client/models"; import { getFilterApi, @@ -40,8 +41,7 @@ import { } from "@jellyfin/sdk/lib/utils/api"; import { FlashList } from "@shopify/flash-list"; import { useSafeAreaInsets } from "react-native-safe-area-context"; - -const MemoizedTouchableItemRouter = React.memo(TouchableItemRouter); +import { colletionTypeToItemType } from "@/utils/collectionTypeToItemType"; const Page = () => { const searchParams = useLocalSearchParams(); @@ -141,6 +141,18 @@ const Page = () => { }): Promise => { if (!api || !library) return null; + console.log("[libraryId] ~", library); + + let itemType: BaseItemKind | undefined; + + // This fix makes sure to only return 1 type of items, if defined. + // This is because the underlying directory some times contains other types, and we don't want to show them. + if (library.CollectionType === "movies") { + itemType = "Movie"; + } else if (library.CollectionType === "tvshows") { + itemType = "Series"; + } + const response = await getItemsApi(api).getItems({ userId: user?.Id, parentId: libraryId, @@ -155,6 +167,7 @@ const Page = () => { genres: selectedGenres, tags: selectedTags, years: selectedYears.map((year) => parseInt(year)), + includeItemTypes: itemType ? [itemType] : undefined, }); return response.data || null; diff --git a/utils/collectionTypeToItemType.ts b/utils/collectionTypeToItemType.ts new file mode 100644 index 00000000..64c23ff0 --- /dev/null +++ b/utils/collectionTypeToItemType.ts @@ -0,0 +1,53 @@ +import { + BaseItemKind, + CollectionType, +} from "@jellyfin/sdk/lib/generated-client"; + +/** + * Converts a ColletionType to a BaseItemKind (also called ItemType) + * + * CollectionTypes + * readonly Unknown: "unknown"; + readonly Movies: "movies"; + readonly Tvshows: "tvshows"; + readonly Music: "music"; + readonly Musicvideos: "musicvideos"; + readonly Trailers: "trailers"; + readonly Homevideos: "homevideos"; + readonly Boxsets: "boxsets"; + readonly Books: "books"; + readonly Photos: "photos"; + readonly Livetv: "livetv"; + readonly Playlists: "playlists"; + readonly Folders: "folders"; + */ +export const colletionTypeToItemType = ( + collectionType?: CollectionType | null +): BaseItemKind | undefined => { + if (!collectionType) return undefined; + + switch (collectionType) { + case CollectionType.Movies: + return BaseItemKind.Movie; + case CollectionType.Tvshows: + return BaseItemKind.Series; + case CollectionType.Homevideos: + return BaseItemKind.Video; + case CollectionType.Musicvideos: + return BaseItemKind.MusicVideo; + case CollectionType.Books: + return BaseItemKind.Book; + case CollectionType.Playlists: + return BaseItemKind.Playlist; + case CollectionType.Folders: + return BaseItemKind.Folder; + case CollectionType.Photos: + return BaseItemKind.Photo; + case CollectionType.Trailers: + return BaseItemKind.Trailer; + case CollectionType.Playlists: + return BaseItemKind.Playlist; + } + + return undefined; +};