refactor(react/ribbon): bring back tab activation

This commit is contained in:
Elian Doran 2025-08-24 12:23:25 +03:00
parent 3815fddb27
commit 0c8bfc39ef
No known key found for this signature in database

View File

@ -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">