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(frontend)!: show only YouTube and Instagram on the Overview
spacesdrive3ba79208f46c
diff --git a/frontend/src/features/analytics/overview/AudienceTab.tsx b/frontend/src/features/analytics/overview/AudienceTab.tsxindex 1c91691..510eebc 100644--- a/frontend/src/features/analytics/overview/AudienceTab.tsx+++ b/frontend/src/features/analytics/overview/AudienceTab.tsx@@ -1,12 +1,10 @@import { Users } from 'lucide-react';-import { Badge } from '@/components/ui/badge';import SurfaceBox from '@/components/SurfaceBox';import { EmptyState } from '@/components/StateViews';import { PlatformBadge } from '@/components/platform';import { platformOf } from '@/lib/accounts';import AudienceChart from './AudienceChart';import AccountRankRow from './AccountRankRow';-import CategoryRow from './CategoryRow';import type { OverviewStats } from './useOverviewStats';export interface AudienceTabProps {@@ -17,7 +15,7 @@ export default function AudienceTab({ stats }: AudienceTabProps) {const audienceData = stats.charts.audience;return (<>- <SurfaceBox title="Audience by account" subheader="Subscribers, followers and karma, plus karma earned by each tracked category">+ <SurfaceBox title="Audience by account" subheader="Subscribers for each YouTube channel and followers for each Instagram account">{audienceData.length === 0 ? (<EmptyState compact icon={<Users />} title="No audience data yet" description="Refresh your accounts to load subscriber and follower counts." />) : (@@ -30,9 +28,6 @@ export default function AudienceTab({ stats }: AudienceTabProps) {{stats.byAudience.map((account, i) => (<AccountRankRow key={account.id} account={account} rank={i + 1} trailing={<PlatformBadge platform={platformOf(account)} />} />))}- {stats.categoryStats.map(stat => (- <CategoryRow key={stat.category} stat={stat} trailing={<Badge variant="outline">Category</Badge>} />- ))}</div></SurfaceBox></>diff --git a/frontend/src/features/analytics/overview/CommentsTab.tsx b/frontend/src/features/analytics/overview/CommentsTab.tsxindex adb3392..f56fc06 100644--- a/frontend/src/features/analytics/overview/CommentsTab.tsx+++ b/frontend/src/features/analytics/overview/CommentsTab.tsx@@ -12,21 +12,21 @@ import { CATEGORY_SERIES } from './overviewCharts.ts';import { pluralWord } from './overviewLabels.ts';import type { OverviewStats } from './useOverviewStats';-const { comments: Comments, videos: Videos, redditPosts: Reddit, median: PerItem } = METRIC_ICONS;+const { comments: Comments, videos: Videos, instagram: Instagram, median: PerItem } = METRIC_ICONS;export interface CommentsTabProps {stats: OverviewStats;}export default function CommentsTab({ stats }: CommentsTabProps) {- const { summary, charts } = stats;+ const { cacheTotals, summary, charts } = stats;const { totalComments, totalContent } = summary;return (<><div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-4"><MetricBox icon={<Comments />} label="Total comments" value={<Num value={totalComments} />} period="Loaded content" subtitle={totalComments > 0 ? 'Across all platforms' : 'Open an analytics page to load'} highlight /><MetricBox icon={<Videos />} label="YouTube comments" value={<Num value={summary.ytComments} />} period="Loaded videos" subtitle={`${fmtPercent(summary.commentShare.youtube)} of all comments`} />- <MetricBox icon={<Reddit />} label="Reddit comments" value={<Num value={summary.rdComments} />} period="Loaded posts" subtitle={`${fmtPercent(summary.commentShare.reddit)} of all comments`} />+ <MetricBox icon={<Instagram />} label="Instagram comments" value={<Num value={cacheTotals.igComments} />} period="Loaded posts" subtitle={`${fmtPercent(summary.commentShare.instagram)} of all comments`} /><MetricBox icon={<PerItem />} label="Comments per item" value={<Num value={summary.avgCommentsPerContent} />} subtitle={`Average across ${fmtNum(totalContent)} ${pluralWord(totalContent, 'item')}`} /></div>@@ -35,24 +35,24 @@ export default function CommentsTab({ stats }: CommentsTabProps) {<EmptyStateicon={<Comments />}title="No comment data yet"- description="Open a channel or account analytics page to load its comments, or track individual posts and videos."+ description="Open a channel or account analytics page to load its comments, or track individual videos."action={<Button size="sm" variant="outline" render={<Link to="/tracked-content" />}>Track content</Button>}/></SurfaceBox>) : (<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">- <SurfaceBox title="Comments by tracked content" subheader="Top 12 tracked items ranked by comments">+ <SurfaceBox title="Comments by tracked video" subheader="Top 12 tracked videos ranked by comments"><MetricAreaChartdata={charts.commentByContent}dataKey="comments"label="Comments"- title="Comments by tracked content"+ title="Comments by tracked video"description={rankingSummary(pointsOf(charts.commentByContent, 'name', 'comments'), fmtNumFull, 'comments')}color={SERIES.neutral}emptyMessage="Track content to compare comment volume"/></SurfaceBox>- <SurfaceBox title="Comments by category" subheader="Total comments across every item in each category">+ <SurfaceBox title="Comments by category" subheader="Total comments across every video in each category"><MetricAreaChartdata={charts.commentByCategory}dataKey="comments"diff --git a/frontend/src/features/analytics/overview/ContentTab.tsx b/frontend/src/features/analytics/overview/ContentTab.tsxindex 8b33d5f..5ba5ddd 100644--- a/frontend/src/features/analytics/overview/ContentTab.tsx+++ b/frontend/src/features/analytics/overview/ContentTab.tsx@@ -13,7 +13,7 @@ import CategoryRow from './CategoryRow';import type { OverviewStats } from './useOverviewStats';import type { CategoryStat } from './overviewTrackedStats.ts';-const { videos: Videos, instagram: Instagram, redditPosts: Reddit, tracked: Tracked, category: Category } = METRIC_ICONS;+const { videos: Videos, instagram: Instagram, tracked: Tracked, category: Category } = METRIC_ICONS;function instagramContentSubtitle(stats: OverviewStats): string {const { igTypes } = stats.cacheTotals;@@ -23,10 +23,7 @@ function instagramContentSubtitle(stats: OverviewStats): string {function CategoryTrailing({ stat }: { stat: CategoryStat }) {return (- <span className="flex flex-col items-end gap-0.5 text-caption">- {stat.views > 0 && <span className="font-medium text-ink">{fmtNum(stat.views)} views</span>}- {stat.rdCount > 0 && <span className="text-ink-faint">{fmtNum(stat.rdKarma)} karma</span>}- </span>+ <span className="text-caption font-medium text-ink">{fmtNum(stat.views)} views</span>);}@@ -35,14 +32,13 @@ export interface ContentTabProps {}export default function ContentTab({ stats }: ContentTabProps) {- const { groups, totals, cacheTotals, trackedStats, categoryStats } = stats;+ const { groups, totals, trackedStats, categoryStats } = stats;return (<>- <div className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4">+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-3"><MetricBox icon={<Videos />} label="YouTube videos" value={<Num value={totals.videos} />} period="All time" subtitle={countLabel(groups.youtube.length, 'channel')} /><MetricBox icon={<Instagram />} label="Instagram content" value={<Num value={totals.posts} />} period="All time" subtitle={instagramContentSubtitle(stats)} />- <MetricBox icon={<Reddit />} label="Reddit posts" value={<Num value={cacheTotals.rdPosts} />} period="Loaded posts" subtitle={cacheTotals.rdPosts > 0 ? 'From the analytics cache' : 'Open Reddit analytics to load'} />- <MetricBox icon={<Tracked />} label="Tracked content" value={<Num value={trackedStats.total} />} period="Now" subtitle={`${trackedStats.ytItems.length} YouTube, ${trackedStats.rdItems.length} Reddit`} />+ <MetricBox icon={<Tracked />} label="Tracked content" value={<Num value={trackedStats.total} />} period="Now" subtitle={countLabel(categoryStats.length, 'category')} /></div><div className="grid grid-cols-1 gap-4 md:grid-cols-2">@@ -65,7 +61,7 @@ export default function ContentTab({ stats }: ContentTabProps) {compacticon={<Category />}title="No categories yet"- description="Assign categories to tracked content to see this breakdown."+ description="Assign categories to tracked videos to see this breakdown."action={<Button size="sm" variant="outline" render={<Link to="/tracked-content" />}>Open tracked content</Button>}/>) : (diff --git a/frontend/src/features/analytics/overview/GettingStarted.tsx b/frontend/src/features/analytics/overview/GettingStarted.tsxindex f2a4231..2ac3ad6 100644--- a/frontend/src/features/analytics/overview/GettingStarted.tsx+++ b/frontend/src/features/analytics/overview/GettingStarted.tsx@@ -9,7 +9,7 @@ export default function GettingStarted() {<div className="relative flex max-w-xl flex-col gap-4 p-8"><p className="eyebrow text-brand-text">Getting started</p><h2 id="getting-started-title" className="font-heading text-page-title font-semibold text-ink">Bring your channels into one picture.</h2>- <p className="max-w-prose text-ink-muted">Add a YouTube channel, connect an Instagram Business or Creator account, or add a Reddit profile. Analytics start filling in as soon as an account is added.</p>+ <p className="max-w-prose text-ink-muted">Add a YouTube channel or connect an Instagram Business or Creator account. Analytics start filling in as soon as an account is added.</p><div><Button render={<Link to="/accounts?add=1" />}><Plus data-icon="inline-start" aria-hidden="true" />Add account</Button></div></div></section>diff --git a/frontend/src/features/analytics/overview/LikesTab.tsx b/frontend/src/features/analytics/overview/LikesTab.tsxindex b00edfa..4c68e52 100644--- a/frontend/src/features/analytics/overview/LikesTab.tsx+++ b/frontend/src/features/analytics/overview/LikesTab.tsx@@ -5,13 +5,13 @@ import MetricBox from '@/components/MetricBox';import Num from '@/components/Num';import MetricAreaChart from '@/components/MetricAreaChart';import { EmptyState } from '@/components/StateViews';-import { PLATFORM_META } from '@/lib/accounts';import { SERIES, pointsOf, rankingSummary } from '@/lib/chart';import { METRIC_ICONS } from '@/lib/metricIcons';-import { fmtNum, fmtNumFull, fmtPercent } from '../../../utils/formatters';+import { fmtNumFull, fmtPercent } from '../../../utils/formatters';+import { CATEGORY_SERIES } from './overviewCharts.ts';import type { OverviewStats } from './useOverviewStats';-const { likes: Likes, karma: Karma, videos: Videos, instagram: Instagram } = METRIC_ICONS;+const { likes: Likes, videos: Videos, instagram: Instagram } = METRIC_ICONS;function instagramLikesSubtitle(stats: OverviewStats): string {if (stats.groups.instagram.length > 0) return `${fmtPercent(stats.summary.likeShare.instagram)} of all likes`;@@ -23,13 +23,12 @@ export interface LikesTabProps {}export default function LikesTab({ stats }: LikesTabProps) {- const { totals, cacheTotals, trackedStats, summary, charts } = stats;+ const { cacheTotals, summary, charts } = stats;const { totalLikes } = summary;return (<>- <div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-4">- <MetricBox icon={<Likes />} label="Total likes" value={<Num value={totalLikes} />} period="Loaded content" subtitle={totalLikes > 0 ? 'YouTube likes, Instagram likes, Reddit karma' : 'Open an analytics page to load'} highlight />- <MetricBox icon={<Karma />} label="Reddit karma" value={<Num value={summary.redditKarma} />} period="All time" subtitle={`${fmtNum(totals.postKarma)} account, ${fmtNum(trackedStats.rdKarma)} tracked`} />+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-3">+ <MetricBox icon={<Likes />} label="Total likes" value={<Num value={totalLikes} />} period="Loaded content" subtitle={totalLikes > 0 ? 'YouTube and Instagram likes' : 'Open an analytics page to load'} highlight /><MetricBox icon={<Videos />} label="YouTube likes" value={<Num value={summary.ytLikes} />} period="Loaded videos" subtitle={`${fmtPercent(summary.likeShare.youtube)} of all likes`} /><MetricBox icon={<Instagram />} label="Instagram likes" value={<Num value={cacheTotals.igLikes} />} period="Loaded posts" subtitle={instagramLikesSubtitle(stats)} /></div>@@ -39,32 +38,32 @@ export default function LikesTab({ stats }: LikesTabProps) {<EmptyStateicon={<Likes />}title="No engagement data yet"- description="Open a channel or account analytics page to load its likes, or track individual posts and videos."+ description="Open a channel or account analytics page to load its likes, or track individual videos."action={<Button size="sm" variant="outline" render={<Link to="/tracked-content" />}>Track content</Button>}/></SurfaceBox>) : (<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">- <SurfaceBox title="Karma by Reddit account" subheader="Post karma earned by each connected account">+ <SurfaceBox title="Likes by tracked video" subheader="Top 12 tracked videos ranked by likes"><MetricAreaChart- data={charts.karmaByAccount}- dataKey="karma"- label="Post karma"- title="Karma by Reddit account"- description={rankingSummary(pointsOf(charts.karmaByAccount, 'name', 'karma'), fmtNumFull, 'post karma')}- color={PLATFORM_META.reddit.series}- emptyMessage="Connect a Reddit account to see karma"+ data={charts.likesByContent}+ dataKey="likes"+ label="Likes"+ title="Likes by tracked video"+ description={rankingSummary(pointsOf(charts.likesByContent, 'name', 'likes'), fmtNumFull, 'likes')}+ color={SERIES.neutral}+ emptyMessage="Track videos to compare likes"/></SurfaceBox>- <SurfaceBox title="Engagement by tracked content" subheader="YouTube likes and Reddit karma for the top 12 tracked items">+ <SurfaceBox title="Likes by category" subheader="Total likes across every video in each category"><MetricAreaChart- data={charts.engagementByContent}- dataKey="engagement"- label="Likes or karma"- title="Engagement by tracked content"- description={rankingSummary(pointsOf(charts.engagementByContent, 'name', 'engagement'), fmtNumFull, 'likes or karma')}- color={SERIES.neutral}- emptyMessage="Track content to compare engagement"+ data={charts.likesByCategory}+ dataKey="likes"+ label="Likes"+ title="Likes by category"+ description={rankingSummary(pointsOf(charts.likesByCategory, 'name', 'likes'), fmtNumFull, 'likes')}+ color={CATEGORY_SERIES}+ emptyMessage="Assign categories to tracked videos to see this breakdown"/></SurfaceBox></div>diff --git a/frontend/src/features/analytics/overview/ViewsTab.tsx b/frontend/src/features/analytics/overview/ViewsTab.tsxindex 06b92c6..fca8ad2 100644--- a/frontend/src/features/analytics/overview/ViewsTab.tsx+++ b/frontend/src/features/analytics/overview/ViewsTab.tsx@@ -4,7 +4,7 @@ import Num from '@/components/Num';import MetricAreaChart from '@/components/MetricAreaChart';import { pointsOf, rankingSummary } from '@/lib/chart';import { METRIC_ICONS } from '@/lib/metricIcons';-import { fmtNum, fmtNumFull } from '../../../utils/formatters';+import { fmtNumFull } from '../../../utils/formatters';import { CATEGORY_SERIES } from './overviewCharts.ts';import { countLabel, igTypeSummary } from './overviewLabels.ts';import InstagramViewsTable from './InstagramViewsTable';@@ -31,13 +31,13 @@ export default function ViewsTab({ stats, isSyncing }: ViewsTabProps) {<MetricBox icon={<Views />} label="Total views" value={<Num value={summary.totalViews} />} period="All sources" subtitle="YouTube, Instagram and tracked content" highlight /><MetricBox icon={<Videos />} label="Channel views" value={<Num value={totals.views} />} period="All time" subtitle={countLabel(groups.youtube.length, 'YouTube channel')} /><MetricBox icon={<Instagram />} label="Instagram views" value={<Num value={cacheTotals.igViews} />} period="Loaded posts" subtitle={instagramViewsSubtitle(stats)} />- <MetricBox icon={<Tracked />} label="Tracked views" value={<Num value={summary.trackedViewTotal} />} period="Tracked items" subtitle={`${fmtNum(trackedStats.ytViews)} YouTube, ${fmtNum(trackedStats.rdViews)} Reddit`} />+ <MetricBox icon={<Tracked />} label="Tracked views" value={<Num value={summary.trackedViewTotal} />} period="Tracked items" subtitle={countLabel(trackedStats.total, 'tracked video')} /></div>{groups.instagram.length > 0 && <InstagramViewsTable rows={stats.igAccountRows} isSyncing={isSyncing} />}{stats.categoryStats.length > 0 && (- <SurfaceBox title="Views by category" subheader="YouTube video views plus Reddit post views entered by hand">+ <SurfaceBox title="Views by category" subheader="Views across the tracked videos in each category"><MetricAreaChartdata={stats.charts.categoryViews}dataKey="views"diff --git a/frontend/src/features/analytics/overview/overviewCharts.ts b/frontend/src/features/analytics/overview/overviewCharts.tsindex 36b941f..3f4de51 100644--- a/frontend/src/features/analytics/overview/overviewCharts.ts+++ b/frontend/src/features/analytics/overview/overviewCharts.ts@@ -8,7 +8,7 @@ import type { CategoryStat } from './overviewTrackedStats.ts';export type AccountGroups = Record<Platform, OverviewAccountFields[]>;-export type AudiencePointType = Platform | 'category';+export type AudiencePointType = Platform;export interface AudiencePoint {name: string;@@ -28,7 +28,7 @@ export interface ChartTrackedItem extends TrackedMetrics {url?: string;}-export type CategoryChartStat = Pick<CategoryStat, 'category' | 'rdKarma' | 'views' | 'ytComments' | 'rdComments'>;+export type CategoryChartStat = Pick<CategoryStat, 'category' | 'views' | 'likes' | 'comments'>;export const CATEGORY_SERIES = SERIES.neutral;@@ -42,8 +42,7 @@ function itemName(item: ChartTrackedItem): string {return (item.title || item.label || item.url || '').slice(0, 16);}-// karma only for categories: adding views would mix reach into an audience chart-export function audienceChartDataOf(groups: AccountGroups, categoryStats: CategoryChartStat[]): AudiencePoint[] {+export function audienceChartDataOf(groups: AccountGroups): AudiencePoint[] {return [...groups.youtube.map((account): AudiencePoint => ({name: shortName(account.title || '', 12),@@ -55,25 +54,13 @@ export function audienceChartDataOf(groups: AccountGroups, categoryStats: Categovalue: account.followersCount || 0,type: 'instagram',})),- ...groups.reddit.map((account): AudiencePoint => ({- name: `u/${(account.username || '')}`.slice(0, 12),- value: account.totalKarma || 0,- type: 'reddit',- })),- ...categoryStats.map((stat): AudiencePoint => ({- name: shortName(stat.category, 12),- value: stat.rdKarma,- type: 'category',- })),];}-export function audienceLegendOf(groups: AccountGroups, categoryStats: CategoryChartStat[]): AudienceLegendItem[] {+export function audienceLegendOf(groups: AccountGroups): AudienceLegendItem[] {return [groups.youtube.length ? { color: PLATFORM_META.youtube.series, label: 'YouTube subscribers' } : null,groups.instagram.length ? { color: PLATFORM_META.instagram.series, label: 'Instagram followers' } : null,- groups.reddit.length ? { color: PLATFORM_META.reddit.series, label: 'Reddit karma' } : null,- categoryStats.length ? { color: CATEGORY_SERIES, label: 'Category karma' } : null,].filter(Boolean) as AudienceLegendItem[];}@@ -81,17 +68,15 @@ export const AUDIENCE_KIND: Record<AudiencePointType, string> = {youtube: 'YouTube subscribers',instagram: 'Instagram followers',reddit: 'Reddit karma',- category: 'Category karma',};-// subscribers, followers and karma share one line, so each point is read with what it counts+// subscribers and followers share one line, so each point is read with what it countsexport function audienceDescription(points: AudiencePoint[]): string {if (points.length === 0) return 'No data yet.';return points.map(point => `${point.name}, ${AUDIENCE_KIND[point.type]}: ${fmtNumFull(point.value)}.`).join(' ');}export function audienceDotColor(type: AudiencePointType): string {- if (type === 'category') return CATEGORY_SERIES;return PLATFORM_META[type]?.series;}@@ -99,19 +84,19 @@ export function commentByContentOf(trackedContent: ChartTrackedItem[]) {return trackedContent.map(item => ({name: itemName(item),- comments: item.contentType === 'youtube' ? (item.commentCount ?? 0) : (item.numComments ?? 0),+ comments: item.commentCount ?? 0,})).sort((a, b) => b.comments - a.comments).slice(0, CHART_ITEMS);}-export function engagementByContentOf(trackedContent: ChartTrackedItem[]) {+export function likesByContentOf(trackedContent: ChartTrackedItem[]) {return trackedContent.map(item => ({name: itemName(item),- engagement: item.contentType === 'youtube' ? (item.likeCount ?? 0) : (item.score ?? 0),+ likes: item.likeCount ?? 0,}))- .sort((a, b) => b.engagement - a.engagement)+ .sort((a, b) => b.likes - a.likes).slice(0, CHART_ITEMS);}@@ -123,12 +108,12 @@ export function categoryViewDataOf(categoryStats: CategoryChartStat[]) {export function commentByCategoryOf(categoryStats: CategoryChartStat[]) {return categoryStats- .map(stat => ({ name: stat.category.slice(0, 16), comments: stat.ytComments + stat.rdComments }))+ .map(stat => ({ name: stat.category.slice(0, 16), comments: stat.comments })).sort((a, b) => b.comments - a.comments);}-export function karmaByAccountOf(redditAccounts: OverviewAccountFields[]) {- return [...redditAccounts]- .sort((a, b) => (b.postKarma || 0) - (a.postKarma || 0))- .map(account => ({ name: `u/${account.username || ''}`.slice(0, 16), karma: account.postKarma || 0 }));+export function likesByCategoryOf(categoryStats: CategoryChartStat[]) {+ return categoryStats+ .map(stat => ({ name: stat.category.slice(0, 16), likes: stat.likes }))+ .sort((a, b) => b.likes - a.likes);}diff --git a/frontend/src/features/analytics/overview/overviewLabels.ts b/frontend/src/features/analytics/overview/overviewLabels.tsindex 3738ef9..1f005e7 100644--- a/frontend/src/features/analytics/overview/overviewLabels.ts+++ b/frontend/src/features/analytics/overview/overviewLabels.ts@@ -7,8 +7,8 @@ import type { CategoryStat, TrackedStats } from './overviewTrackedStats.ts';// the parts of useOverviewStats() the metric tabs readexport interface MetricTabStats {- totals: Pick<AccountTotals, 'subscribers' | 'followers' | 'karma' | 'views' | 'videos' | 'posts'>;- cacheTotals: Pick<CacheTotals, 'igViews' | 'rdPosts'>;+ totals: Pick<AccountTotals, 'subscribers' | 'followers' | 'views' | 'videos' | 'posts'>;+ cacheTotals: Pick<CacheTotals, 'igViews'>;trackedStats: Pick<TrackedStats, 'total'>;summary: {totalAudience: number;@@ -62,7 +62,7 @@ export function metricTabsOf(accounts: OverviewAccountFields[], stats: MetricTab{value: 'audience', label: 'Audience', figure: summary.totalAudience,detail: detailOf([- partOf(totals.subscribers, 'subscribers'), partOf(totals.followers, 'followers'), partOf(totals.karma, 'karma'),+ partOf(totals.subscribers, 'subscribers'), partOf(totals.followers, 'followers'),], 'No data yet'),},{@@ -74,8 +74,7 @@ export function metricTabsOf(accounts: OverviewAccountFields[], stats: MetricTab{value: 'content', label: 'Content', figure: summary.totalContent,detail: detailOf([- partOf(totals.videos, 'videos'), partOf(totals.posts, 'Instagram'),- partOf(cacheTotals.rdPosts, 'Reddit'), partOf(trackedStats.total, 'tracked'),+ partOf(totals.videos, 'videos'), partOf(totals.posts, 'Instagram'), partOf(trackedStats.total, 'tracked'),], 'No content yet'),},{ value: 'accounts', label: 'Accounts', figure: accounts.length, detail: platformSummary(accounts) },@@ -96,31 +95,24 @@ export function igTypeSummary(igTypes: Record<string, IGTypeTotals>, field: keyo.join(', ');}-export function categoryMeta(stat: Pick<CategoryStat, 'count' | 'ytCount' | 'rdCount'>): string {- return [- countLabel(stat.count, 'item'),- stat.ytCount > 0 && `${stat.ytCount} YouTube`,- stat.rdCount > 0 && `${stat.rdCount} Reddit`,- ].filter(Boolean).join(', ');+export function categoryMeta(stat: Pick<CategoryStat, 'count'>): string {+ return countLabel(stat.count, 'video');}export function topContentLabel(account: OverviewAccountFields): string {const platform = platformOf(account);if (platform === 'instagram') return `${fmtNum(account.mediaCount)} items`;- if (platform === 'reddit') return `${fmtNum(account.totalKarma)} karma`;return `${fmtNum(account.viewCount)} views`;}export function accountAudienceLabel(account: OverviewAccountFields): string {const platform = platformOf(account);if (platform === 'instagram') return `${fmtNum(account.followersCount)} followers`;- if (platform === 'reddit') return `${fmtNum(account.totalKarma)} karma`;return `${fmtNum(account.subscriberCount)} subscribers`;}export function accountContentLabel(account: OverviewAccountFields): string {const platform = platformOf(account);if (platform === 'instagram') return `${fmtNum(account.mediaCount)} items`;- if (platform === 'reddit') return `${fmtNum(account.postKarma)} post karma`;return `${fmtNum(account.viewCount)} views, ${fmtNum(account.videoCount)} videos`;}diff --git a/frontend/src/features/analytics/overview/overviewStats.ts b/frontend/src/features/analytics/overview/overviewStats.tsindex d18582e..f9b3e65 100644--- a/frontend/src/features/analytics/overview/overviewStats.ts+++ b/frontend/src/features/analytics/overview/overviewStats.ts@@ -9,8 +9,6 @@ export interface OverviewAccountFields extends AccountFields {mediaCount?: number;viewCount?: number;videoCount?: number;- postKarma?: number;- commentKarma?: number;}export interface OverviewAccount extends OverviewAccountFields {@@ -25,8 +23,6 @@ export interface AccountCacheFields {totalComments?: number;totalViews?: number;contentTypes?: Partial<Record<InstagramContentType, Partial<InstagramContentTypeTotals>>>;- fetchedPosts?: number;- totalScore?: number;fetchedAt?: string;}@@ -47,9 +43,6 @@ export interface AccountTotals {videos: number;followers: number;posts: number;- karma: number;- postKarma: number;- commentKarma: number;}export interface IGTypeTotals {@@ -63,9 +56,6 @@ export interface CacheTotals {igLikes: number;igComments: number;igViews: number;- rdPosts: number;- rdKarma: number;- rdComments: number;igTypes: Record<string, IGTypeTotals>;}@@ -78,14 +68,6 @@ function addAccountTotals(totals: AccountTotals, account: OverviewAccountFields)if (account.platform === 'instagram') {return { ...totals, followers: totals.followers + (account.followersCount || 0), posts: totals.posts + (account.mediaCount || 0) };}- if (account.platform === 'reddit') {- return {- ...totals,- karma: totals.karma + (account.totalKarma || 0),- postKarma: totals.postKarma + (account.postKarma || 0),- commentKarma: totals.commentKarma + (account.commentKarma || 0),- };- }return {...totals,subscribers: totals.subscribers + (account.subscriberCount || 0),@@ -96,7 +78,7 @@ function addAccountTotals(totals: AccountTotals, account: OverviewAccountFields)export function accountTotalsOf(accounts: OverviewAccountFields[]): AccountTotals {return accounts.reduce<AccountTotals>(addAccountTotals, {- subscribers: 0, views: 0, videos: 0, followers: 0, posts: 0, karma: 0, postKarma: 0, commentKarma: 0,+ subscribers: 0, views: 0, videos: 0, followers: 0, posts: 0,});}@@ -113,7 +95,7 @@ function addInstagramCache(result: CacheTotals, cache: AccountCacheFields): void// only accounts saved as 'youtube' count here, unlike the platform splitsexport function cacheTotalsOf(accounts: OverviewAccount[], analyticsCache: AccountCache): CacheTotals {const result: CacheTotals = {- ytLikes: 0, ytComments: 0, igLikes: 0, igComments: 0, igViews: 0, rdPosts: 0, rdKarma: 0, rdComments: 0,+ ytLikes: 0, ytComments: 0, igLikes: 0, igComments: 0, igViews: 0,igTypes: Object.fromEntries(IG_CONTENT_TYPES.map(type => [type, { count: 0, views: 0 }])),};accounts.forEach(account => {@@ -124,10 +106,6 @@ export function cacheTotalsOf(accounts: OverviewAccount[], analyticsCache: Accouresult.ytComments += cache.totalComments ?? 0;} else if (account.platform === 'instagram') {addInstagramCache(result, cache);- } else if (account.platform === 'reddit') {- result.rdPosts += cache.fetchedPosts ?? 0;- result.rdKarma += cache.totalScore ?? 0;- result.rdComments += cache.totalComments ?? 0;}});return result;@@ -139,30 +117,26 @@ function shareOf(part: number, total: number): number {// tracked items are never the user's own, so they never overlap cache totalsexport function summaryOf(totals: AccountTotals, cacheTotals: CacheTotals, trackedStats: TrackedStats) {- const totalContent = totals.videos + totals.posts + cacheTotals.rdPosts + trackedStats.total;- const trackedViewTotal = trackedStats.ytViews + trackedStats.rdViews;- const ytComments = cacheTotals.ytComments + trackedStats.ytComments;- const rdComments = cacheTotals.rdComments + trackedStats.rdComments;- const totalComments = ytComments + cacheTotals.igComments + rdComments;- const redditKarma = totals.postKarma + trackedStats.rdKarma;- const ytLikes = cacheTotals.ytLikes + trackedStats.ytLikes;- const totalLikes = redditKarma + ytLikes + cacheTotals.igLikes;+ const totalContent = totals.videos + totals.posts + trackedStats.total;+ const ytComments = cacheTotals.ytComments + trackedStats.comments;+ const totalComments = ytComments + cacheTotals.igComments;+ const ytLikes = cacheTotals.ytLikes + trackedStats.likes;+ const totalLikes = ytLikes + cacheTotals.igLikes;return {- totalAudience: totals.subscribers + totals.followers + totals.karma,+ totalAudience: totals.subscribers + totals.followers,totalContent,- trackedViewTotal,- totalViews: totals.views + cacheTotals.igViews + trackedViewTotal,- ytComments, rdComments, totalComments,- redditKarma, ytLikes, totalLikes,+ trackedViewTotal: trackedStats.views,+ totalViews: totals.views + cacheTotals.igViews + trackedStats.views,+ ytComments, totalComments,+ ytLikes, totalLikes,avgCommentsPerContent: totalContent > 0 ? Math.round(totalComments / totalContent) : 0,- commentShare: { youtube: shareOf(ytComments, totalComments), reddit: shareOf(rdComments, totalComments) },+ commentShare: { youtube: shareOf(ytComments, totalComments), instagram: shareOf(cacheTotals.igComments, totalComments) },likeShare: { youtube: shareOf(ytLikes, totalLikes), instagram: shareOf(cacheTotals.igLikes, totalLikes) },};}function contentOf(account: OverviewAccountFields): number {if (account.platform === 'instagram') return account.mediaCount || 0;- if (account.platform === 'reddit') return account.totalKarma || 0;return account.viewCount || 0;}diff --git a/frontend/src/features/analytics/overview/overviewTrackedStats.ts b/frontend/src/features/analytics/overview/overviewTrackedStats.tsindex d94c724..a4fedac 100644--- a/frontend/src/features/analytics/overview/overviewTrackedStats.ts+++ b/frontend/src/features/analytics/overview/overviewTrackedStats.ts@@ -1,94 +1,57 @@import { trackedViews } from '../../../utils/trackedContent.ts';import type { TrackedMetrics } from '../../../utils/trackedContent.ts';-// the tracked post fields the overview reads+// the tracked video fields the overview readsexport interface TrackedStatsItem extends TrackedMetrics {category?: string;}-export interface TrackedStats<T extends TrackedStatsItem = TrackedStatsItem> {+export interface TrackedStats {total: number;- ytItems: T[];- rdItems: T[];- ytViews: number;- ytLikes: number;- ytComments: number;- rdViews: number;- rdKarma: number;- rdComments: number;+ views: number;+ likes: number;+ comments: number;}-export interface CategoryTotals {+export interface CategoryStat {category: string;count: number;- ytCount: number;- rdCount: number;- ytViews: number;- ytLikes: number;- ytComments: number;- rdViews: number;- rdKarma: number;- rdComments: number;-}--export interface CategoryStat extends CategoryTotals {views: number;+ likes: number;+ comments: number;}function sumOf<T>(items: T[], valueOf: (item: T) => number): number {return items.reduce((sum, item) => sum + valueOf(item), 0);}-// reddit post score is karma, so it rolls into karma totals-export function trackedStatsOf<T extends TrackedStatsItem>(trackedContent: T[]): TrackedStats<T> {- const ytItems = trackedContent.filter(item => item.contentType === 'youtube');- const rdItems = trackedContent.filter(item => (item.contentType || 'reddit') === 'reddit');+export function trackedStatsOf(trackedContent: TrackedStatsItem[]): TrackedStats {return {- total: trackedContent.length,- ytItems,- rdItems,- ytViews: sumOf(ytItems, trackedViews),- ytLikes: sumOf(ytItems, item => item.likeCount ?? 0),- ytComments: sumOf(ytItems, item => item.commentCount ?? 0),- rdViews: sumOf(rdItems, trackedViews),- rdKarma: sumOf(rdItems, item => item.score ?? 0),- rdComments: sumOf(rdItems, item => item.numComments ?? 0),+ total: trackedContent.length,+ views: sumOf(trackedContent, trackedViews),+ likes: sumOf(trackedContent, item => item.likeCount ?? 0),+ comments: sumOf(trackedContent, item => item.commentCount ?? 0),};}-function emptyCategory(category: string): CategoryTotals {- return {- category,- count: 0, ytCount: 0, rdCount: 0,- ytViews: 0, ytLikes: 0, ytComments: 0,- rdViews: 0, rdKarma: 0, rdComments: 0,- };+function emptyCategory(category: string): CategoryStat {+ return { category, count: 0, views: 0, likes: 0, comments: 0 };}-function addToCategory(stat: CategoryTotals, item: TrackedStatsItem): void {+function addToCategory(stat: CategoryStat, item: TrackedStatsItem): void {stat.count++;- if (item.contentType === 'youtube') {- stat.ytCount++;- stat.ytViews += trackedViews(item);- stat.ytLikes += item.likeCount ?? 0;- stat.ytComments += item.commentCount ?? 0;- return;- }- stat.rdCount++;- stat.rdViews += trackedViews(item);- stat.rdKarma += item.score ?? 0;- stat.rdComments += item.numComments ?? 0;+ stat.views += trackedViews(item);+ stat.likes += item.likeCount ?? 0;+ stat.comments += item.commentCount ?? 0;}export function categoryStatsOf(trackedContent: TrackedStatsItem[]): CategoryStat[] {const withCategory = trackedContent.filter(item => item.category);if (!withCategory.length) return [];- const byCategory: Record<string, CategoryTotals> = {};+ const byCategory: Record<string, CategoryStat> = {};withCategory.forEach(item => {if (!byCategory[item.category!]) byCategory[item.category!] = emptyCategory(item.category!);addToCategory(byCategory[item.category!], item);});- return Object.values(byCategory)- .map(stat => ({ ...stat, views: stat.ytViews + stat.rdViews }))- .sort((a, b) => (b.views + b.rdKarma) - (a.views + a.rdKarma));+ return Object.values(byCategory).sort((a, b) => b.views - a.views);}diff --git a/frontend/src/features/analytics/overview/useOverviewStats.ts b/frontend/src/features/analytics/overview/useOverviewStats.tsindex 1bcc5ec..4741a8c 100644--- a/frontend/src/features/analytics/overview/useOverviewStats.ts+++ b/frontend/src/features/analytics/overview/useOverviewStats.ts@@ -10,17 +10,17 @@ import {import { categoryStatsOf, trackedStatsOf } from './overviewTrackedStats.ts';import {audienceChartDataOf, audienceLegendOf, categoryViewDataOf, commentByCategoryOf, commentByContentOf,- engagementByContentOf, karmaByAccountOf,+ likesByCategoryOf, likesByContentOf,} from './overviewCharts.ts';function useOverviewCharts(groups: AccountGroups, trackedContent: TrackedContentItem[], categoryStats: CategoryStat[]) {- const audience = useMemo(() => audienceChartDataOf(groups, categoryStats), [groups, categoryStats]);+ const audience = useMemo(() => audienceChartDataOf(groups), [groups]);const commentByContent = useMemo(() => commentByContentOf(trackedContent), [trackedContent]);const categoryViews = useMemo(() => categoryViewDataOf(categoryStats), [categoryStats]);const commentByCategory = useMemo(() => commentByCategoryOf(categoryStats), [categoryStats]);- const karmaByAccount = useMemo(() => karmaByAccountOf(groups.reddit), [groups.reddit]);- const engagementByContent = useMemo(() => engagementByContentOf(trackedContent), [trackedContent]);- return { audience, commentByContent, categoryViews, commentByCategory, karmaByAccount, engagementByContent };+ const likesByContent = useMemo(() => likesByContentOf(trackedContent), [trackedContent]);+ const likesByCategory = useMemo(() => likesByCategoryOf(categoryStats), [categoryStats]);+ return { audience, commentByContent, categoryViews, commentByCategory, likesByContent, likesByCategory };}export function useOverviewStats(accounts: AppAccount[], overviewData: OverviewResponse) {@@ -44,7 +44,7 @@ export function useOverviewStats(accounts: AppAccount[], overviewData: OverviewRcategoryStats,charts,summary: summaryOf(totals, cacheTotals, trackedStats),- legend: audienceLegendOf(groups, categoryStats),+ legend: audienceLegendOf(groups),igAccountRows: igAccountRowsOf(groups.instagram, analyticsCache),byAudience: sortedByAudience(accounts),byContent: sortedByContent(accounts),diff --git a/frontend/tests/features/analytics/overview/overviewCharts.test.ts b/frontend/tests/features/analytics/overview/overviewCharts.test.tsindex 34aaf05..64f3dd2 100644--- a/frontend/tests/features/analytics/overview/overviewCharts.test.ts+++ b/frontend/tests/features/analytics/overview/overviewCharts.test.ts@@ -1,56 +1,57 @@import { test } from 'node:test';import assert from 'node:assert/strict';import {- CATEGORY_SERIES, audienceChartDataOf, audienceDescription, audienceLegendOf, audienceDotColor, commentByContentOf, engagementByContentOf,- categoryViewDataOf, commentByCategoryOf, karmaByAccountOf,+ audienceChartDataOf, audienceDescription, audienceLegendOf, audienceDotColor, commentByContentOf, likesByContentOf,+ categoryViewDataOf, commentByCategoryOf, likesByCategoryOf,} from '../../../../src/features/analytics/overview/overviewCharts.ts';const groups = {youtube: [{ title: 'A channel with a long name', subscriberCount: 10 }],- instagram: [{ username: 'fold', followersCount: 5 }],- reddit: [{ username: 'averyverylongname', totalKarma: 3, postKarma: 2 }, { username: 'b', postKarma: 9 }],+ instagram: [{ username: 'fold', followersCount: 5 }, { title: 'Paper' }],+ reddit: [],};-const categoryStats = [{ category: 'Technology news', rdKarma: 4, views: 10, ytComments: 1, rdComments: 2 }];+const categoryStats = [+ { category: 'Technology news', views: 10, likes: 3, comments: 3 },+ { category: 'Art', views: 4, likes: 7, comments: 1 },+];-test('audience chart shortens names and keeps category karma only', () => {- assert.deepEqual(audienceChartDataOf(groups, categoryStats), [+test('audience chart shortens names and counts subscribers and followers', () => {+ assert.deepEqual(audienceChartDataOf(groups), [{ name: 'A channel wi…', value: 10, type: 'youtube' },{ name: 'fold', value: 5, type: 'instagram' },- { name: 'u/averyveryl', value: 3, type: 'reddit' },- { name: 'u/b', value: 0, type: 'reddit' },- { name: 'Technology n…', value: 4, type: 'category' },+ { name: 'Paper', value: 0, type: 'instagram' },]);});test('the audience description names what each point counts, in full', () => {- const points = [{ name: 'Kitchen', value: 12345, type: 'youtube' as const }, { name: 'Tech', value: 40, type: 'category' as const }];- assert.equal(audienceDescription(points), 'Kitchen, YouTube subscribers: 12,345. Tech, Category karma: 40.');+ const points = [{ name: 'Kitchen', value: 12345, type: 'youtube' as const }, { name: 'Fold', value: 40, type: 'instagram' as const }];+ assert.equal(audienceDescription(points), 'Kitchen, YouTube subscribers: 12,345. Fold, Instagram followers: 40.');assert.equal(audienceDescription([]), 'No data yet.');});test('legend lists only platforms with data', () => {- const labels = audienceLegendOf({ youtube: [], instagram: [{}], reddit: [] }, []).map(item => item.label);+ const labels = audienceLegendOf({ youtube: [], instagram: [{}], reddit: [] }).map(item => item.label);assert.deepEqual(labels, ['Instagram followers']);- assert.equal(audienceDotColor('category'), CATEGORY_SERIES);- assert.equal(audienceDotColor('reddit'), 'var(--chart-4)');+ assert.equal(audienceDotColor('youtube'), 'var(--chart-1)');+ assert.equal(audienceDotColor('instagram'), 'var(--chart-3)');});-test('tracked content charts rank the top items', () => {+test('tracked video charts rank the top items', () => {const tracked = [{ contentType: 'youtube', title: 'Video', commentCount: 3, likeCount: 8 },- { url: 'https://reddit.com/r/x/comments/abc', numComments: 7, score: 1 },+ { contentType: 'youtube', url: 'https://youtu.be/abcdefghijk', commentCount: 7, likeCount: 1 },];assert.deepEqual(commentByContentOf(tracked), [- { name: 'https://reddit.c', comments: 7 },+ { name: 'https://youtu.be', comments: 7 },{ name: 'Video', comments: 3 },]);- assert.deepEqual(engagementByContentOf(tracked).map(row => row.engagement), [8, 1]);- const many = Array.from({ length: 20 }, (_, i) => ({ title: `Post ${i}`, numComments: i }));+ assert.deepEqual(likesByContentOf(tracked).map(row => row.likes), [8, 1]);+ const many = Array.from({ length: 20 }, (_, i) => ({ title: `Video ${i}`, commentCount: i }));assert.equal(commentByContentOf(many).length, 12);});-test('category and karma charts', () => {- assert.deepEqual(categoryViewDataOf(categoryStats), [{ name: 'Technology news', views: 10 }]);- assert.deepEqual(commentByCategoryOf(categoryStats), [{ name: 'Technology news', comments: 3 }]);- assert.deepEqual(karmaByAccountOf(groups.reddit), [{ name: 'u/b', karma: 9 }, { name: 'u/averyverylongn', karma: 2 }]);+test('category charts rank categories by views, comments and likes', () => {+ assert.deepEqual(categoryViewDataOf(categoryStats), [{ name: 'Technology news', views: 10 }, { name: 'Art', views: 4 }]);+ assert.deepEqual(commentByCategoryOf(categoryStats), [{ name: 'Technology news', comments: 3 }, { name: 'Art', comments: 1 }]);+ assert.deepEqual(likesByCategoryOf(categoryStats), [{ name: 'Art', likes: 7 }, { name: 'Technology news', likes: 3 }]);});diff --git a/frontend/tests/features/analytics/overview/overviewLabels.test.ts b/frontend/tests/features/analytics/overview/overviewLabels.test.tsindex fb5480d..b6db70d 100644--- a/frontend/tests/features/analytics/overview/overviewLabels.test.ts+++ b/frontend/tests/features/analytics/overview/overviewLabels.test.ts@@ -7,7 +7,6 @@ import {const channel = { id: 'y1', viewCount: 5000, videoCount: 10, subscriberCount: 100 };const igAccount = { id: 'i1', platform: 'instagram', mediaCount: 20, followersCount: 300 };-const redditAccount = { id: 'r1', platform: 'reddit', totalKarma: 70, postKarma: 60 };test('count labels pluralise every count except one', () => {assert.equal(countLabel(1, 'channel'), '1 channel');@@ -29,19 +28,19 @@ test('sync detail prefers the syncing label', () => {test('metric tabs list present parts or a fallback', () => {const stats = {- totals: { subscribers: 1500, followers: 0, karma: 20, views: 0, videos: 3, posts: 0 },- cacheTotals: { igViews: 0, rdPosts: 0 },+ totals: { subscribers: 1500, followers: 20, views: 0, videos: 3, posts: 0 },+ cacheTotals: { igViews: 0 },trackedStats: { total: 2 },summary: { totalAudience: 1520, totalViews: 0, trackedViewTotal: 0, totalContent: 5, totalComments: 0, totalLikes: 9 },};- const tabs = metricTabsOf([channel, redditAccount], stats, false);+ const tabs = metricTabsOf([channel, igAccount], stats, false);assert.deepEqual(tabs.map(tab => tab.value), ['audience', 'views', 'content', 'accounts', 'comments', 'likes']);assert.equal(tabs[0].figure, 1520);- assert.equal(tabs[0].detail, '1.5K subscribers, 20 karma');+ assert.equal(tabs[0].detail, '1.5K subscribers, 20 followers');assert.equal(tabs[1].detail, 'No views recorded yet');assert.equal(tabs[2].detail, '3 videos, 2 tracked');assert.equal(tabs[3].figure, 2);- assert.equal(tabs[3].detail, '1 YouTube, 1 Reddit');+ assert.equal(tabs[3].detail, '1 YouTube, 1 Instagram');assert.equal(tabs[4].detail, 'Open an analytics page to load');assert.equal(tabs[5].detail, 'Across all platforms');});@@ -52,19 +51,16 @@ test('Instagram type summary lists every content type', () => {assert.equal(igTypeSummary(igTypes, 'count'), '2 reels, 1 posts, 0 videos');});-test('category meta skips empty platforms', () => {- assert.equal(categoryMeta({ count: 1, ytCount: 1, rdCount: 0 }), '1 item, 1 YouTube');- assert.equal(categoryMeta({ count: 3, ytCount: 1, rdCount: 2 }), '3 items, 1 YouTube, 2 Reddit');+test('category meta counts the videos in the category', () => {+ assert.equal(categoryMeta({ count: 1 }), '1 video');+ assert.equal(categoryMeta({ count: 3 }), '3 videos');});test('row labels follow the account platform', () => {assert.equal(topContentLabel(channel), '5K views');assert.equal(topContentLabel(igAccount), '20 items');- assert.equal(topContentLabel(redditAccount), '70 karma');assert.equal(accountAudienceLabel(channel), '100 subscribers');assert.equal(accountAudienceLabel(igAccount), '300 followers');- assert.equal(accountAudienceLabel(redditAccount), '70 karma');assert.equal(accountContentLabel(channel), '5K views, 10 videos');assert.equal(accountContentLabel(igAccount), '20 items');- assert.equal(accountContentLabel(redditAccount), '60 post karma');});diff --git a/frontend/tests/features/analytics/overview/overviewStats.test.ts b/frontend/tests/features/analytics/overview/overviewStats.test.tsindex b6f0bf4..b36a072 100644--- a/frontend/tests/features/analytics/overview/overviewStats.test.ts+++ b/frontend/tests/features/analytics/overview/overviewStats.test.ts@@ -9,26 +9,23 @@ import { trackedStatsOf } from '../../../../src/features/analytics/overview/overconst channel = { id: 'y1', platform: 'youtube', title: 'Studio', subscriberCount: 100, viewCount: 5000, videoCount: 10 };const legacyYt = { id: 'y2', title: 'Legacy', subscriberCount: 50, viewCount: 9000, videoCount: 4 };const igAccount = { id: 'i1', platform: 'instagram', username: 'fold', followersCount: 300, mediaCount: 20 };-const redditAccount = { id: 'r1', platform: 'reddit', username: 'ribbon', totalKarma: 70, postKarma: 60, commentKarma: 10 };-const accounts = [channel, legacyYt, igAccount, redditAccount];+const accounts = [channel, legacyYt, igAccount];const cache = {y1: { totalLikes: 5, totalComments: 2 },y2: { totalLikes: 99, totalComments: 99 },i1: { totalLikes: 7, totalComments: 3, totalViews: 400, contentTypes: { reel: { count: 2, views: 300 }, post: { count: 1, views: 100 } } },- r1: { fetchedPosts: 4, totalScore: 40, totalComments: 6 },};const tracked = [{ contentType: 'youtube', viewCount: 1000, likeCount: 10, commentCount: 4, category: 'Tech' },- { contentType: 'reddit', manualViews: 200, score: 30, numComments: 5, category: 'Tech' },- { score: 8, numComments: 1, category: 'Art' },+ { contentType: 'youtube', viewCount: 200, likeCount: 30, commentCount: 5, category: 'Tech' },{ contentType: 'youtube', viewCount: 50 },];test('account totals add each platform into its own fields', () => {assert.deepEqual(accountTotalsOf(accounts), {- subscribers: 150, views: 14000, videos: 14, followers: 300, posts: 20, karma: 70, postKarma: 60, commentKarma: 10,+ subscribers: 150, views: 14000, videos: 14, followers: 300, posts: 20,});});@@ -38,27 +35,25 @@ test('cache totals only count YouTube accounts saved with a platform', () => {assert.equal(totals.ytComments, 2);assert.equal(totals.igViews, 400);assert.deepEqual(totals.igTypes, { reel: { count: 2, views: 300 }, post: { count: 1, views: 100 }, video: { count: 0, views: 0 } });- assert.equal(totals.rdPosts, 4);- assert.equal(totals.rdKarma, 40);- assert.equal(totals.rdComments, 6);});test('summary combines account, cache and tracked totals', () => {const totals = accountTotalsOf(accounts);const summary = summaryOf(totals, cacheTotalsOf(accounts, cache), trackedStatsOf(tracked));- assert.equal(summary.totalAudience, 520);- assert.equal(summary.totalContent, 14 + 20 + 4 + 4);+ assert.equal(summary.totalAudience, 450);+ assert.equal(summary.totalContent, 14 + 20 + 3);assert.equal(summary.totalViews, 14000 + 400 + 1250);- assert.equal(summary.totalComments, (2 + 4) + 3 + (6 + 6));- assert.equal(summary.totalLikes, (60 + 38) + (5 + 10) + 7);- assert.equal(summary.avgCommentsPerContent, Math.round(21 / 42));- assert.equal(summary.commentShare.youtube, (6 / 21) * 100);+ assert.equal(summary.totalComments, (2 + 9) + 3);+ assert.equal(summary.totalLikes, (5 + 40) + 7);+ assert.equal(summary.avgCommentsPerContent, Math.round(14 / 37));+ assert.equal(summary.commentShare.youtube, (11 / 14) * 100);+ assert.equal(summary.commentShare.instagram, (3 / 14) * 100);assert.equal(summaryOf(accountTotalsOf([]), cacheTotalsOf([], {}), trackedStatsOf([])).likeShare.youtube, 0);});test('account lists sort without changing the input', () => {- assert.deepEqual(sortedByAudience(accounts).map(account => account.id), ['i1', 'y1', 'r1', 'y2']);- assert.deepEqual(sortedByContent(accounts).map(account => account.id), ['y2', 'y1', 'r1', 'i1']);+ assert.deepEqual(sortedByAudience(accounts).map(account => account.id), ['i1', 'y1', 'y2']);+ assert.deepEqual(sortedByContent(accounts).map(account => account.id), ['y2', 'y1', 'i1']);assert.deepEqual(sortedByChannelViews([channel, legacyYt]).map(account => account.id), ['y2', 'y1']);assert.equal(accounts[0], channel);});@@ -74,9 +69,9 @@ test('the overview reports the age of its oldest cached account and ignores accoconst cache = {y1: { cacheWarmed: true, fetchedAt: '2026-11-04T10:00:00Z' },i1: { cacheWarmed: true, fetchedAt: '2026-11-04T08:30:00Z' },- r1: { cacheWarmed: false, syncing: true },+ i2: { cacheWarmed: false, syncing: true },y2: { cacheWarmed: true },};assert.equal(oldestFetchedAt(cache), '2026-11-04T08:30:00Z');- assert.equal(oldestFetchedAt({ r1: { cacheWarmed: false } }), null);+ assert.equal(oldestFetchedAt({ i2: { cacheWarmed: false } }), null);});diff --git a/frontend/tests/features/analytics/overview/overviewTrackedStats.test.ts b/frontend/tests/features/analytics/overview/overviewTrackedStats.test.tsindex 98e1e4b..5e58ece 100644--- a/frontend/tests/features/analytics/overview/overviewTrackedStats.test.ts+++ b/frontend/tests/features/analytics/overview/overviewTrackedStats.test.ts@@ -4,28 +4,22 @@ import { trackedStatsOf, categoryStatsOf } from '../../../../src/features/analytconst tracked = [{ contentType: 'youtube', viewCount: 1000, likeCount: 10, commentCount: 4, category: 'Tech' },- { contentType: 'reddit', manualViews: 200, score: 30, numComments: 5, category: 'Tech' },- { score: 8, numComments: 1, category: 'Art' },+ { contentType: 'youtube', viewCount: 200, likeCount: 30, commentCount: 5, category: 'Tech' },+ { contentType: 'youtube', viewCount: 3000, likeCount: 8, commentCount: 1, category: 'Art' },{ contentType: 'youtube', viewCount: 50 },];-test('tracked stats treat a missing content type as Reddit', () => {+test('tracked stats add up the views, likes and comments of every tracked video', () => {const stats = trackedStatsOf(tracked);assert.equal(stats.total, 4);- assert.equal(stats.ytItems.length, 2);- assert.equal(stats.rdItems.length, 2);- assert.equal(stats.ytViews, 1050);- assert.equal(stats.rdViews, 200);- assert.equal(stats.rdKarma, 38);- assert.equal(stats.rdComments, 6);+ assert.equal(stats.views, 4250);+ assert.equal(stats.likes, 48);+ assert.equal(stats.comments, 10);});-test('category stats are ranked by views plus karma', () => {+test('category stats are ranked by views and leave out videos without a category', () => {const stats = categoryStatsOf(tracked);- assert.deepEqual(stats.map(stat => stat.category), ['Tech', 'Art']);- assert.equal(stats[0].views, 1200);- assert.equal(stats[0].ytCount, 1);- assert.equal(stats[0].rdCount, 1);- assert.equal(stats[1].rdKarma, 8);+ assert.deepEqual(stats.map(stat => stat.category), ['Art', 'Tech']);+ assert.deepEqual(stats[1], { category: 'Tech', count: 2, views: 1200, likes: 40, comments: 9 });assert.deepEqual(categoryStatsOf([{ contentType: 'youtube' }]), []);});