From 0ddf25bb444fca6fa619a5ffdecdeb6140eb3ae1 Mon Sep 17 00:00:00 2001 From: Tommaso Casaburi Date: Thu, 23 Jul 2026 16:27:59 +0700 Subject: [PATCH] fix(home stats): include replies in total post count --- src/views/home/__tests__/home.test.tsx | 14 +++++++------- src/views/home/home.tsx | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/views/home/__tests__/home.test.tsx b/src/views/home/__tests__/home.test.tsx index 1c221813..a581ac89 100644 --- a/src/views/home/__tests__/home.test.tsx +++ b/src/views/home/__tests__/home.test.tsx @@ -19,7 +19,7 @@ const testState = vi.hoisted(() => ({ setStatsScopeMock: vi.fn(), statsScope: 'directory' as 'directory' | 'all', communities: {} as Record, - communityStats: {} as Record, + communityStats: {} as Record, feedStateString: 'Downloading boards', })); @@ -145,8 +145,8 @@ describe('Home', () => { 'tech-posting.eth': { address: 'tech-posting.eth' }, }; testState.communityStats = { - 'music-posting.eth': { allPostCount: 5, weekActiveUserCount: 2 }, - 'tech-posting.eth': { allPostCount: 7, weekActiveUserCount: 5 }, + 'music-posting.eth': { allPostCount: 5, allReplyCount: 3, weekActiveUserCount: 2 }, + 'tech-posting.eth': { allPostCount: 7, allReplyCount: 4, weekActiveUserCount: 5 }, }; testState.feedStateString = 'Downloading boards'; testState.statsScope = 'directory'; @@ -179,7 +179,7 @@ describe('Home', () => { expect(container.textContent).not.toContain('loaded 2/2 boards p2p'); expect(container.querySelector('.yellowOfflineIcon')).toBeNull(); expect(container.querySelectorAll('[data-testid="loading-ellipsis"]')).toHaveLength(0); - expect(container.textContent).toContain('total_posts 12'); + expect(container.textContent).toContain('total_posts 19'); expect(container.textContent).toContain('current_users 7'); expect(container.textContent).toContain('boards_loaded 2'); expect(container.querySelector('[data-testid="site-legal-meta"]')?.textContent).toBe('site-legal-meta'); @@ -232,8 +232,8 @@ describe('Home', () => { }, }; testState.communityStats = { - 'backup-business.bso': { allPostCount: 11, weekActiveUserCount: 3 }, - 'tech-posting.eth': { allPostCount: 7, weekActiveUserCount: 4 }, + 'backup-business.bso': { allPostCount: 11, allReplyCount: 13, weekActiveUserCount: 3 }, + 'tech-posting.eth': { allPostCount: 7, allReplyCount: 2, weekActiveUserCount: 4 }, }; renderHome(); @@ -245,7 +245,7 @@ describe('Home', () => { expect(container.querySelector('.yellowOfflineIcon')).not.toBeNull(); expect(container.querySelectorAll('[data-testid="loading-ellipsis"]')).toHaveLength(0); expect(container.textContent).not.toContain('loaded 2/3 boards p2p'); - expect(container.textContent).toContain('total_posts 18'); + expect(container.textContent).toContain('total_posts 33'); expect(container.textContent).toContain('current_users 7'); expect(container.textContent).toContain('boards_loaded 2'); }); diff --git a/src/views/home/home.tsx b/src/views/home/home.tsx index 02bb5399..0bbe6ead 100644 --- a/src/views/home/home.tsx +++ b/src/views/home/home.tsx @@ -102,6 +102,7 @@ const InfoBox = () => { type HomepageStats = { allPostCount?: number; + allReplyCount?: number; weekActiveUserCount?: number; state?: string; }; @@ -237,7 +238,7 @@ const Stats = ({ directories }: { directories: DirectoryCommunity[] }) => { boardsLoaded++; if (hasLoadedStats(stats)) { boardsWithStats++; - totalPosts += stats.allPostCount || 0; + totalPosts += stats.allPostCount + (stats.allReplyCount ?? 0); currentUsers += stats.weekActiveUserCount || 0; } }