From 76d068aa2321add24bae068e6a2fd26b67bc3bc6 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 6 Sep 2025 16:13:33 +0300 Subject: [PATCH] chore(react/collections/calendar): optimize button building --- apps/client/src/widgets/react/TouchBar.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/client/src/widgets/react/TouchBar.tsx b/apps/client/src/widgets/react/TouchBar.tsx index d948e32a8..80ba8b37a 100644 --- a/apps/client/src/widgets/react/TouchBar.tsx +++ b/apps/client/src/widgets/react/TouchBar.tsx @@ -1,4 +1,4 @@ -import { useContext, useEffect, useState } from "preact/hooks"; +import { useContext, useEffect, useMemo, useState } from "preact/hooks"; import { ParentComponent } from "./react_utils"; import { ComponentChildren, createContext } from "preact"; import { TouchBarItem } from "../../components/touch_bar"; @@ -90,8 +90,6 @@ export default function TouchBar({ children }: TouchBarProps) { } }); - console.log("Touch bar state", isFocused, items); - return ( {children} @@ -129,12 +127,15 @@ export function TouchBarSlider({ label, value, minValue, maxValue, onChange }: S export function TouchBarButton({ label, icon, click, enabled }: ButtonProps) { const api = useContext(TouchBarContext); - - if (api) { - const item = new api.TouchBar.TouchBarButton({ + const item = useMemo(() => { + if (!api) return null; + return new api.TouchBar.TouchBarButton({ label, click, enabled, icon: icon ? buildIcon(api.nativeImage, icon) : undefined }); + }, [ label, icon ]); + + if (item && api) { api.addItem(item); }