From 8c1cd74355619604161279fe64b8eef20a3f28f3 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 22 Sep 2021 17:52:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8A=BD=E8=B1=A1=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E5=8C=85=E8=A3=85=E5=99=A8=E9=80=BB=E8=BE=91,?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=8F=AF=E4=BB=A5=E6=96=B9=E4=BE=BF=E5=A4=8D?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/Panel/common/Wrapper.tsx | 63 +++++++++++++++ web/src/components/Panel/group/Wrapper.tsx | 78 ++++++------------- .../Panel/personal/ConversePanel.tsx | 2 - 3 files changed, 86 insertions(+), 57 deletions(-) create mode 100644 web/src/components/Panel/common/Wrapper.tsx diff --git a/web/src/components/Panel/common/Wrapper.tsx b/web/src/components/Panel/common/Wrapper.tsx new file mode 100644 index 00000000..70368724 --- /dev/null +++ b/web/src/components/Panel/common/Wrapper.tsx @@ -0,0 +1,63 @@ +import React, { useState } from 'react'; +import { PanelCommonHeader } from '../common/Header'; +import { Icon } from '@iconify/react'; +import { Button } from 'antd'; +import clsx from 'clsx'; + +interface RightPanelType { + name: string; + panel: React.ReactNode; +} + +/** + * 面板通用包装器 + */ +interface CommonPanelWrapperProps { + header: React.ReactNode; + actions: ( + setRightPanel: (info: RightPanelType) => void + ) => React.ReactElement[]; +} +export const CommonPanelWrapper: React.FC = React.memo( + (props) => { + const [rightPanel, setRightPanel] = useState(); + + return ( +
+ {/* 主面板 */} +
+ + {props.header} + +
{props.children}
+
+ + {/* 右侧面板 */} +
+ } + onClick={() => setRightPanel(undefined)} + />, + ]} + > + {rightPanel?.name} + + {rightPanel?.panel} +
+
+ ); + } +); +CommonPanelWrapper.displayName = 'CommonPanelWrapper'; diff --git a/web/src/components/Panel/group/Wrapper.tsx b/web/src/components/Panel/group/Wrapper.tsx index 07e71d63..c93581d3 100644 --- a/web/src/components/Panel/group/Wrapper.tsx +++ b/web/src/components/Panel/group/Wrapper.tsx @@ -1,11 +1,10 @@ -import React, { useState } from 'react'; +import React from 'react'; import { t, useGroupPanel } from 'tailchat-shared'; -import { PanelCommonHeader } from '../common/Header'; import _isNil from 'lodash/isNil'; import { Icon } from '@iconify/react'; import { Button } from 'antd'; import { MembersPanel } from './MembersPanel'; -import clsx from 'clsx'; +import { CommonPanelWrapper } from '../common/Wrapper'; /** * 群组面板通用包装器 @@ -17,65 +16,34 @@ interface GroupPanelWrapperProps { export const GroupPanelWrapper: React.FC = React.memo( (props) => { const panelInfo = useGroupPanel(props.groupId, props.panelId); - const [rightPanel, setRightPanel] = - useState<{ name: string; panel: React.ReactNode }>(); if (_isNil(panelInfo)) { return null; } return ( -
- {/* 主面板 */} -
- - } - onClick={() => - setRightPanel({ - name: t('成员'), - panel: , - }) - } - />, - ]} - > - {panelInfo.name} - -
{props.children}
-
- - {/* 右侧面板 */} -
[ +
-
+ />, + ]} + > + {props.children} + ); } ); diff --git a/web/src/components/Panel/personal/ConversePanel.tsx b/web/src/components/Panel/personal/ConversePanel.tsx index 84917696..d064d481 100644 --- a/web/src/components/Panel/personal/ConversePanel.tsx +++ b/web/src/components/Panel/personal/ConversePanel.tsx @@ -7,8 +7,6 @@ import { useDMConverseName, } from 'tailchat-shared'; import { PanelCommonHeader } from '../common/Header'; -import _isNil from 'lodash/isNil'; -import { LoadingSpinner } from '@/components/LoadingSpinner'; const ConversePanelHeader: React.FC<{ converse: ChatConverseState }> = React.memo(({ converse }) => {