mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 17:08:58 +01:00
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { TabContext } from "./ribbon-interface";
|
|
import { useElementSize, useLegacyWidget, useWindowSize } from "../react/hooks";
|
|
import ActionButton from "../react/ActionButton";
|
|
import { t } from "../../services/i18n";
|
|
import { useEffect, useRef, useState } from "preact/hooks";
|
|
import NoteMap from "../note_map/NoteMap";
|
|
|
|
const SMALL_SIZE_HEIGHT = "300px";
|
|
|
|
export default function NoteMapTab({ noteContext }: TabContext) {
|
|
const [ isExpanded, setExpanded ] = useState(false);
|
|
const [ height, setHeight ] = useState(SMALL_SIZE_HEIGHT);
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
const { windowHeight } = useWindowSize();
|
|
const containerSize = useElementSize(containerRef);
|
|
|
|
useEffect(() => {
|
|
if (isExpanded && containerRef.current && containerSize) {
|
|
const height = windowHeight - containerSize.top;
|
|
setHeight(height + "px");
|
|
} else {
|
|
setHeight(SMALL_SIZE_HEIGHT);
|
|
}
|
|
}, [ isExpanded, containerRef, windowHeight, containerSize?.top ]);
|
|
// useEffect(() => noteMapWidget.setDimensions(), [ containerSize?.width, height ]);
|
|
|
|
return (
|
|
<div className="note-map-ribbon-widget" style={{ height }} ref={containerRef}>
|
|
<NoteMap />
|
|
|
|
{!isExpanded ? (
|
|
<ActionButton
|
|
icon="bx bx-arrow-to-bottom"
|
|
text={t("note_map.open_full")}
|
|
className="open-full-button"
|
|
onClick={() => setExpanded(true)}
|
|
/>
|
|
) : (
|
|
<ActionButton
|
|
icon="bx bx-arrow-to-top"
|
|
text={t("note_map.collapse")}
|
|
className="collapse-button"
|
|
onClick={() => setExpanded(false)}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|