mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
## Note this is early stages of said integration. Things will change! series and season working - added jellyseerr git submodule - augmentations - working jellyseerr search integration - working jellyseerr requests & updated interceptors to persist cookies from every response
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { Text } from "@/components/common/Text";
|
|
import { useDownload } from "@/providers/DownloadProvider";
|
|
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
|
import React, { useEffect, useMemo, useState } from "react";
|
|
import { TextProps } from "react-native";
|
|
|
|
interface DownloadSizeProps extends TextProps {
|
|
items: BaseItemDto[];
|
|
}
|
|
|
|
export const DownloadSize: React.FC<DownloadSizeProps> = ({
|
|
items,
|
|
...props
|
|
}) => {
|
|
const { downloadedFiles, getDownloadedItemSize } = useDownload();
|
|
const [size, setSize] = useState<string | undefined>();
|
|
|
|
const itemIds = useMemo(() => items.map((i) => i.Id), [items]);
|
|
|
|
useEffect(() => {
|
|
if (!downloadedFiles) return;
|
|
|
|
let s = 0;
|
|
|
|
for (const item of items) {
|
|
if (!item.Id) continue;
|
|
const size = getDownloadedItemSize(item.Id);
|
|
if (size) {
|
|
s += size;
|
|
}
|
|
}
|
|
setSize(s.bytesToReadable());
|
|
}, [itemIds]);
|
|
|
|
const sizeText = useMemo(() => {
|
|
if (!size) return "...";
|
|
return size;
|
|
}, [size]);
|
|
|
|
return (
|
|
<>
|
|
<Text className="text-xs text-neutral-500" {...props}>
|
|
{sizeText}
|
|
</Text>
|
|
</>
|
|
);
|
|
};
|