mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-16 08:08:18 +00:00
Co-authored-by: lostb1t <coding-mosses0z@icloud.com> Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com> Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com> Co-authored-by: Gauvino <uruknarb20@gmail.com> Co-authored-by: storm1er <le.storm1er@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Chris <182387676+whoopsi-daisy@users.noreply.github.com> Co-authored-by: arch-fan <55891793+arch-fan@users.noreply.github.com> Co-authored-by: Alex Kim <alexkim@Alexs-MacBook-Pro.local>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
|
import type React from "react";
|
|
import { useEffect, useMemo, useState } from "react";
|
|
import type { TextProps } from "react-native";
|
|
import { Text } from "@/components/common/Text";
|
|
import { useDownload } from "@/providers/DownloadProvider";
|
|
|
|
interface DownloadSizeProps extends TextProps {
|
|
items: BaseItemDto[];
|
|
}
|
|
|
|
export const DownloadSize: React.FC<DownloadSizeProps> = ({
|
|
items,
|
|
...props
|
|
}) => {
|
|
const { getDownloadedItemSize, getDownloadedItems } = useDownload();
|
|
const downloadedFiles = getDownloadedItems();
|
|
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>
|
|
);
|
|
};
|