Add computed entry stats to collection detail page
Show movies/series/seasons/episodes counts and estimated total watch time inline — all from already-fetched data.
This commit is contained in:
1 parent
e660b1ec87
commit
1aa0a84f4d
1 file changed
+50
-4
@@ -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}
|
||||
</p>
|
||||
)}
|
||||
<div className="flex items-center gap-3">
|
||||
<p className="text-sm text-white/60">
|
||||
{entries.length} {entries.length === 1 ? "entry" : "entries"}
|
||||
</p>
|
||||
<div className="flex items-center gap-3 flex-wrap text-sm text-white/60">
|
||||
<span>
|
||||
{stats.summary} ~{stats.watchTime}
|
||||
</span>
|
||||
{collection.user_rating != null &&
|
||||
collection.user_rating > 0 && (
|
||||
<div className="flex items-center gap-1">
|
||||
|
||||
Reference in new issue
Block a user