-
-
Notifications
You must be signed in to change notification settings - Fork 927
Expand file tree
/
Copy pathtabcontent.tsx
More file actions
76 lines (65 loc) · 2.66 KB
/
tabcontent.tsx
File metadata and controls
76 lines (65 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2025, 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";
const tileGapSizeAtom = atom((get) => {
const settings = get(atoms.settingsAtom);
return settings["window:tilegapsize"];
});
const TabContent = React.memo(({ tabId, noTopPadding }: { tabId: string; noTopPadding?: boolean }) => {
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]);
let innerContent;
if (tabLoading) {
innerContent = <CenteredDiv>Tab Loading</CenteredDiv>;
} else if (!tabData) {
innerContent = <CenteredDiv>Tab Not Found</CenteredDiv>;
} else if (tabData?.blockids?.length == 0) {
innerContent = null;
} else {
innerContent = (
<TileLayout
key={tabId}
contents={tileLayoutContents}
tabAtom={tabAtom}
getCursorPoint={getApi().getCursorPoint}
/>
);
}
return (
<div className={`flex flex-row flex-grow min-h-0 w-full items-center justify-center overflow-hidden relative ${noTopPadding ? "" : "pt-[3px]"} pr-[3px]`}>
{innerContent}
</div>
);
});
export { TabContent };