mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-06-07 23:43:57 +02:00
refactor: cleanup bandwidth tracking functionality
This commit is contained in:
@@ -884,7 +884,10 @@ export function ProfilesDataTable({
|
||||
const newSnapshots: Record<string, TrafficSnapshot> = {};
|
||||
for (const snapshot of allSnapshots) {
|
||||
if (snapshot.profile_id) {
|
||||
newSnapshots[snapshot.profile_id] = snapshot;
|
||||
const existing = newSnapshots[snapshot.profile_id];
|
||||
if (!existing || snapshot.last_update > existing.last_update) {
|
||||
newSnapshots[snapshot.profile_id] = snapshot;
|
||||
}
|
||||
}
|
||||
}
|
||||
setTrafficSnapshots(newSnapshots);
|
||||
@@ -1693,13 +1696,17 @@ export function ProfilesDataTable({
|
||||
if (isRunning && meta.trafficSnapshots) {
|
||||
// Find the traffic snapshot for this profile by matching profile_id
|
||||
const snapshot = meta.trafficSnapshots[profile.id];
|
||||
const bandwidthData = snapshot?.recent_bandwidth || [];
|
||||
// Create a new array reference to ensure React detects changes
|
||||
const bandwidthData = snapshot?.recent_bandwidth
|
||||
? [...snapshot.recent_bandwidth]
|
||||
: [];
|
||||
const currentBandwidth =
|
||||
(snapshot?.current_bytes_sent || 0) +
|
||||
(snapshot?.current_bytes_received || 0);
|
||||
|
||||
return (
|
||||
<BandwidthMiniChart
|
||||
key={`${profile.id}-${snapshot?.last_update || 0}-${bandwidthData.length}`}
|
||||
data={bandwidthData}
|
||||
currentBandwidth={currentBandwidth}
|
||||
onClick={() => meta.onOpenTrafficDialog?.(profile.id)}
|
||||
|
||||
@@ -83,8 +83,16 @@ export function TrafficDetailsDialog({
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
const allStats = await invoke<TrafficStats[]>("get_all_traffic_stats");
|
||||
const profileStats = allStats.find((s) => s.profile_id === profileId);
|
||||
setStats(profileStats || null);
|
||||
const matchingStats = allStats.filter(
|
||||
(s) => s.profile_id === profileId,
|
||||
);
|
||||
const profileStats =
|
||||
matchingStats.length > 0
|
||||
? matchingStats.reduce((latest, current) =>
|
||||
current.last_update > latest.last_update ? current : latest,
|
||||
)
|
||||
: null;
|
||||
setStats(profileStats);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch traffic stats:", error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user