Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(client): fix type error due to React integration
Elian Doraned320e4e24bb
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex c968e7498b..1110f4e1b8 100644--- a/apps/client/src/widgets/react/hooks.tsx+++ b/apps/client/src/widgets/react/hooks.tsx@@ -504,6 +504,24 @@ export function useTooltip(elRef: RefObject<HTMLElement>, config: Partial<Tooltireturn { showTooltip, hideTooltip };}+/**+ * Similar to {@link useTooltip}, but doesn't expose methods to imperatively hide or show the tooltip.+ *+ * @param elRef the element to bind the tooltip to.+ * @param config optionally, the tooltip configuration.+ */+export function useStaticTooltip(elRef: RefObject<HTMLElement>, config?: Partial<Tooltip.Options>) {+ useEffect(() => {+ if (!elRef?.current) return;++ const $el = $(elRef.current);+ $el.tooltip(config);+ return () => {+ $el.tooltip("dispose");+ }+ }, [ elRef, config ]);+}+// eslint-disable-next-line @typescript-eslint/no-unsafe-function-typeexport function useLegacyImperativeHandlers(handlers: Record<string, Function>) {const parentComponent = useContext(ParentComponent);diff --git a/apps/client/src/widgets/ribbon/Ribbon.tsx b/apps/client/src/widgets/ribbon/Ribbon.tsxindex bf1b310aad..cbdd2f619f 100644--- a/apps/client/src/widgets/ribbon/Ribbon.tsx+++ b/apps/client/src/widgets/ribbon/Ribbon.tsx@@ -1,6 +1,6 @@-import { useCallback, useEffect, useMemo, useState } from "preact/hooks";+import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";import { t } from "../../services/i18n";-import { useNoteContext, useTriliumEvents } from "../react/hooks";+import { useNoteContext, useStaticTooltip, useTooltip, useTriliumEvents } from "../react/hooks";import "./style.css";import { VNode } from "preact";import BasicPropertiesTab from "./BasicPropertiesTab";@@ -233,6 +233,9 @@ export default function Ribbon() {}function RibbonTab({ icon, title, active, onClick }: { icon: string; title: string; active: boolean, onClick: () => void }) {+ const iconRef = useRef<HTMLDivElement>(null);+ useStaticTooltip(iconRef, { });+return (<><div@@ -240,6 +243,7 @@ function RibbonTab({ icon, title, active, onClick }: { icon: string; title: strionClick={onClick}><span+ ref={iconRef}className={`ribbon-tab-title-icon ${icon}`}title={title}/>