waveterm/frontend/app/tab/tabcontent.tsx
Evan Simkowitz 2e91ee843c
Switch from Less to Scss (#1335)
Less hasn't received an update in over a year and the parser is missing
some modern syntax like relative colors so this switches us to scss
2024-11-21 16:05:04 -08:00

84 lines
2.6 KiB
TypeScript

// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { Block } from "@/app/block/block";
import { CenteredDiv } from "@/element/quickelems";
import { ContentRenderer, NodeModel, PreviewRenderer, TileLayout } from "@/layout/index";
import { TileLayoutContents } from "@/layout/lib/types";
import { atoms, getApi } from "@/store/global";
import * as services from "@/store/services";
import * as WOS from "@/store/wos";
import { atom, useAtomValue } from "jotai";
import * as React from "react";
import { useMemo } from "react";
import "./tabcontent.scss";
const tileGapSizeAtom = atom((get) => {
const settings = get(atoms.settingsAtom);
return settings["window:tilegapsize"];
});
const TabContent = React.memo(({ tabId }: { tabId: string }) => {
const oref = useMemo(() => WOS.makeORef("tab", tabId), [tabId]);
const loadingAtom = useMemo(() => WOS.getWaveObjectLoadingAtom(oref), [oref]);
const tabLoading = useAtomValue(loadingAtom);
const tabAtom = useMemo(() => WOS.getWaveObjectAtom<Tab>(oref), [oref]);
const tabData = useAtomValue(tabAtom);
const tileGapSize = useAtomValue(tileGapSizeAtom);
const tileLayoutContents = useMemo(() => {
const renderContent: ContentRenderer = (nodeModel: NodeModel) => {
return <Block key={nodeModel.blockId} nodeModel={nodeModel} preview={false} />;
};
const renderPreview: PreviewRenderer = (nodeModel: NodeModel) => {
return <Block key={nodeModel.blockId} nodeModel={nodeModel} preview={true} />;
};
function onNodeDelete(data: TabLayoutData) {
return services.ObjectService.DeleteBlock(data.blockId);
}
return {
renderContent,
renderPreview,
tabId,
onNodeDelete,
gapSizePx: tileGapSize,
} as TileLayoutContents;
}, [tabId, tileGapSize]);
if (tabLoading) {
return (
<div className="tabcontent">
<CenteredDiv>Tab Loading</CenteredDiv>
</div>
);
}
if (!tabData) {
return (
<div className="tabcontent">
<CenteredDiv>Tab Not Found</CenteredDiv>
</div>
);
}
if (tabData?.blockids?.length == 0) {
return <div className="tabcontent tabcontent-empty"></div>;
}
return (
<div className="tabcontent">
<TileLayout
key={tabId}
contents={tileLayoutContents}
tabAtom={tabAtom}
getCursorPoint={getApi().getCursorPoint}
/>
</div>
);
});
export { TabContent };