fix: item count

This commit is contained in:
Fredrik Burmester
2025-01-03 10:12:40 +01:00
parent c9fb52086e
commit ea3cc18b3c
2 changed files with 44 additions and 6 deletions

View File

@@ -150,6 +150,8 @@ const Page = () => {
itemType = "Series"; itemType = "Series";
} else if (library.CollectionType === "boxsets") { } else if (library.CollectionType === "boxsets") {
itemType = "BoxSet"; itemType = "BoxSet";
} else if (library.CollectionType === "music") {
itemType = "MusicAlbum";
} }
const response = await getItemsApi(api).getItems({ const response = await getItemsApi(api).getItems({

View File

@@ -5,6 +5,7 @@ import { getPrimaryImageUrl } from "@/utils/jellyfin/image/getPrimaryImageUrl";
import { Ionicons } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons";
import { import {
BaseItemDto, BaseItemDto,
BaseItemKind,
CollectionType, CollectionType,
} from "@jellyfin/sdk/lib/generated-client/models"; } from "@jellyfin/sdk/lib/generated-client/models";
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api"; import { getItemsApi } from "@jellyfin/sdk/lib/utils/api";
@@ -50,18 +51,52 @@ export const LibraryItemCard: React.FC<Props> = ({ library, ...props }) => {
[library] [library]
); );
const itemType = useMemo(() => {
let _itemType: BaseItemKind | undefined;
if (library.CollectionType === "movies") {
_itemType = "Movie";
} else if (library.CollectionType === "tvshows") {
_itemType = "Series";
} else if (library.CollectionType === "boxsets") {
_itemType = "BoxSet";
} else if (library.CollectionType === "music") {
_itemType = "MusicAlbum";
}
return _itemType;
}, [library.CollectionType]);
const itemTypeName = useMemo(() => {
let nameStr: string;
if (library.CollectionType === "movies") {
nameStr = "movies";
} else if (library.CollectionType === "tvshows") {
nameStr = "series";
} else if (library.CollectionType === "boxsets") {
nameStr = "box sets";
} else if (library.CollectionType === "music") {
nameStr = "albums";
} else {
nameStr = "items";
}
return nameStr;
}, [library.CollectionType]);
const { data: itemsCount } = useQuery({ const { data: itemsCount } = useQuery({
queryKey: ["library-count", library.Id], queryKey: ["library-count", library.Id],
queryFn: async () => { queryFn: async () => {
if (!api) return null; const response = await getItemsApi(api!).getItems({
const response = await getItemsApi(api).getItems({
userId: user?.Id, userId: user?.Id,
parentId: library.Id, parentId: library.Id,
recursive: true,
limit: 0, limit: 0,
includeItemTypes: itemType ? [itemType] : undefined,
}); });
return response.data.TotalRecordCount; return response.data.TotalRecordCount;
}, },
staleTime: 1000 * 60 * 60,
}); });
if (!url) return null; if (!url) return null;
@@ -80,7 +115,7 @@ export const LibraryItemCard: React.FC<Props> = ({ library, ...props }) => {
</Text> </Text>
{settings?.libraryOptions?.showStats && ( {settings?.libraryOptions?.showStats && (
<Text className="font-bold text-xs text-neutral-500 text-start ml-auto"> <Text className="font-bold text-xs text-neutral-500 text-start ml-auto">
{itemsCount} items {itemsCount} {itemTypeName}
</Text> </Text>
)} )}
</View> </View>
@@ -109,6 +144,7 @@ export const LibraryItemCard: React.FC<Props> = ({ library, ...props }) => {
width: "100%", width: "100%",
height: "100%", height: "100%",
}} }}
cachePolicy={"memory-disk"}
/> />
<View <View
style={{ style={{
@@ -128,7 +164,7 @@ export const LibraryItemCard: React.FC<Props> = ({ library, ...props }) => {
)} )}
{settings?.libraryOptions?.showStats && ( {settings?.libraryOptions?.showStats && (
<Text className="font-bold text-xs text-start px-4"> <Text className="font-bold text-xs text-start px-4">
{itemsCount} items {itemsCount} {itemTypeName}
</Text> </Text>
)} )}
</View> </View>
@@ -145,7 +181,7 @@ export const LibraryItemCard: React.FC<Props> = ({ library, ...props }) => {
</Text> </Text>
{settings?.libraryOptions?.showStats && ( {settings?.libraryOptions?.showStats && (
<Text className="font-bold text-xs text-neutral-500 text-start px-4"> <Text className="font-bold text-xs text-neutral-500 text-start px-4">
{itemsCount} items {itemsCount} {itemTypeName}
</Text> </Text>
)} )}
</View> </View>