Skip to content

Commit 8efff60

Browse files
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
1 parent ec9bdf5 commit 8efff60

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/app/page.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,42 @@ export default function Home() {
7070

7171
// Calculate script counts
7272
const scriptCounts = {
73-
available: scriptCardsData?.success ? scriptCardsData.cards?.length ?? 0 : 0,
73+
available: (() => {
74+
if (!scriptCardsData?.success) return 0;
75+
76+
// Deduplicate scripts using Map by slug (same logic as ScriptsGrid.tsx)
77+
const scriptMap = new Map<string, any>();
78+
79+
scriptCardsData.cards?.forEach(script => {
80+
if (script?.name && script?.slug) {
81+
// Use slug as unique identifier, only keep first occurrence
82+
if (!scriptMap.has(script.slug)) {
83+
scriptMap.set(script.slug, script);
84+
}
85+
}
86+
});
87+
88+
return scriptMap.size;
89+
})(),
7490
downloaded: (() => {
7591
if (!scriptCardsData?.success || !localScriptsData?.scripts) return 0;
7692

77-
// Count scripts that are both in GitHub data and have local versions
78-
const githubScripts = scriptCardsData.cards ?? [];
93+
// First deduplicate GitHub scripts using Map by slug
94+
const scriptMap = new Map<string, any>();
95+
96+
scriptCardsData.cards?.forEach(script => {
97+
if (script?.name && script?.slug) {
98+
if (!scriptMap.has(script.slug)) {
99+
scriptMap.set(script.slug, script);
100+
}
101+
}
102+
});
103+
104+
const deduplicatedGithubScripts = Array.from(scriptMap.values());
79105
const localScripts = localScriptsData.scripts ?? [];
80106

81-
return githubScripts.filter(script => {
107+
// Count scripts that are both in deduplicated GitHub data and have local versions
108+
return deduplicatedGithubScripts.filter(script => {
82109
if (!script?.name) return false;
83110
return localScripts.some(local => {
84111
if (!local?.name) return false;

0 commit comments

Comments
 (0)