Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
feat(tracked-content): add per-category analytics page, fix Overview category metrics
spacesdrive54bd44518add
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b06d1f9..d815d75 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -35,6 +35,17 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).- Reddit section card removed; Reddit data fully integrated into the tab views- Accounts tab now shows all accounts including Reddit in a unified table+**Tracked Content category analytics**+- New page at `/tracked-content/category/:name` showing detailed analytics per category+- YouTube section: views, likes, comments, like-to-view ratio StatCards; top videos horizontal bar chart; full table sorted by views+- Reddit section: total score, comments, avg upvote ratio, avg score StatCards; top posts horizontal bar chart; full table sorted by score+- Category name decoded from URL param; handles mixed categories (YouTube + Reddit items in the same category)+- Overview category cards now navigate to `/tracked-content/category/:name` instead of the general Tracked Content page+- `categoryStats` in Overview now tracks `ytViews`, `ytLikes`, `ytComments`, `rdScore`, `rdComments` per platform separately; no longer mixes YouTube views and Reddit score under a single "totalScore" label+- Audience Comparison chart tooltip for categories now shows "Views + Score" instead of "Score"+- Audience chart legend updated to "Category (views + score)"+- Tracked Categories card in the Content tab now shows platform-specific metrics: YouTube views in red, Reddit score in orange+**Overview metrics fixed**- New `/api/overview` backend endpoint reads per-account analytics from Redis cache (YouTube video likes/comments, Instagram media likes/comments, Reddit account posts/score/comments)- Total Comments and Total Likes now include YouTube channel video data and Instagram media data, not just tracked contentdiff --git a/docs/architecture/frontend/FEATURES.md b/docs/architecture/frontend/FEATURES.mdindex 09abb9c..bf41da1 100644--- a/docs/architecture/frontend/FEATURES.md+++ b/docs/architecture/frontend/FEATURES.md@@ -79,7 +79,8 @@ Each page manages its own loading/data/error state. Pages do not write to `AppCo| Reddit Analytics | `/reddit/:id` | Reddit analytics for one account - karma breakdown, score timeline, post type distribution, day/hour analysis, subreddit breakdown, top posts || Reddit Posts (global) | `/reddit-posts` | Combined post explorer across all Reddit accounts with account and subreddit filters || Reddit Posts (per account) | `/reddit-posts/:id` | Searchable and sortable post list for a single Reddit account |-| Tracked Posts | `/reddit-tracked` | Monitor specific Reddit post URLs for score and comment changes; bulk category assignment; category stats shown on Overview |+| Tracked Content | `/tracked-content` | Monitor Reddit posts and YouTube videos; add by URL, assign categories, bulk edit, per-row refresh |+| Tracked Category | `/tracked-content/category/:name` | Detailed per-category analytics; YouTube section (views, likes, comments, bar chart, table) and Reddit section (score, ratio, comments, bar chart, table) rendered separately || Video Explorer | `/videos/:id` | YouTube video library with search and sort || Publish | `/publish/:id` | Publish a post to Instagram immediately || Schedule | `/schedule/:id` | View and manage the scheduled post queue |diff --git a/docs/architecture/frontend/ROUTING.md b/docs/architecture/frontend/ROUTING.mdindex 06ca3a2..3a0597f 100644--- a/docs/architecture/frontend/ROUTING.md+++ b/docs/architecture/frontend/ROUTING.md@@ -17,7 +17,9 @@ The app uses React Router v6 in `frontend/src/App.jsx`. The router uses `Browser| `/reddit/:id` | `RedditAnalytics.jsx` | `:id` = account.id for Reddit accounts || `/reddit-posts` | `RedditPostsAll.jsx` | Combined post explorer across all connected Reddit accounts || `/reddit-posts/:id` | `RedditPosts.jsx` | `:id` = account.id; filterable/sortable post explorer for one account |-| `/reddit-tracked` | `RedditTracked.jsx` | Tracked post URL monitor - paste any Reddit URL, watch score and comment count |+| `/tracked-content` | `TrackedContent.jsx` | Tracked Reddit posts and YouTube videos - add, manage, categorize, refresh |+| `/tracked-content/category/:name` | `TrackedCategory.jsx` | Per-category analytics page; `:name` is URL-encoded category label; shows YouTube and Reddit sections separately |+| `/reddit-tracked` | redirect | Redirects to `/tracked-content` || `/videos/:id` | `VideoExplorer.jsx` | `:id` = account.id for YouTube accounts || `/publish/:id` | `Publish.jsx` | `:id` = account.id for Instagram accounts || `/schedule/:id` | `Schedule.jsx` | `:id` = account.id for Instagram accounts |diff --git a/frontend/src/App.jsx b/frontend/src/App.jsxindex 567b62a..f182173 100644--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@ -22,6 +22,7 @@ const RedditAnalytics = lazy(() => import('./features/analytics/reddit/Redditconst RedditPosts = lazy(() => import('./features/analytics/reddit/RedditPosts'));const RedditPostsAll = lazy(() => import('./features/analytics/reddit/RedditPostsAll'));const TrackedContent = lazy(() => import('./features/analytics/tracked/TrackedContent'));+const TrackedCategory = lazy(() => import('./features/analytics/tracked/TrackedCategory'));const router = createBrowserRouter([{@@ -50,8 +51,9 @@ const router = createBrowserRouter([{ path: 'reddit/:id', element: <RedditAnalytics /> },{ path: 'reddit-posts', element: <RedditPostsAll /> },{ path: 'reddit-posts/:id', element: <RedditPosts /> },- { path: 'tracked-content', element: <TrackedContent /> },- { path: 'reddit-tracked', element: <Navigate to="/tracked-content" replace /> },+ { path: 'tracked-content', element: <TrackedContent /> },+ { path: 'tracked-content/category/:name', element: <TrackedCategory /> },+ { path: 'reddit-tracked', element: <Navigate to="/tracked-content" replace /> },{ path: '*', element: <Navigate to="/" replace /> },],},diff --git a/frontend/src/features/analytics/overview/Overview.jsx b/frontend/src/features/analytics/overview/Overview.jsxindex 0354213..c7fe3d7 100644--- a/frontend/src/features/analytics/overview/Overview.jsx+++ b/frontend/src/features/analytics/overview/Overview.jsx@@ -169,11 +169,30 @@ export default function Overview() {if (!withCat.length) return [];const map = {};withCat.forEach(p => {- if (!map[p.category]) map[p.category] = { category: p.category, count: 0, totalScore: 0 };- map[p.category].count++;- map[p.category].totalScore += p.contentType === 'youtube' ? (p.viewCount ?? 0) : (p.score ?? 0);+ if (!map[p.category]) {+ map[p.category] = {+ category: p.category,+ count: 0, ytCount: 0, rdCount: 0,+ ytViews: 0, ytLikes: 0, ytComments: 0,+ rdScore: 0, rdComments: 0,+ };+ }+ const c = map[p.category];+ c.count++;+ if (p.contentType === 'youtube') {+ c.ytCount++;+ c.ytViews += p.viewCount ?? 0;+ c.ytLikes += p.likeCount ?? 0;+ c.ytComments += p.commentCount ?? 0;+ } else {+ c.rdCount++;+ c.rdScore += p.score ?? 0;+ c.rdComments += p.numComments ?? 0;+ }});- return Object.values(map).sort((a, b) => b.totalScore - a.totalScore);+ return Object.values(map).sort((a, b) =>+ (b.rdScore + b.ytViews) - (a.rdScore + a.ytViews)+ );}, [trackedContent]);// ── Audience metric per account ────────────────────────────────────────────────@@ -211,7 +230,7 @@ export default function Overview() {})),...categoryStats.map(c => ({name: c.category.slice(0, 12) + (c.category.length > 12 ? '…' : ''),- value: c.totalScore,+ value: c.rdScore + c.ytViews,type: 'category',})),], [ytAccounts, igAccounts, redditAccounts, categoryStats]);@@ -225,7 +244,7 @@ export default function Overview() {})),...categoryStats.map((c, i) => ({name: c.category.slice(0, 14),- value: c.totalScore,+ value: c.rdScore + c.ytViews,color: CHART_COLORS[(accounts.length + i) % CHART_COLORS.length],})),].filter(e => e.value > 0);@@ -386,7 +405,7 @@ export default function Overview() {<YAxis tick={{ fill: 'var(--muted-foreground)', fontSize: 11 }} tickFormatter={fmtNum} axisLine={false} tickLine={false} width={48} /><ReTooltipcontentStyle={{ background: 'var(--card)', border: '1px solid var(--border)', borderRadius: 8, fontSize: 12 }}- formatter={(v, name, props) => [fmtNumFull(v), props.payload.type === 'category' ? 'Score' : 'Audience']}+ formatter={(v, name, props) => [fmtNumFull(v), props.payload.type === 'category' ? 'Views + Score' : 'Audience']}/><Areatype="monotone"@@ -418,7 +437,7 @@ export default function Overview() {ytAccounts.length ? { color: PLATFORM_COLORS.youtube, label: 'YouTube (subs)' } : null,igAccounts.length ? { color: PLATFORM_COLORS.instagram, label: 'Instagram (followers)' } : null,redditAccounts.length ? { color: PLATFORM_COLORS.reddit, label: 'Reddit (karma)' } : null,- categoryStats.length ? { color: PLATFORM_COLORS.category, label: 'Category (score)' } : null,+ categoryStats.length ? { color: PLATFORM_COLORS.category, label: 'Category (views + score)' } : null,].filter(Boolean).map(({ color, label }) => (<div key={label} className="flex items-center gap-1.5 text-xs text-muted-foreground"><span className="h-2.5 w-2.5 rounded-full flex-shrink-0" style={{ background: color }} />@@ -476,7 +495,7 @@ export default function Overview() {{categoryStats.map(stat => (<buttonkey={stat.category}- onClick={() => navigate('/tracked-content')}+ onClick={() => navigate(`/tracked-content/category/${encodeURIComponent(stat.category)}`)}className="w-full flex items-center gap-3 px-2 py-1.5 rounded-lg hover:bg-muted/60 transition-colors text-left"><span className="w-5 text-xs font-bold tabular-nums text-muted-foreground">#</span>@@ -484,9 +503,14 @@ export default function Overview() {<Tag className="h-3.5 w-3.5 text-purple-500" /></div><span className="flex-1 text-sm font-medium truncate">{stat.category}</span>- <Badge variant="outline" className="text-[10px] border-purple-200 bg-purple-50 text-purple-700 dark:border-purple-900 dark:bg-purple-950 dark:text-purple-400">- Category- </Badge>+ <div className="text-right">+ {stat.ytCount > 0 && (+ <p className="text-[10px] text-red-500 tabular-nums leading-none">{fmtNum(stat.ytViews)} views</p>+ )}+ {stat.rdCount > 0 && (+ <p className="text-[10px] text-orange-500 tabular-nums leading-none mt-0.5">{fmtNum(stat.rdScore)} score</p>+ )}+ </div></button>))}</div>@@ -605,29 +629,37 @@ export default function Overview() {</p>) : (<div className="space-y-1">- {categoryStats.map(stat => {- const ytInCat = trackedStats.ytItems.filter(p => p.category === stat.category).length;- const rdInCat = trackedStats.rdItems.filter(p => p.category === stat.category).length;- return (- <button- key={stat.category}- onClick={() => navigate('/tracked-content')}- className="w-full flex items-center gap-2.5 px-2 py-2 rounded-lg hover:bg-muted/60 transition-colors text-left"- >- <div className="h-7 w-7 rounded-md bg-purple-500/10 flex items-center justify-center flex-shrink-0">- <Tag className="h-3.5 w-3.5 text-purple-500" />- </div>- <div className="flex-1 min-w-0">- <p className="text-sm font-medium truncate">{stat.category}</p>- <p className="text-xs text-muted-foreground">- {stat.count} item{stat.count !== 1 ? 's' : ''}- {ytInCat > 0 && rdInCat > 0 ? ` · ${ytInCat} YT · ${rdInCat} Reddit` : ''}+ {categoryStats.map(stat => (+ <button+ key={stat.category}+ onClick={() => navigate(`/tracked-content/category/${encodeURIComponent(stat.category)}`)}+ className="w-full flex items-center gap-2.5 px-2 py-2 rounded-lg hover:bg-muted/60 transition-colors text-left"+ >+ <div className="h-7 w-7 rounded-md bg-purple-500/10 flex items-center justify-center flex-shrink-0">+ <Tag className="h-3.5 w-3.5 text-purple-500" />+ </div>+ <div className="flex-1 min-w-0">+ <p className="text-sm font-medium truncate">{stat.category}</p>+ <p className="text-xs text-muted-foreground">+ {stat.count} item{stat.count !== 1 ? 's' : ''}+ {stat.ytCount > 0 && ` · ${stat.ytCount} YouTube`}+ {stat.rdCount > 0 && ` · ${stat.rdCount} Reddit`}+ </p>+ </div>+ <div className="text-right">+ {stat.ytCount > 0 && (+ <p className="text-xs font-semibold tabular-nums text-red-500 leading-none">+ {fmtNum(stat.ytViews)} views</p>- </div>- <span className="text-sm font-semibold tabular-nums text-purple-500">{fmtNum(stat.totalScore)}</span>- </button>- );- })}+ )}+ {stat.rdCount > 0 && (+ <p className="text-xs font-semibold tabular-nums text-orange-500 leading-none mt-0.5">+ {fmtNum(stat.rdScore)} score+ </p>+ )}+ </div>+ </button>+ ))}</div>)}</MainCard>diff --git a/frontend/src/features/analytics/tracked/TrackedCategory.jsx b/frontend/src/features/analytics/tracked/TrackedCategory.jsxnew file mode 100644index 0000000..830b1e5--- /dev/null+++ b/frontend/src/features/analytics/tracked/TrackedCategory.jsx@@ -0,0 +1,549 @@+import React, { useState, useEffect, useMemo } from 'react';+import { useParams, useNavigate } from 'react-router-dom';+import { Button } from '@/components/ui/button';+import { Badge } from '@/components/ui/badge';+import { Separator } from '@/components/ui/separator';+import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';+import { Skeleton } from '@/components/ui/skeleton';+import {+ BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as ReTooltip,+ ResponsiveContainer, Cell,+} from 'recharts';+import StatCard from '../../../components/ui/StatCard';+import MainCard from '../../../components/MainCard';+import { useAppContext } from '../../../context/AppContext';+import { api } from '../../../services/api';+import { fmtNum, fmtNumFull, fmtDate } from '../../../utils/formatters';+import {+ ArrowLeft, CirclePlay, Flame, ExternalLink, Eye,+ ThumbsUp, MessageSquare, Tag, TrendingUp, BarChart2,+} from 'lucide-react';++function ContentTypeBadge({ type }) {+ if (type === 'youtube') {+ return (+ <Badge variant="outline" className="text-[10px] border-red-200 bg-red-50 text-red-700 dark:border-red-900 dark:bg-red-950 dark:text-red-400 gap-1 px-1.5 py-0">+ <CirclePlay className="h-2.5 w-2.5" />+ YouTube+ </Badge>+ );+ }+ return (+ <Badge variant="outline" className="text-[10px] border-orange-200 bg-orange-50 text-orange-700 dark:border-orange-900 dark:bg-orange-950 dark:text-orange-400 gap-1 px-1.5 py-0">+ <Flame className="h-2.5 w-2.5" />+ </Badge>+ );+}++export default function TrackedCategory() {+ const { name } = useParams();+ const navigate = useNavigate();+ const { showToast } = useAppContext();++ const categoryName = decodeURIComponent(name || '');++ const [items, setItems] = useState([]);+ const [loading, setLoading] = useState(true);++ useEffect(() => {+ api.getTrackedContent()+ .then(data => {+ const all = Array.isArray(data) ? data : [];+ setItems(all.filter(p => p.category === categoryName));+ })+ .catch(err => showToast(err.message, 'error'))+ .finally(() => setLoading(false));+ }, [categoryName, showToast]);++ const ytItems = useMemo(() => items.filter(p => p.contentType === 'youtube'), [items]);+ const rdItems = useMemo(() => items.filter(p => (p.contentType || 'reddit') === 'reddit'), [items]);++ const ytStats = useMemo(() => {+ const count = ytItems.length;+ const views = ytItems.reduce((s, p) => s + (p.viewCount ?? 0), 0);+ const likes = ytItems.reduce((s, p) => s + (p.likeCount ?? 0), 0);+ const comments = ytItems.reduce((s, p) => s + (p.commentCount ?? 0), 0);+ return {+ count,+ views,+ likes,+ comments,+ avgViews: count ? Math.round(views / count) : 0,+ avgLikes: count ? Math.round(likes / count) : 0,+ likeRatio: views > 0 ? ((likes / views) * 100).toFixed(2) : '0',+ };+ }, [ytItems]);++ const rdStats = useMemo(() => {+ const count = rdItems.length;+ const score = rdItems.reduce((s, p) => s + (p.score ?? 0), 0);+ const comments = rdItems.reduce((s, p) => s + (p.numComments ?? 0), 0);+ const ratioSum = rdItems.reduce((s, p) => s + (p.upvoteRatio ?? 0), 0);+ return {+ count,+ score,+ comments,+ avgScore: count ? Math.round(score / count) : 0,+ avgRatio: count ? ratioSum / count : 0,+ };+ }, [rdItems]);++ const ytChartData = useMemo(() =>+ [...ytItems]+ .sort((a, b) => (b.viewCount ?? 0) - (a.viewCount ?? 0))+ .slice(0, 10)+ .map(p => ({+ name: (p.title || p.url || '').slice(0, 30),+ views: p.viewCount ?? 0,+ })),+ [ytItems]+ );++ const rdChartData = useMemo(() =>+ [...rdItems]+ .sort((a, b) => (b.score ?? 0) - (a.score ?? 0))+ .slice(0, 10)+ .map(p => ({+ name: (p.title || p.url || '').slice(0, 30),+ score: p.score ?? 0,+ })),+ [rdItems]+ );++ const medalColor = (i) =>+ i === 0 ? 'text-yellow-500' : i === 1 ? 'text-slate-400' : i === 2 ? 'text-orange-400' : 'text-muted-foreground';++ if (loading) {+ return (+ <div className="space-y-6">+ <div className="flex items-center gap-3">+ <Skeleton className="h-9 w-9 rounded-md" />+ <div className="space-y-1">+ <Skeleton className="h-7 w-48" />+ <Skeleton className="h-4 w-32" />+ </div>+ </div>+ <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">+ {[0, 1, 2, 3].map(i => <Skeleton key={i} className="h-28" />)}+ </div>+ <Skeleton className="h-48" />+ <Skeleton className="h-64" />+ </div>+ );+ }++ if (items.length === 0) {+ return (+ <div className="space-y-6">+ <div className="flex items-center gap-3">+ <Button variant="ghost" size="icon" className="shrink-0" onClick={() => navigate('/tracked-content')}>+ <ArrowLeft className="h-4 w-4" />+ </Button>+ <div>+ <h1 className="text-2xl font-bold tracking-tight">{categoryName}</h1>+ <p className="text-sm text-muted-foreground mt-0.5">No items in this category</p>+ </div>+ </div>+ <MainCard>+ <div className="flex flex-col items-center text-center py-12 gap-3">+ <div className="h-14 w-14 rounded-full bg-purple-500/10 flex items-center justify-center">+ <Tag className="h-7 w-7 text-purple-500" />+ </div>+ <div>+ <p className="text-sm font-semibold">No tracked items in "{categoryName}"</p>+ <p className="text-xs text-muted-foreground mt-1">+ Add content and assign this category in Tracked Content to see analytics here+ </p>+ </div>+ <Button size="sm" onClick={() => navigate('/tracked-content')}>Manage Tracked Content</Button>+ </div>+ </MainCard>+ </div>+ );+ }++ return (+ <div className="space-y-6">+ {/* Header */}+ <div className="flex items-start gap-3">+ <Button variant="ghost" size="icon" className="shrink-0 mt-0.5" onClick={() => navigate('/tracked-content')}>+ <ArrowLeft className="h-4 w-4" />+ </Button>+ <div className="flex-1 min-w-0">+ <div className="flex items-center gap-2 flex-wrap">+ <h1 className="text-2xl font-bold tracking-tight">{categoryName}</h1>+ <Badge variant="outline" className="text-xs border-purple-200 bg-purple-50 text-purple-700 dark:border-purple-900 dark:bg-purple-950 dark:text-purple-400">+ <Tag className="h-3 w-3 mr-1" />+ Category+ </Badge>+ </div>+ <p className="text-sm text-muted-foreground mt-0.5">+ {items.length} item{items.length !== 1 ? 's' : ''}+ {ytItems.length > 0 && ` · ${ytItems.length} YouTube`}+ {rdItems.length > 0 && ` · ${rdItems.length} Reddit`}+ </p>+ </div>+ <Button size="sm" variant="outline" onClick={() => navigate('/tracked-content')} className="shrink-0">+ Manage Content+ </Button>+ </div>++ {/* Summary StatCards */}+ <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">+ <StatCard+ icon={<Tag />}+ label="Total Items"+ value={items.length}+ subtitle={[+ ytItems.length > 0 ? `${ytItems.length} YouTube` : null,+ rdItems.length > 0 ? `${rdItems.length} Reddit` : null,+ ].filter(Boolean).join(' · ')}+ gradient="purple"+ />+ <StatCard+ icon={<Eye />}+ label="Total Views"+ value={ytItems.length > 0 ? fmtNum(ytStats.views) : '-'}+ subtitle={ytItems.length > 0 ? `avg ${fmtNum(ytStats.avgViews)} per video` : 'no YouTube videos'}+ gradient="red"+ />+ <StatCard+ icon={<Flame />}+ label="Total Score"+ value={rdItems.length > 0 ? fmtNum(rdStats.score) : '-'}+ subtitle={rdItems.length > 0 ? `avg ${fmtNum(rdStats.avgScore)} per post` : 'no Reddit posts'}+ gradient="orange"+ />+ <StatCard+ icon={<MessageSquare />}+ label="Total Comments"+ value={fmtNum(ytStats.comments + rdStats.comments)}+ subtitle={[+ ytItems.length > 0 ? 'YouTube' : null,+ rdItems.length > 0 ? 'Reddit' : null,+ ].filter(Boolean).join(' + ') + ' combined'}+ gradient="blue"+ />+ </div>++ {/* YouTube section */}+ {ytItems.length > 0 && (+ <>+ <div className="flex items-center gap-3 pt-2">+ <CirclePlay className="h-5 w-5 text-red-500 shrink-0" />+ <h2 className="text-base font-semibold">YouTube Videos</h2>+ <Separator className="flex-1" />+ <span className="text-sm text-muted-foreground shrink-0">+ {ytItems.length} video{ytItems.length !== 1 ? 's' : ''}+ </span>+ </div>++ <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">+ <StatCard+ icon={<Eye />}+ label="Total Views"+ value={fmtNum(ytStats.views)}+ subtitle={`avg ${fmtNum(ytStats.avgViews)} per video`}+ gradient="red"+ />+ <StatCard+ icon={<ThumbsUp />}+ label="Total Likes"+ value={fmtNum(ytStats.likes)}+ subtitle={`avg ${fmtNum(ytStats.avgLikes)} per video`}+ gradient="orange"+ />+ <StatCard+ icon={<MessageSquare />}+ label="Total Comments"+ value={fmtNum(ytStats.comments)}+ subtitle="across all videos"+ gradient="blue"+ />+ <StatCard+ icon={<TrendingUp />}+ label="Like-to-View Ratio"+ value={ytStats.likeRatio + '%'}+ subtitle="likes as share of views"+ gradient="purple"+ />+ </div>++ {ytChartData.length > 1 && (+ <MainCard title="Top Videos by Views">+ <ResponsiveContainer+ width="100%"+ height={Math.max(ytChartData.length * 44, 200)}+ debounce={200}+ >+ <BarChart+ data={ytChartData}+ layout="vertical"+ margin={{ top: 0, right: 56, left: 0, bottom: 0 }}+ >+ <CartesianGrid strokeDasharray="3 3" stroke="var(--border)" horizontal={false} />+ <XAxis+ type="number"+ tick={{ fill: 'var(--muted-foreground)', fontSize: 11 }}+ tickFormatter={fmtNum}+ axisLine={false}+ tickLine={false}+ />+ <YAxis+ type="category"+ dataKey="name"+ width={196}+ tick={{ fill: 'var(--muted-foreground)', fontSize: 11 }}+ axisLine={false}+ tickLine={false}+ />+ <ReTooltip+ contentStyle={{ background: 'var(--card)', border: '1px solid var(--border)', borderRadius: 8, fontSize: 12 }}+ formatter={(v) => [fmtNumFull(v), 'Views']}+ />+ <Bar dataKey="views" radius={[0, 4, 4, 0]} maxBarSize={22}>+ {ytChartData.map((_, i) => (+ <Cell key={i} fill="#ef4444" fillOpacity={Math.max(1 - i * 0.07, 0.4)} />+ ))}+ </Bar>+ </BarChart>+ </ResponsiveContainer>+ </MainCard>+ )}++ <MainCard content={false}>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead className="w-8">#</TableHead>+ <TableHead>Video</TableHead>+ <TableHead className="text-right w-32">Views</TableHead>+ <TableHead className="text-right w-24">Likes</TableHead>+ <TableHead className="text-right w-24">Comments</TableHead>+ <TableHead className="text-right w-28">Fetched</TableHead>+ <TableHead className="w-10" />+ </TableRow>+ </TableHeader>+ <TableBody>+ {[...ytItems]+ .sort((a, b) => (b.viewCount ?? 0) - (a.viewCount ?? 0))+ .map((item, i) => (+ <TableRow key={item.id}>+ <TableCell>+ <span className={`text-xs font-bold tabular-nums ${medalColor(i)}`}>{i + 1}</span>+ </TableCell>+ <TableCell>+ <div className="flex items-start gap-2.5">+ {item.thumbnail ? (+ <img+ src={item.thumbnail}+ alt=""+ className="h-10 w-16 rounded object-cover flex-shrink-0 mt-0.5"+ />+ ) : (+ <div className="h-10 w-16 rounded bg-red-500/10 flex items-center justify-center flex-shrink-0 mt-0.5">+ <CirclePlay className="h-4 w-4 text-red-500" />+ </div>+ )}+ <div className="min-w-0">+ <p className="text-sm font-medium leading-snug line-clamp-2">+ {item.title || item.url}+ </p>+ <div className="flex items-center gap-2 mt-0.5 flex-wrap">+ {item.channelTitle && (+ <span className="text-xs text-muted-foreground">{item.channelTitle}</span>+ )}+ {item.isShort && (+ <Badge variant="outline" className="text-[10px] px-1.5 py-0">Short</Badge>+ )}+ {item.label && (+ <span className="text-xs text-muted-foreground italic">{item.label}</span>+ )}+ </div>+ </div>+ </div>+ </TableCell>+ <TableCell className="text-right">+ <p className="text-sm font-bold tabular-nums">{fmtNum(item.viewCount ?? 0)}</p>+ <p className="text-xs text-muted-foreground">{fmtNumFull(item.viewCount ?? 0)}</p>+ </TableCell>+ <TableCell className="text-right text-sm font-semibold tabular-nums text-red-500">+ {fmtNum(item.likeCount ?? 0)}+ </TableCell>+ <TableCell className="text-right text-sm tabular-nums text-muted-foreground">+ {fmtNum(item.commentCount ?? 0)}+ </TableCell>+ <TableCell className="text-right text-xs text-muted-foreground">+ {item.lastFetchedAt ? fmtDate(item.lastFetchedAt) : '-'}+ </TableCell>+ <TableCell>+ <a href={item.url} target="_blank" rel="noopener noreferrer">+ <Button variant="ghost" size="icon" className="size-7">+ <ExternalLink className="h-3.5 w-3.5" />+ </Button>+ </a>+ </TableCell>+ </TableRow>+ ))}+ </TableBody>+ </Table>+ </MainCard>+ </>+ )}++ {/* Reddit section */}+ {rdItems.length > 0 && (+ <>+ <div className="flex items-center gap-3 pt-2">+ <Flame className="h-5 w-5 text-orange-500 shrink-0" />+ <h2 className="text-base font-semibold">Reddit Posts</h2>+ <Separator className="flex-1" />+ <span className="text-sm text-muted-foreground shrink-0">+ {rdItems.length} post{rdItems.length !== 1 ? 's' : ''}+ </span>+ </div>++ <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">+ <StatCard+ icon={<Flame />}+ label="Total Score"+ value={fmtNum(rdStats.score)}+ subtitle={`avg ${fmtNum(rdStats.avgScore)} per post`}+ gradient="orange"+ />+ <StatCard+ icon={<MessageSquare />}+ label="Total Comments"+ value={fmtNum(rdStats.comments)}+ subtitle="across all posts"+ gradient="blue"+ />+ <StatCard+ icon={<TrendingUp />}+ label="Avg Upvote Ratio"+ value={rdStats.avgRatio > 0 ? Math.round(rdStats.avgRatio * 100) + '%' : '-'}+ subtitle="upvotes as share of total votes"+ gradient="green"+ />+ <StatCard+ icon={<BarChart2 />}+ label="Avg Score"+ value={fmtNum(rdStats.avgScore)}+ subtitle={`${rdItems.length} post${rdItems.length !== 1 ? 's' : ''} tracked`}+ gradient="purple"+ />+ </div>++ {rdChartData.length > 1 && (+ <MainCard title="Top Posts by Score">+ <ResponsiveContainer+ width="100%"+ height={Math.max(rdChartData.length * 44, 200)}+ debounce={200}+ >+ <BarChart+ data={rdChartData}+ layout="vertical"+ margin={{ top: 0, right: 56, left: 0, bottom: 0 }}+ >+ <CartesianGrid strokeDasharray="3 3" stroke="var(--border)" horizontal={false} />+ <XAxis+ type="number"+ tick={{ fill: 'var(--muted-foreground)', fontSize: 11 }}+ tickFormatter={fmtNum}+ axisLine={false}+ tickLine={false}+ />+ <YAxis+ type="category"+ dataKey="name"+ width={196}+ tick={{ fill: 'var(--muted-foreground)', fontSize: 11 }}+ axisLine={false}+ tickLine={false}+ />+ <ReTooltip+ contentStyle={{ background: 'var(--card)', border: '1px solid var(--border)', borderRadius: 8, fontSize: 12 }}+ formatter={(v) => [fmtNumFull(v), 'Score']}+ />+ <Bar dataKey="score" radius={[0, 4, 4, 0]} maxBarSize={22}>+ {rdChartData.map((_, i) => (+ <Cell key={i} fill="#f97316" fillOpacity={Math.max(1 - i * 0.07, 0.4)} />+ ))}+ </Bar>+ </BarChart>+ </ResponsiveContainer>+ </MainCard>+ )}++ <MainCard content={false}>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead className="w-8">#</TableHead>+ <TableHead>Post</TableHead>+ <TableHead className="text-right w-28">Score</TableHead>+ <TableHead className="text-right w-20">Upvote %</TableHead>+ <TableHead className="text-right w-24">Comments</TableHead>+ <TableHead className="text-right w-28">Fetched</TableHead>+ <TableHead className="w-10" />+ </TableRow>+ </TableHeader>+ <TableBody>+ {[...rdItems]+ .sort((a, b) => (b.score ?? 0) - (a.score ?? 0))+ .map((item, i) => (+ <TableRow key={item.id}>+ <TableCell>+ <span className={`text-xs font-bold tabular-nums ${medalColor(i)}`}>{i + 1}</span>+ </TableCell>+ <TableCell>+ <div className="min-w-0">+ <p className="text-sm font-medium leading-snug line-clamp-2">+ {item.title || item.url}+ </p>+ <div className="flex items-center gap-2 mt-0.5 flex-wrap">+ {item.subredditPrefixed && (+ <span className="text-xs text-muted-foreground">{item.subredditPrefixed}</span>+ )}+ {item.label && (+ <span className="text-xs text-muted-foreground italic">{item.label}</span>+ )}+ </div>+ </div>+ </TableCell>+ <TableCell className="text-right">+ <p className="text-sm font-bold tabular-nums text-orange-500">+ {fmtNum(item.score ?? 0)}+ </p>+ <p className="text-xs text-muted-foreground">{fmtNumFull(item.score ?? 0)}</p>+ </TableCell>+ <TableCell className="text-right text-sm tabular-nums text-muted-foreground">+ {(item.upvoteRatio != null && (item.score ?? 0) >= 10)+ ? Math.round(item.upvoteRatio * 100) + '%'+ : '-'}+ </TableCell>+ <TableCell className="text-right text-sm tabular-nums text-muted-foreground">+ {fmtNum(item.numComments ?? 0)}+ </TableCell>+ <TableCell className="text-right text-xs text-muted-foreground">+ {item.lastFetchedAt ? fmtDate(item.lastFetchedAt) : '-'}+ </TableCell>+ <TableCell>+ <a href={item.permalink || item.url} target="_blank" rel="noopener noreferrer">+ <Button variant="ghost" size="icon" className="size-7">+ <ExternalLink className="h-3.5 w-3.5" />+ </Button>+ </a>+ </TableCell>+ </TableRow>+ ))}+ </TableBody>+ </Table>+ </MainCard>+ </>+ )}+ </div>+ );+}