···
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { toast } from "@/hooks/use-toast";
13
-
import { useState, useEffect } from "react";
13
+
import { useState, useEffect, useMemo } from "react";
import { getLinkClickStats, getLinkSourceStats } from "../api/client";
import { ClickStats, SourceStats } from "../types/api";
···
100
+
const aggregatedSources = useMemo(() => {
101
+
const sourceMap = sourcesData.reduce<Record<string, number>>(
102
+
(acc, { source, count }) => ({
104
+
[source]: (acc[source] || 0) + count
109
+
return Object.entries(sourceMap)
110
+
.map(([source, count]) => ({ source, count }))
111
+
.sort((a, b) => b.count - a.count);
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent className="max-w-3xl">
···
<ul className="space-y-2">
141
-
{sourcesData.map((source, index) => (
155
+
{aggregatedSources.map((source, index) => (
className="flex items-center justify-between py-2 border-b last:border-0"
···
152
-
<span className="text-sm font-medium">
153
-
{source.count} clicks
166
+
<span className="text-sm font-medium">{source.count} clicks</span>