From cb209564459c300e9c88661a1aa5c99c364706b9 Mon Sep 17 00:00:00 2001 From: Alex P Date: Wed, 27 Aug 2025 18:33:52 +0000 Subject: [PATCH] refactor(AudioControlPopover): simplify audio metrics display and remove unused code Remove advanced metrics toggle and related complex display logic, replacing it with a simplified quick status summary. Also clean up unused imports, state variables, and helper functions. --- .../popovers/AudioControlPopover.tsx | 200 ++++-------------- 1 file changed, 44 insertions(+), 156 deletions(-) diff --git a/ui/src/components/popovers/AudioControlPopover.tsx b/ui/src/components/popovers/AudioControlPopover.tsx index fb3364b..51836de 100644 --- a/ui/src/components/popovers/AudioControlPopover.tsx +++ b/ui/src/components/popovers/AudioControlPopover.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { MdVolumeOff, MdVolumeUp, MdGraphicEq, MdMic, MdMicOff, MdRefresh } from "react-icons/md"; -import { LuActivity, LuSettings, LuSignal } from "react-icons/lu"; +import { LuActivity, LuSignal } from "react-icons/lu"; import { Button } from "@components/Button"; import { AudioLevelMeter } from "@components/AudioLevelMeter"; @@ -11,7 +11,6 @@ import { useAudioLevel } from "@/hooks/useAudioLevel"; import { useAudioEvents } from "@/hooks/useAudioEvents"; import api from "@/api"; import notifications from "@/notifications"; -import { AUDIO_CONFIG } from "@/config/constants"; import audioQualityService from "@/services/audioQualityService"; // Type for microphone error @@ -54,7 +53,7 @@ interface AudioControlPopoverProps { export default function AudioControlPopover({ microphone, open }: AudioControlPopoverProps) { const [currentConfig, setCurrentConfig] = useState(null); const [currentMicrophoneConfig, setCurrentMicrophoneConfig] = useState(null); - const [showAdvanced, setShowAdvanced] = useState(false); + const [isLoading, setIsLoading] = useState(false); // Add cache flags to prevent unnecessary API calls @@ -274,17 +273,7 @@ export default function AudioControlPopover({ microphone, open }: AudioControlPo } }; - const formatBytes = (bytes: number) => { - if (bytes === 0) return "0 B"; - const k = 1024; - const sizes = ["B", "KB", "MB", "GB"]; - const i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i]; - }; - const formatNumber = (num: number) => { - return new Intl.NumberFormat().format(num); - }; return (
@@ -575,152 +564,51 @@ export default function AudioControlPopover({ microphone, open }: AudioControlPo )}
- {/* Advanced Controls Toggle */} - - - {/* Advanced Metrics */} - {showAdvanced && ( -
-
- - - Performance Metrics - -
- - {metrics ? ( - <> -
-

Audio Output

-
-
-
Frames Received
-
- {formatNumber(metrics.frames_received)} -
-
- -
-
Frames Dropped
-
0 - ? "text-red-600 dark:text-red-400" - : "text-green-600 dark:text-green-400" - )}> - {formatNumber(metrics.frames_dropped)} -
-
- -
-
Data Processed
-
- {formatBytes(metrics.bytes_processed)} -
-
- -
-
Connection Drops
-
0 - ? "text-red-600 dark:text-red-400" - : "text-green-600 dark:text-green-400" - )}> - {formatNumber(metrics.connection_drops)} -
-
-
-
- - {micMetrics && ( -
-

Microphone Input

-
-
-
Frames Sent
-
- {formatNumber(micMetrics.frames_sent)} -
-
- -
-
Frames Dropped
-
0 - ? "text-red-600 dark:text-red-400" - : "text-green-600 dark:text-green-400" - )}> - {formatNumber(micMetrics.frames_dropped)} -
-
- -
-
Data Processed
-
- {formatBytes(micMetrics.bytes_processed)} -
-
- -
-
Connection Drops
-
0 - ? "text-red-600 dark:text-red-400" - : "text-green-600 dark:text-green-400" - )}> - {formatNumber(micMetrics.connection_drops)} -
-
-
-
- )} - - {metrics.frames_received > 0 && ( -
-
Drop Rate
-
AUDIO_CONFIG.DROP_RATE_CRITICAL_THRESHOLD - ? "text-red-600 dark:text-red-400" - : ((metrics.frames_dropped / metrics.frames_received) * AUDIO_CONFIG.PERCENTAGE_MULTIPLIER) > AUDIO_CONFIG.DROP_RATE_WARNING_THRESHOLD - ? "text-yellow-600 dark:text-yellow-400" - : "text-green-600 dark:text-green-400" - )}> - {((metrics.frames_dropped / metrics.frames_received) * AUDIO_CONFIG.PERCENTAGE_MULTIPLIER).toFixed(AUDIO_CONFIG.PERCENTAGE_DECIMAL_PLACES)}% -
-
- )} - -
- Last updated: {new Date().toLocaleTimeString()} -
- - ) : ( -
-
- Loading metrics... + + {metrics ? ( +
+
+
0 + ? "text-red-600 dark:text-red-400" + : "text-green-600 dark:text-green-400" + )}> + {metrics.frames_dropped > 0 ? "Issues" : "Good"}
+
Audio Output
- )} -
- )} + + {micMetrics && ( +
+
0 + ? "text-red-600 dark:text-red-400" + : "text-green-600 dark:text-green-400" + )}> + {micMetrics.frames_dropped > 0 ? "Issues" : "Good"} +
+
Microphone
+
+ )} +
+ ) : ( +
+
+ No data available +
+
+ )} +
{/* Audio Metrics Dashboard Button */}