A very performant and light (2mb in memory) link shortener and tracker. Written in Rust and React and uses Postgres/SQLite.

Fix source count in statistics

Changed files
+17 -5
frontend
src
components
+17 -5
frontend/src/components/StatisticsModal.tsx
···
} from "recharts";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { toast } from "@/hooks/use-toast";
-
import { useState, useEffect } from "react";
+
import { useState, useEffect, useMemo } from "react";
import { getLinkClickStats, getLinkSourceStats } from "../api/client";
import { ClickStats, SourceStats } from "../types/api";
···
}
}, [isOpen, linkId]);
+
const aggregatedSources = useMemo(() => {
+
const sourceMap = sourcesData.reduce<Record<string, number>>(
+
(acc, { source, count }) => ({
+
...acc,
+
[source]: (acc[source] || 0) + count
+
}),
+
{}
+
);
+
+
return Object.entries(sourceMap)
+
.map(([source, count]) => ({ source, count }))
+
.sort((a, b) => b.count - a.count);
+
}, [sourcesData]);
+
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent className="max-w-3xl">
···
</CardHeader>
<CardContent>
<ul className="space-y-2">
-
{sourcesData.map((source, index) => (
+
{aggregatedSources.map((source, index) => (
<li
key={source.source}
className="flex items-center justify-between py-2 border-b last:border-0"
···
</span>
{source.source}
</span>
-
<span className="text-sm font-medium">
-
{source.count} clicks
-
</span>
+
<span className="text-sm font-medium">{source.count} clicks</span>
</li>
))}
</ul>