From 72a9ac225747a985d03044b960c04f995c344d13 Mon Sep 17 00:00:00 2001 From: lars-berger Date: Wed, 27 Nov 2024 22:39:29 +0800 Subject: [PATCH] feat: add count of how many widgets are open to settings UI sidebar --- .../src/configs/WidgetConfigSidebar.tsx | 38 ++++++++++++++++--- .../settings-ui/src/configs/WidgetConfigs.tsx | 1 + 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/settings-ui/src/configs/WidgetConfigSidebar.tsx b/packages/settings-ui/src/configs/WidgetConfigSidebar.tsx index bed659fa..d2e6fcd4 100644 --- a/packages/settings-ui/src/configs/WidgetConfigSidebar.tsx +++ b/packages/settings-ui/src/configs/WidgetConfigSidebar.tsx @@ -1,15 +1,17 @@ import { + Badge, cn, Collapsible, CollapsibleContent, CollapsibleTrigger, } from '@glzr/components'; import { IconChevronDown, IconDiamonds } from '@tabler/icons-solidjs'; -import { createMemo, For } from 'solid-js'; -import { WidgetConfig } from 'zebar'; +import { createMemo, For, Show } from 'solid-js'; +import { Widget, WidgetConfig } from 'zebar'; export interface WidgetConfigSidebarProps { configs: Record; + widgetStates: Record; selectedConfig: WidgetConfig | null; selectedConfigPath: string | null; onSelect: (configPath: string) => void; @@ -33,6 +35,17 @@ export function WidgetConfigSidebar(props: WidgetConfigSidebarProps) { return tree; }); + const widgetCounts = createMemo(() => { + const counts = new Map(); + + Object.values(props.widgetStates).forEach(state => { + const current = counts.get(state.configPath) ?? 0; + counts.set(state.configPath, current + 1); + }); + + return counts; + }); + return (

Widget configs

@@ -40,9 +53,9 @@ export function WidgetConfigSidebar(props: WidgetConfigSidebarProps) { {([folder, configs]) => ( - - - {folder} + + + {folder} @@ -50,7 +63,7 @@ export function WidgetConfigSidebar(props: WidgetConfigSidebarProps) { {([configPath]) => (
+ + {widgetCounts().get(configPath)} + +
)} diff --git a/packages/settings-ui/src/configs/WidgetConfigs.tsx b/packages/settings-ui/src/configs/WidgetConfigs.tsx index 780023cf..31ba7a9a 100644 --- a/packages/settings-ui/src/configs/WidgetConfigs.tsx +++ b/packages/settings-ui/src/configs/WidgetConfigs.tsx @@ -172,6 +172,7 @@ export function WidgetConfigs() { {/* Sidebar. */}