mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 14:25:51 +01:00
chore(react/collections/calendar): optimize button building
This commit is contained in:
@@ -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 { ParentComponent } from "./react_utils";
|
||||||
import { ComponentChildren, createContext } from "preact";
|
import { ComponentChildren, createContext } from "preact";
|
||||||
import { TouchBarItem } from "../../components/touch_bar";
|
import { TouchBarItem } from "../../components/touch_bar";
|
||||||
@@ -90,8 +90,6 @@ export default function TouchBar({ children }: TouchBarProps) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Touch bar state", isFocused, items);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchBarContext.Provider value={api}>
|
<TouchBarContext.Provider value={api}>
|
||||||
{children}
|
{children}
|
||||||
@@ -129,12 +127,15 @@ export function TouchBarSlider({ label, value, minValue, maxValue, onChange }: S
|
|||||||
|
|
||||||
export function TouchBarButton({ label, icon, click, enabled }: ButtonProps) {
|
export function TouchBarButton({ label, icon, click, enabled }: ButtonProps) {
|
||||||
const api = useContext(TouchBarContext);
|
const api = useContext(TouchBarContext);
|
||||||
|
const item = useMemo(() => {
|
||||||
if (api) {
|
if (!api) return null;
|
||||||
const item = new api.TouchBar.TouchBarButton({
|
return new api.TouchBar.TouchBarButton({
|
||||||
label, click, enabled,
|
label, click, enabled,
|
||||||
icon: icon ? buildIcon(api.nativeImage, icon) : undefined
|
icon: icon ? buildIcon(api.nativeImage, icon) : undefined
|
||||||
});
|
});
|
||||||
|
}, [ label, icon ]);
|
||||||
|
|
||||||
|
if (item && api) {
|
||||||
api.addItem(item);
|
api.addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user