-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubPage.tsx
171 lines (162 loc) · 5.18 KB
/
SubPage.tsx
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { Input, Select, Collapse, Menu, Button } from "antd";
import { useEffect, useRef, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Link } from "react-router-dom";
import { buildMenuData, getItem, MenuItem } from "../../../layout/Layout";
import { FileOutlined, FolderOutlined, InboxOutlined } from "@ant-design/icons";
import { RootState } from "../../../store/store";
import { NodeFileNavigator } from "../../home/utils/DataPayload";
import { BlockType, IContentBlock } from "../../../store/interfaces/block";
import { getPageByid, updatePageContent } from "../../../store/API/Page";
import { setBlockContent } from "../../../store/slices/blockSlice";
import Tiptap from "./EditorContent";
import { Editor } from "@tiptap/react";
import ImageBlockComponent from "./ImageBlock";
import TableDataBase from "./DataBaseTable";
import { TrelloDataBase } from "./TrelloDataBase";
const { Panel } = Collapse;
const { Search } = Input;
export function buildSubPageMenuData(
data: NodeFileNavigator[] | undefined
): MenuItem[] {
if (!data) return [];
return data.map((node) => {
if (node.children) {
return getItem(
node.title,
node.key,
<FolderOutlined />,
buildSubPageMenuData(node.children)
);
} else {
return getItem(
<Button type="text">{node.title}</Button>,
node.key,
<FileOutlined />,
undefined
);
}
});
}
const buildTreeSubPageMenuData = (treeData: NodeFileNavigator) => {
const menuData = buildSubPageMenuData(treeData.children);
return getItem("Workspace", "sub4", <InboxOutlined />, menuData);
};
interface SubPagePropsBlock {
dataSource: IContentBlock;
index: number;
}
const SubPageBlockComponent: React.FC<SubPagePropsBlock> = ({
dataSource,
index,
}) => {
const dispatch = useDispatch();
const treeData = useSelector((state: RootState) => state.Tree);
const refs = useRef<(Editor | null)[]>([]);
const [pageIsSelected, setpageIsSelected] = useState(false);
const [documentTitle, setDocumentTitle] = useState("");
useEffect(() => {
if (Array.isArray(dataSource.content))
setDocumentTitle(dataSource.content[0].content.slice(4, -5));
}, [dataSource.content]);
const handleSelectedSubPage = async (value: any) => {
const subpage = await getPageByid(value.key);
console.log("Datasrouce : ", subpage);
setDocumentTitle(subpage.title);
dispatch(
setBlockContent({
item: dataSource,
content: subpage.content,
})
);
};
const onChange = (key: string | string[]) => {
setpageIsSelected(true);
console.log(key);
};
const handleDelete = () => {
/* console.log("delete");
dispatch(
setBlockContent({
item: blockState,
content: "",
})
); */
};
const MenuAuthAccess = (): MenuItem[] => {
return [buildTreeSubPageMenuData(treeData)];
};
return (
<>
{Array.isArray(dataSource.content) ? (
<Collapse
defaultActiveKey={["1"]}
onChange={onChange}
style={{ width: "100%" }}
>
<Panel header={documentTitle.toUpperCase()} key="1">
{dataSource.content.map((item, index) => {
return (
<div
key={item.id}
className="block"
style={{ display: "flex", alignItems: "center" }}
>
{item.type === BlockType.TIPTAP ? (
<Tiptap
isEditable={false}
blockState={item}
ref={(ref) => {
refs.current[index] = ref;
}}
/>
) : null}
{item.type === BlockType.IMAGE &&
typeof item.content === "string" ? (
<ImageBlockComponent
isEditable={false}
blockState={item}
imageUrl={item.content}
/>
) : null}
{item.type === BlockType.DATABASE ? (
<TableDataBase
isSubPage={true}
isEditable={false}
dataSource={item}
index={index}
/>
) : null}
{item.type === BlockType.TRELLO &&
typeof item.content != "string" ? (
<TrelloDataBase
isSubPage={true}
isEditable={false}
dataSource={item}
index={index}
/>
) : null}
</div>
);
})}
</Panel>
</Collapse>
) : (
<Menu
style={{
border: "1px solid #8080802e",
borderRadius: "5px",
width: "50%",
}}
onClick={(e) => handleSelectedSubPage(e)}
defaultSelectedKeys={["1"]}
defaultOpenKeys={["sub1"]}
theme="light"
mode="inline"
items={MenuAuthAccess()}
/>
)}
</>
);
};
export default SubPageBlockComponent;