From 1aa0a84f4d32b2ec285f1d3b7befb1e7efd45257 Mon Sep 17 00:00:00 2001
From: X4Lo
Date: Wed, 1 Jul 2026 00:00:13 +0100
Subject: [PATCH] Add computed entry stats to collection detail page
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Show movies/series/seasons/episodes counts and estimated
total watch time inline — all from already-fetched data.
---
.../src/pages/CollectionDetailsPage.tsx | 54 +++++++++++++++++--
1 file changed, 50 insertions(+), 4 deletions(-)
diff --git a/react_frontend/src/pages/CollectionDetailsPage.tsx b/react_frontend/src/pages/CollectionDetailsPage.tsx
index 60a6cbf..58ac08b 100644
--- a/react_frontend/src/pages/CollectionDetailsPage.tsx
+++ b/react_frontend/src/pages/CollectionDetailsPage.tsx
@@ -125,6 +125,52 @@ export function CollectionDetailsPage() {
}
};
+ // ── Computed stats (from already-fetched data) ──
+ const stats = useMemo(() => {
+ const movies = entries.filter((e) => !e.is_tvseries);
+ const tvEntries = entries.filter((e) => e.is_tvseries);
+ const seasonCount = tvEntries.reduce(
+ (sum, e) => sum + (e.seasons?.length || 0),
+ 0,
+ );
+ const episodeCount = tvEntries.reduce(
+ (sum, e) =>
+ sum +
+ (e.seasons?.reduce((s, season) => s + (season.episode_count || 0), 0) ||
+ 0),
+ 0,
+ );
+ const typeParts: string[] = [];
+ if (movies.length > 0) typeParts.push(`${movies.length} movies`);
+ if (tvEntries.length > 0) typeParts.push(`${tvEntries.length} series`);
+ const typeStr = typeParts.join(" & ");
+
+ const subParts: string[] = [];
+ if (seasonCount > 0) subParts.push(`${seasonCount} seasons`);
+ if (episodeCount > 0) subParts.push(`${episodeCount} episodes`);
+ const subStr = subParts.length > 0 ? ` (${subParts.join("/")})` : "";
+
+ const summary = `${entries.length} entries - ${typeStr}${subStr}`;
+
+ const watchMinutes = entries.reduce((sum, e) => {
+ if (e.is_tvseries) {
+ const eps =
+ e.seasons?.reduce(
+ (s, season) => s + (season.episode_count || 0),
+ 0,
+ ) || 0;
+ const epRuntime = e.runtime || 42;
+ return sum + eps * epRuntime;
+ }
+ return sum + (e.runtime || 0);
+ }, 0);
+ const hours = Math.floor(watchMinutes / 60);
+ const mins = watchMinutes % 60;
+ const watchTime = hours > 0 ? `${hours}h ${mins}m` : `${mins}m`;
+
+ return { summary, watchTime };
+ }, [entries]);
+
// Handle error redirect in useEffect (not during render)
useEffect(() => {
if (!isLoading && (isError || (!collection && !isLoading))) {
@@ -221,10 +267,10 @@ export function CollectionDetailsPage() {
{collection.description}
)}
-
-
- {entries.length} {entries.length === 1 ? "entry" : "entries"}
-
+
+
+ {stats.summary} ~{stats.watchTime}
+
{collection.user_rating != null &&
collection.user_rating > 0 && (