From 9fef709fe51ef7adc5db360dee5e68cb28d3655f Mon Sep 17 00:00:00 2001 From: limina1 Date: Wed, 23 Jul 2025 21:00:17 -0400 Subject: [PATCH] refactor: create EventCounts type --- src/lib/components/EventKindFilter.svelte | 3 ++- src/lib/components/EventTypeConfig.svelte | 3 ++- src/lib/navigator/EventNetwork/Settings.svelte | 3 ++- src/lib/navigator/EventNetwork/index.svelte | 3 ++- src/lib/types.ts | 2 ++ src/routes/visualize/+page.svelte | 3 ++- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/components/EventKindFilter.svelte b/src/lib/components/EventKindFilter.svelte index 63087a9..f13429f 100644 --- a/src/lib/components/EventKindFilter.svelte +++ b/src/lib/components/EventKindFilter.svelte @@ -2,13 +2,14 @@ import { visualizationConfig } from '$lib/stores/visualizationConfig'; import { Button, Badge } from 'flowbite-svelte'; import { CloseCircleOutline } from 'flowbite-svelte-icons'; + import type { EventCounts } from "$lib/types"; let { onReload = () => {}, eventCounts = {} } = $props<{ onReload?: () => void; - eventCounts?: { [kind: number]: number }; + eventCounts?: EventCounts; }>(); let newKind = $state(''); diff --git a/src/lib/components/EventTypeConfig.svelte b/src/lib/components/EventTypeConfig.svelte index 0330b89..4d7bfc7 100644 --- a/src/lib/components/EventTypeConfig.svelte +++ b/src/lib/components/EventTypeConfig.svelte @@ -8,6 +8,7 @@ handleAddEventKind, handleEventKindKeydown } from '$lib/utils/event_kind_utils'; + import type { EventCounts } from "$lib/types"; let { onReload = () => {}, @@ -15,7 +16,7 @@ profileStats = { totalFetched: 0, displayLimit: 50 } } = $props<{ onReload?: () => void; - eventCounts?: { [kind: number]: number }; + eventCounts?: EventCounts; profileStats?: { totalFetched: number; displayLimit: number }; }>(); diff --git a/src/lib/navigator/EventNetwork/Settings.svelte b/src/lib/navigator/EventNetwork/Settings.svelte index e48e3c3..584834b 100644 --- a/src/lib/navigator/EventNetwork/Settings.svelte +++ b/src/lib/navigator/EventNetwork/Settings.svelte @@ -3,6 +3,7 @@ import EventTypeConfig from "$lib/components/EventTypeConfig.svelte"; import { visualizationConfig } from "$lib/stores/visualizationConfig"; import { Toggle } from "flowbite-svelte"; + import type { EventCounts } from "$lib/types"; let { count = 0, @@ -19,7 +20,7 @@ onclear?: () => void; starVisualization?: boolean; - eventCounts?: { [kind: number]: number }; + eventCounts?: EventCounts; profileStats?: { totalFetched: number; displayLimit: number }; }>(); diff --git a/src/lib/navigator/EventNetwork/index.svelte b/src/lib/navigator/EventNetwork/index.svelte index 992204b..c9a8149 100644 --- a/src/lib/navigator/EventNetwork/index.svelte +++ b/src/lib/navigator/EventNetwork/index.svelte @@ -45,6 +45,7 @@ import { Button } from "flowbite-svelte"; import { visualizationConfig } from "$lib/stores/visualizationConfig"; import { get } from "svelte/store"; + import type { EventCounts } from "$lib/types"; // Type alias for D3 selections type Selection = any; @@ -84,7 +85,7 @@ onclear?: () => void; onTagExpansionChange?: (tags: string[]) => void; profileStats?: { totalFetched: number; displayLimit: number }; - allEventCounts?: { [kind: number]: number }; + allEventCounts?: EventCounts; }>(); // Error state diff --git a/src/lib/types.ts b/src/lib/types.ts index 06e130c..54f58f4 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -13,3 +13,5 @@ export type TabType = | "user" | "settings" | "editor"; + +export type EventCounts = { [kind: number]: number }; diff --git a/src/routes/visualize/+page.svelte b/src/routes/visualize/+page.svelte index 8dc16d7..91925ec 100644 --- a/src/routes/visualize/+page.svelte +++ b/src/routes/visualize/+page.svelte @@ -27,6 +27,7 @@ fetchProfilesForNewEvents } from "$lib/utils/tag_event_fetch"; import { deduplicateAndCombineEvents } from "$lib/utils/eventDeduplication"; + import type { EventCounts } from "$lib/types"; // Configuration const DEBUG = true; // Set to true to enable debug logging @@ -94,7 +95,7 @@ // Event counts from all events (not just filtered) let allEventCounts = $derived.by(() => { - const counts: { [kind: number]: number } = {}; + const counts: EventCounts = {}; allEvents.forEach((event: NDKEvent) => { if (event.kind !== undefined) { counts[event.kind] = (counts[event.kind] || 0) + 1;