Browse Source

refactor: create EventCounts type

master
limina1 8 months ago
parent
commit
9fef709fe5
  1. 3
      src/lib/components/EventKindFilter.svelte
  2. 3
      src/lib/components/EventTypeConfig.svelte
  3. 3
      src/lib/navigator/EventNetwork/Settings.svelte
  4. 3
      src/lib/navigator/EventNetwork/index.svelte
  5. 2
      src/lib/types.ts
  6. 3
      src/routes/visualize/+page.svelte

3
src/lib/components/EventKindFilter.svelte

@ -2,13 +2,14 @@ @@ -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('');

3
src/lib/components/EventTypeConfig.svelte

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
handleAddEventKind,
handleEventKindKeydown
} from '$lib/utils/event_kind_utils';
import type { EventCounts } from "$lib/types";
let {
onReload = () => {},
@ -15,7 +16,7 @@ @@ -15,7 +16,7 @@
profileStats = { totalFetched: 0, displayLimit: 50 }
} = $props<{
onReload?: () => void;
eventCounts?: { [kind: number]: number };
eventCounts?: EventCounts;
profileStats?: { totalFetched: number; displayLimit: number };
}>();

3
src/lib/navigator/EventNetwork/Settings.svelte

@ -3,6 +3,7 @@ @@ -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 @@ @@ -19,7 +20,7 @@
onclear?: () => void;
starVisualization?: boolean;
eventCounts?: { [kind: number]: number };
eventCounts?: EventCounts;
profileStats?: { totalFetched: number; displayLimit: number };
}>();

3
src/lib/navigator/EventNetwork/index.svelte

@ -45,6 +45,7 @@ @@ -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 @@ @@ -84,7 +85,7 @@
onclear?: () => void;
onTagExpansionChange?: (tags: string[]) => void;
profileStats?: { totalFetched: number; displayLimit: number };
allEventCounts?: { [kind: number]: number };
allEventCounts?: EventCounts;
}>();
// Error state

2
src/lib/types.ts

@ -13,3 +13,5 @@ export type TabType = @@ -13,3 +13,5 @@ export type TabType =
| "user"
| "settings"
| "editor";
export type EventCounts = { [kind: number]: number };

3
src/routes/visualize/+page.svelte

@ -27,6 +27,7 @@ @@ -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 @@ @@ -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;

Loading…
Cancel
Save