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
refactor(react/ribbon): bring back tab activation
Elian Doran0c8bfc39ef65
diff --git a/apps/client/src/widgets/ribbon/Ribbon.tsx b/apps/client/src/widgets/ribbon/Ribbon.tsxindex 7d0bc777ba..e439529f34 100644--- a/apps/client/src/widgets/ribbon/Ribbon.tsx+++ b/apps/client/src/widgets/ribbon/Ribbon.tsx@@ -1,4 +1,4 @@-import { useMemo, useState } from "preact/hooks";+import { useEffect, useMemo, useState } from "preact/hooks";import { t } from "../../services/i18n";import { useNoteContext } from "../react/hooks";import "./style.css";@@ -162,6 +162,14 @@ export default function Ribbon() {const [ activeTabIndex, setActiveTabIndex ] = useState<number | undefined>();const filteredTabs = useMemo(() => TAB_CONFIGURATION.filter(tab => typeof tab.show === "boolean" ? tab.show : tab.show?.(titleContext)), [ titleContext, note ]);+ // Automatically activate the first ribbon tab that needs to be activated whenever a note changes.+ useEffect(() => {+ const tabToActivate = filteredTabs.find(tab => typeof tab.activate === "boolean" ? tab.activate : tab.activate?.(titleContext));+ if (tabToActivate) {+ setActiveTabIndex(tabToActivate.index);+ }+ }, [ note?.noteId ]);+return (<div className="ribbon-container" style={{ contain: "none" }}><div className="ribbon-top-row">