diff --git a/app/(auth)/(tabs)/(home,libraries,search)/series/[id].tsx b/app/(auth)/(tabs)/(home,libraries,search)/series/[id].tsx
index 2b0df7da..ecee672b 100644
--- a/app/(auth)/(tabs)/(home,libraries,search)/series/[id].tsx
+++ b/app/(auth)/(tabs)/(home,libraries,search)/series/[id].tsx
@@ -82,7 +82,6 @@ const page: React.FC = () => {
(
diff --git a/components/DownloadItem.tsx b/components/DownloadItem.tsx
index bde17688..fb479260 100644
--- a/components/DownloadItem.tsx
+++ b/components/DownloadItem.tsx
@@ -90,18 +90,19 @@ export const DownloadItems: React.FC = ({
bottomSheetModalRef.current?.dismiss();
}, []);
- // region computed
const itemIds = useMemo(() => items.map((i) => i.Id), [items]);
- const pendingItems = useMemo(
+
+ // Get a list of all items that are not downloaded - based on the items passed in as props
+ const itemsNotDownloaded = useMemo(
() =>
items.filter((i) => !downloadedFiles?.some((f) => f.item.Id === i.Id)),
[items, downloadedFiles]
);
- const isDownloaded = useMemo(() => {
- if (!downloadedFiles) return false;
- return pendingItems.length == 0;
- }, [downloadedFiles, pendingItems]);
+ const allItemsDownloaded = useMemo(() => {
+ if (items.length === 0) return false;
+ return itemsNotDownloaded.length === 0;
+ }, [items, itemsNotDownloaded]);
const itemsProcesses = useMemo(
() => processes?.filter((p) => itemIds.includes(p.item.Id)),
[processes, itemIds]
@@ -120,10 +121,10 @@ export const DownloadItems: React.FC = ({
const itemsQueued = useMemo(() => {
return (
- pendingItems.length > 0 &&
- pendingItems.every((p) => queue.some((q) => p.Id == q.item.Id))
+ itemsNotDownloaded.length > 0 &&
+ itemsNotDownloaded.every((p) => queue.some((q) => p.Id == q.item.Id))
);
- }, [queue, pendingItems]);
+ }, [queue, itemsNotDownloaded]);
// endregion computed
// region helper functions
@@ -145,17 +146,17 @@ export const DownloadItems: React.FC = ({
const acceptDownloadOptions = useCallback(() => {
if (userCanDownload === true) {
- if (pendingItems.some((i) => !i.Id)) {
+ if (itemsNotDownloaded.some((i) => !i.Id)) {
throw new Error("No item id");
}
closeModal();
- if (usingOptimizedServer) initiateDownload(...pendingItems);
+ if (usingOptimizedServer) initiateDownload(...itemsNotDownloaded);
else {
queueActions.enqueue(
queue,
setQueue,
- ...pendingItems.map((item) => ({
+ ...itemsNotDownloaded.map((item) => ({
id: item.Id!,
execute: async () => await initiateDownload(item),
item,
@@ -168,7 +169,7 @@ export const DownloadItems: React.FC = ({
}, [
queue,
setQueue,
- pendingItems,
+ itemsNotDownloaded,
usingOptimizedServer,
userCanDownload,
@@ -188,7 +189,7 @@ export const DownloadItems: React.FC = ({
!api ||
!user?.Id ||
items.some((p) => !p.Id) ||
- (pendingItems.length === 1 && !selectedMediaSource?.Id)
+ (itemsNotDownloaded.length === 1 && !selectedMediaSource?.Id)
) {
throw new Error(
"DownloadItem ~ initiateDownload: No api or user or item"
@@ -199,7 +200,7 @@ export const DownloadItems: React.FC = ({
let subtitleIndex: number | undefined = selectedSubtitleStream;
for (const item of items) {
- if (pendingItems.length > 1) {
+ if (itemsNotDownloaded.length > 1) {
({ mediaSource, audioIndex, subtitleIndex } = getDefaultPlaySettings(
item,
settings!
@@ -242,7 +243,7 @@ export const DownloadItems: React.FC = ({
[
api,
user?.Id,
- pendingItems,
+ itemsNotDownloaded,
selectedMediaSource,
selectedAudioStream,
selectedSubtitleStream,
@@ -270,7 +271,7 @@ export const DownloadItems: React.FC = ({
useFocusEffect(
useCallback(() => {
if (!settings) return;
- if (pendingItems.length !== 1) return;
+ if (itemsNotDownloaded.length !== 1) return;
const { bitrate, mediaSource, audioIndex, subtitleIndex } =
getDefaultPlaySettings(items[0], settings);
@@ -279,7 +280,7 @@ export const DownloadItems: React.FC = ({
setSelectedAudioStream(audioIndex ?? 0);
setSelectedSubtitleStream(subtitleIndex ?? -1);
setMaxBitrate(bitrate);
- }, [items, pendingItems, settings])
+ }, [items, itemsNotDownloaded, settings])
);
return (
@@ -307,7 +308,7 @@ export const DownloadItems: React.FC = ({
- ) : isDownloaded ? (
+ ) : allItemsDownloaded ? (
{DownloadedIconComponent()}
@@ -334,7 +335,9 @@ export const DownloadItems: React.FC = ({
{title}
- {subtitle}
+
+ {subtitle || `Download ${itemsNotDownloaded.length} items`}
+
= ({
onChange={setMaxBitrate}
selected={maxBitrate}
/>
- {pendingItems.length === 1 && (
+ {itemsNotDownloaded.length === 1 && (
<>
= ({ item, initialSeasonIndex }) => {
/>
(
)}
DownloadedIconComponent={() => (
-
+
)}
/>