fix: correct script counters to use deduplicated counts (#143)

- Update available scripts counter to deduplicate by slug using Map
- Update downloaded scripts counter to use deduplicated GitHub scripts
- Ensures tab header counts match CategorySidebar counts
- Fixes inconsistency where tab headers showed different numbers than displayed content

Resolves counter discrepancies:
- Available Scripts: now shows deduplicated count (403) instead of raw count (408)
- Downloaded Scripts: now shows deduplicated count matching sidebar display
This commit is contained in:
Michel Roegl-Brunner
2025-10-14 09:50:29 +02:00
committed by GitHub
parent ec9bdf54ba
commit 8efff60025

View File

@@ -70,15 +70,42 @@ export default function Home() {
// Calculate script counts
const scriptCounts = {
available: scriptCardsData?.success ? scriptCardsData.cards?.length ?? 0 : 0,
available: (() => {
if (!scriptCardsData?.success) return 0;
// Deduplicate scripts using Map by slug (same logic as ScriptsGrid.tsx)
const scriptMap = new Map<string, any>();
scriptCardsData.cards?.forEach(script => {
if (script?.name && script?.slug) {
// Use slug as unique identifier, only keep first occurrence
if (!scriptMap.has(script.slug)) {
scriptMap.set(script.slug, script);
}
}
});
return scriptMap.size;
})(),
downloaded: (() => {
if (!scriptCardsData?.success || !localScriptsData?.scripts) return 0;
// Count scripts that are both in GitHub data and have local versions
const githubScripts = scriptCardsData.cards ?? [];
// First deduplicate GitHub scripts using Map by slug
const scriptMap = new Map<string, any>();
scriptCardsData.cards?.forEach(script => {
if (script?.name && script?.slug) {
if (!scriptMap.has(script.slug)) {
scriptMap.set(script.slug, script);
}
}
});
const deduplicatedGithubScripts = Array.from(scriptMap.values());
const localScripts = localScriptsData.scripts ?? [];
return githubScripts.filter(script => {
// Count scripts that are both in deduplicated GitHub data and have local versions
return deduplicatedGithubScripts.filter(script => {
if (!script?.name) return false;
return localScripts.some(local => {
if (!local?.name) return false;