mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	refactor(react/ribbon): bring back tab activation
This commit is contained in:
		@@ -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">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user