From f350e45d02be878aa0631a7c4712fd774a26dc6b Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 29 Sep 2022 20:34:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=92=E4=BB=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A=E7=9A=84=E4=B8=8A=E4=B8=8B=E6=96=87=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generate-plugin-declaration.typescript.ts | 10 ++ .../src/components/Panel/group/Wrapper.tsx | 105 ++++++++++-------- client/web/src/context/GroupIdContext.tsx | 2 +- .../GroupPanelContext.tsx} | 0 client/web/src/plugin/common/context.ts | 3 + client/web/src/plugin/common/index.ts | 2 +- client/web/tailchat.d.ts | 11 +- 7 files changed, 80 insertions(+), 53 deletions(-) rename client/web/src/{routes/Main/Content/Group/context.tsx => context/GroupPanelContext.tsx} (100%) create mode 100644 client/web/src/plugin/common/context.ts diff --git a/client/web/scripts/generate-plugin-declaration.typescript.ts b/client/web/scripts/generate-plugin-declaration.typescript.ts index 98cb8299..7151352f 100644 --- a/client/web/scripts/generate-plugin-declaration.typescript.ts +++ b/client/web/scripts/generate-plugin-declaration.typescript.ts @@ -38,6 +38,11 @@ function generateDeclarationFile() { {} ); + const { exportModules: commonContextExportModules } = parseExports( + path.resolve(__dirname, '../src/plugin/common/context.ts'), + {} + ); + const { exportModules: componentExportModules } = parseExports( path.resolve(__dirname, '../src/plugin/component/index.tsx'), {} @@ -68,6 +73,11 @@ declare module '@capital/common' { commonRegExportModules, existedModules['@capital/common'] )} + + ${exportModulesTemplate( + commonContextExportModules, + existedModules['@capital/common'] + )} } /** diff --git a/client/web/src/components/Panel/group/Wrapper.tsx b/client/web/src/components/Panel/group/Wrapper.tsx index 1cca8835..75eef4a2 100644 --- a/client/web/src/components/Panel/group/Wrapper.tsx +++ b/client/web/src/components/Panel/group/Wrapper.tsx @@ -11,6 +11,7 @@ import { pluginPanelActions, } from '@/plugin/common'; import { useUserSessionPreference } from '@/hooks/useUserPreference'; +import { GroupPanelContext } from '@/context/GroupPanelContext'; /** * 记录下最后访问的面板id @@ -56,58 +57,64 @@ export const GroupPanelWrapper: React.FC = React.memo( } if (!props.showHeader) { - return <>{props.children}; + return ( + + {props.children} + + ); } return ( - [ - ...pluginPanelActions - .filter( - (action): action is GroupPluginPanelActionProps => - action.position === 'group' - ) - .map((action) => ( - - action.onClick({ - groupId: props.groupId, - panelId: props.panelId, - }) - } - /> - )), - , - - setRightPanel({ - name: t('成员'), - panel: , - }) - } - />, - ]} - > - {props.children} - + + [ + ...pluginPanelActions + .filter( + (action): action is GroupPluginPanelActionProps => + action.position === 'group' + ) + .map((action) => ( + + action.onClick({ + groupId: props.groupId, + panelId: props.panelId, + }) + } + /> + )), + , + + setRightPanel({ + name: t('成员'), + panel: , + }) + } + />, + ]} + > + {props.children} + + ); } ); diff --git a/client/web/src/context/GroupIdContext.tsx b/client/web/src/context/GroupIdContext.tsx index 50369bec..5c975d9b 100644 --- a/client/web/src/context/GroupIdContext.tsx +++ b/client/web/src/context/GroupIdContext.tsx @@ -5,6 +5,6 @@ GroupIdContext.displayName = 'GroupIdContext'; export const GroupIdContextProvider = GroupIdContext.Provider; -export function useGroupIdContext() { +export function useGroupIdContext(): string { return useContext(GroupIdContext); } diff --git a/client/web/src/routes/Main/Content/Group/context.tsx b/client/web/src/context/GroupPanelContext.tsx similarity index 100% rename from client/web/src/routes/Main/Content/Group/context.tsx rename to client/web/src/context/GroupPanelContext.tsx diff --git a/client/web/src/plugin/common/context.ts b/client/web/src/plugin/common/context.ts new file mode 100644 index 00000000..6974a7d1 --- /dev/null +++ b/client/web/src/plugin/common/context.ts @@ -0,0 +1,3 @@ +export { useGroupIdContext } from '../../context/GroupIdContext'; +export { useGroupPanelContext } from '../../context/GroupPanelContext'; +export { useSocketContext } from '../../context/SocketContext'; diff --git a/client/web/src/plugin/common/index.ts b/client/web/src/plugin/common/index.ts index edc6263d..548a0d27 100644 --- a/client/web/src/plugin/common/index.ts +++ b/client/web/src/plugin/common/index.ts @@ -5,6 +5,7 @@ import _pick from 'lodash/pick'; export * from './reg'; +export * from './context'; export { useGroupPanelParams } from '@/routes/Main/Content/Group/utils'; /** @@ -28,7 +29,6 @@ export { appendUrlSearch, } from '@/utils/url-helper'; export { getServiceWorkerRegistration } from '@/utils/sw-helper'; -export { useGroupIdContext } from '@/context/GroupIdContext'; import { request, RequestConfig, useUserInfo } from 'tailchat-shared'; export { getServiceUrl, diff --git a/client/web/tailchat.d.ts b/client/web/tailchat.d.ts index 2babb196..51d3e874 100644 --- a/client/web/tailchat.d.ts +++ b/client/web/tailchat.d.ts @@ -70,8 +70,6 @@ declare module '@capital/common' { export const getServiceWorkerRegistration: any; - export const useGroupIdContext: any; - export const getServiceUrl: () => string; export const getCachedUserInfo: ( @@ -216,6 +214,15 @@ declare module '@capital/common' { */ required?: string[]; }) => void; + + export const useGroupIdContext: () => string; + + export const useGroupPanelContext: () => { + groupId: string; + panelId: string; + } | null; + + export const useSocketContext: any; } /**