mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-13 01:12:01 +01:00
I am updating the layout node setup to write to its own wave object. The existing setup requires me to plumb the layout updates through every time the tab gets updated, which produces a lot of annoying and unintuitive design patterns. With this new setup, the tab object doesn't get written to when the layout changes, only the layout object will get written to. This prevents collisions when both the tab object and the layout node object are getting updated, such as when a new block is added or deleted.
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
// Copyright 2023, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { Block } from "@/app/block/block";
|
|
import * as WOS from "@/store/wos";
|
|
|
|
import { TileLayout } from "@/faraday/index";
|
|
import { getLayoutStateAtomForTab } from "@/faraday/lib/layoutAtom";
|
|
import { useAtomValue } from "jotai";
|
|
import { useCallback, useMemo } from "react";
|
|
import { CenteredDiv, CenteredLoadingDiv } from "../element/quickelems";
|
|
import "./tab.less";
|
|
|
|
const TabContent = ({ tabId }: { tabId: string }) => {
|
|
const oref = useMemo(() => WOS.makeORef("tab", tabId), [tabId]);
|
|
const loadingAtom = useMemo(() => WOS.getWaveObjectLoadingAtom<Tab>(oref), [oref]);
|
|
const tabLoading = useAtomValue(loadingAtom);
|
|
const tabAtom = useMemo(() => WOS.getWaveObjectAtom<Tab>(oref), [oref]);
|
|
const layoutStateAtom = useMemo(() => getLayoutStateAtomForTab(tabId, tabAtom), [tabAtom, tabId]);
|
|
const tabData = useAtomValue(tabAtom);
|
|
|
|
const renderBlock = useCallback((tabData: TabLayoutData, ready: boolean, onClose: () => void) => {
|
|
// console.log("renderBlock", tabData);
|
|
if (!tabData.blockId || !ready) {
|
|
return null;
|
|
}
|
|
return <Block blockId={tabData.blockId} onClose={onClose} />;
|
|
}, []);
|
|
|
|
const onNodeDelete = useCallback((data: TabLayoutData) => {
|
|
console.log("onNodeDelete", data);
|
|
return WOS.DeleteBlock(data.blockId);
|
|
}, []);
|
|
|
|
if (tabLoading) {
|
|
return <CenteredLoadingDiv />;
|
|
}
|
|
|
|
if (!tabData) {
|
|
return (
|
|
<div className="tabcontent">
|
|
<CenteredDiv>Tab Not Found</CenteredDiv>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="tabcontent">
|
|
<TileLayout
|
|
key={tabId}
|
|
renderContent={renderBlock}
|
|
layoutTreeStateAtom={layoutStateAtom}
|
|
onNodeDelete={onNodeDelete}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export { TabContent };
|