From d17dc5558cbed272ff55172f91c32c02d20d9223 Mon Sep 17 00:00:00 2001 From: JSC Date: Sat, 27 Sep 2025 21:38:07 +0200 Subject: [PATCH] feat: add TTS statistics to DashboardPage and StatisticsGrid components --- src/components/dashboard/StatisticsGrid.tsx | 54 ++++++++++++++++++++- src/pages/DashboardPage.tsx | 31 ++++++++++-- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/components/dashboard/StatisticsGrid.tsx b/src/components/dashboard/StatisticsGrid.tsx index 75fb24a..00f1e56 100644 --- a/src/components/dashboard/StatisticsGrid.tsx +++ b/src/components/dashboard/StatisticsGrid.tsx @@ -2,7 +2,7 @@ import { StatisticCard } from '@/components/dashboard/StatisticCard' import { NumberFlowDuration } from '@/components/ui/number-flow-duration' import { NumberFlowSize } from '@/components/ui/number-flow-size' import NumberFlow from '@number-flow/react' -import { Clock, HardDrive, Music, Play, Volume2 } from 'lucide-react' +import { Clock, HardDrive, Music, Play, Volume2, MessageSquare } from 'lucide-react' interface SoundboardStatistics { sound_count: number @@ -18,12 +18,20 @@ interface TrackStatistics { total_size: number } +interface TTSStatistics { + sound_count: number + total_play_count: number + total_duration: number + total_size: number +} + interface StatisticsGridProps { soundboardStatistics: SoundboardStatistics trackStatistics: TrackStatistics + ttsStatistics: TTSStatistics } -export function StatisticsGrid({ soundboardStatistics, trackStatistics }: StatisticsGridProps) { +export function StatisticsGrid({ soundboardStatistics, trackStatistics, ttsStatistics }: StatisticsGridProps) { return (
@@ -109,6 +117,48 @@ export function StatisticsGrid({ soundboardStatistics, trackStatistics }: Statis />
+ +
+

+ TTS Statistics +

+
+ } + description="Text-to-speech audio files" + /> + } + description="All-time play count" + /> + + } + description="Combined TTS duration" + /> + + } + description="Original + normalized files" + /> +
+
) } \ No newline at end of file diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx index 1413950..dc29e13 100644 --- a/src/pages/DashboardPage.tsx +++ b/src/pages/DashboardPage.tsx @@ -19,6 +19,13 @@ interface TrackStatistics { total_size: number } +interface TTSStatistics { + sound_count: number + total_play_count: number + total_duration: number + total_size: number +} + interface TopSound { id: number name: string @@ -33,6 +40,8 @@ export function DashboardPage() { useState(null) const [trackStatistics, setTrackStatistics] = useState(null) + const [ttsStatistics, setTtsStatistics] = + useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) @@ -74,6 +83,19 @@ export function DashboardPage() { const trackData = await trackResponse.json() setTrackStatistics(trackData) + // Fetch TTS statistics separately to avoid Promise.all failures + const ttsResponse = await fetch('/api/v1/dashboard/tts-statistics', { + credentials: 'include' + }) + + if (!ttsResponse.ok) { + const errorText = await ttsResponse.text() + throw new Error(`Failed to fetch TTS statistics: ${errorText}`) + } + + const ttsData = await ttsResponse.json() + setTtsStatistics(ttsData) + } catch (err) { console.error('Dashboard statistics error:', err) setError(err instanceof Error ? err.message : 'An error occurred') @@ -174,13 +196,13 @@ export function DashboardPage() { useEffect(() => { const interval = setInterval(() => { // Only auto-refresh if not currently loading or in error state - if (!loading && !refreshing && (!error || (soundboardStatistics && trackStatistics))) { + if (!loading && !refreshing && (!error || (soundboardStatistics && trackStatistics && ttsStatistics))) { refreshAll() } }, 30000) // Increased to 30 seconds return () => clearInterval(interval) - }, [refreshAll, loading, refreshing, error, soundboardStatistics, trackStatistics]) + }, [refreshAll, loading, refreshing, error, soundboardStatistics, trackStatistics, ttsStatistics]) useEffect(() => { fetchTopSounds(true) // Show loading on initial load and filter changes @@ -190,7 +212,7 @@ export function DashboardPage() { return } - if (error && (!soundboardStatistics || !trackStatistics)) { + if (error && (!soundboardStatistics || !trackStatistics || !ttsStatistics)) { return } @@ -204,10 +226,11 @@ export function DashboardPage() {
- {soundboardStatistics && trackStatistics && ( + {soundboardStatistics && trackStatistics && ttsStatistics && ( )}