diff --git a/web/src/components/modals/GroupDetail/Panel.tsx b/web/src/components/modals/GroupDetail/Panel.tsx new file mode 100644 index 00000000..f66b7599 --- /dev/null +++ b/web/src/components/modals/GroupDetail/Panel.tsx @@ -0,0 +1,72 @@ +import React, { useCallback, useMemo } from 'react'; +import { + GroupPanelType, + useGroupInfo, + GroupPanel as GroupPanelInfo, +} from 'tailchat-shared'; +import { Tree } from 'antd'; +import type { NodeDragEventParams } from 'rc-tree/lib/contextTypes'; +import type { DataNode, EventDataNode } from 'antd/lib/tree'; +import type { Key } from 'rc-tree/lib/interface'; + +/** + * 将一维的面板列表构筑成立体的数组 + */ +function buildTreeDataWithGroupPanel( + groupPanels: GroupPanelInfo[] +): DataNode[] { + return groupPanels + .filter((panel) => panel.type === GroupPanelType.GROUP) + .map((section) => ({ + key: section.id, + title: section.name, + isLeaf: false, + children: groupPanels + .filter((panel) => panel.parentId === section.id) + .map((panel) => ({ + key: panel.id, + title: panel.name, + isLeaf: true, + })), + })); +} + +export const GroupPanel: React.FC<{ + groupId: string; +}> = React.memo((props) => { + const groupId = props.groupId; + const groupInfo = useGroupInfo(groupId); + const groupPanels = groupInfo?.panels ?? []; + + const handleDrop = useCallback( + ( + info: NodeDragEventParams & { + dragNode: EventDataNode; + dragNodesKeys: Key[]; + dropPosition: number; + dropToGap: boolean; + } + ) => { + // TODO + console.log(info); + }, + [] + ); + + const treeData: DataNode[] = useMemo( + () => buildTreeDataWithGroupPanel(groupPanels), + [groupPanels] + ); + + return ( +
+ +
+ ); +}); +GroupPanel.displayName = 'GroupPanel'; diff --git a/web/src/components/modals/GroupDetail/index.tsx b/web/src/components/modals/GroupDetail/index.tsx index 10fd32d1..c10aac2a 100644 --- a/web/src/components/modals/GroupDetail/index.tsx +++ b/web/src/components/modals/GroupDetail/index.tsx @@ -2,6 +2,7 @@ import { FullModal } from '@/components/FullModal'; import { SidebarView, SidebarViewMenuType } from '@/components/SidebarView'; import React, { useCallback, useMemo } from 'react'; import { t } from 'tailchat-shared'; +import { GroupPanel } from './Panel'; import { GroupSummary } from './Summary'; interface SettingsViewProps { @@ -29,6 +30,11 @@ export const GroupDetail: React.FC = React.memo((props) => { title: t('概述'), content: , }, + { + type: 'item', + title: t('面板'), + content: , + }, ], }, ],