feat: 插件增加更多的上下文获取

pull/56/head
moonrailgun 3 years ago
parent fd85953967
commit f350e45d02

@ -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']
)}
}
/**

@ -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<GroupPanelWrapperProps> = React.memo(
}
if (!props.showHeader) {
return <>{props.children}</>;
return (
<GroupPanelContext.Provider value={props}>
{props.children}
</GroupPanelContext.Provider>
);
}
return (
<CommonPanelWrapper
header={panelInfo.name}
actions={(setRightPanel) => [
...pluginPanelActions
.filter(
(action): action is GroupPluginPanelActionProps =>
action.position === 'group'
)
.map((action) => (
<IconBtn
key={action.name}
title={action.label}
shape="square"
icon={action.icon}
iconClassName="text-2xl"
onClick={() =>
action.onClick({
groupId: props.groupId,
panelId: props.panelId,
})
}
/>
)),
<IconBtn
key="open"
title={t('在新窗口打开')}
shape="square"
icon="mdi:dock-window"
iconClassName="text-2xl"
onClick={openPanelWindow}
/>,
<IconBtn
key="members"
title={t('成员列表')}
shape="square"
icon="mdi:account-supervisor-outline"
iconClassName="text-2xl"
onClick={() =>
setRightPanel({
name: t('成员'),
panel: <MembersPanel groupId={props.groupId} />,
})
}
/>,
]}
>
{props.children}
</CommonPanelWrapper>
<GroupPanelContext.Provider value={props}>
<CommonPanelWrapper
header={panelInfo.name}
actions={(setRightPanel) => [
...pluginPanelActions
.filter(
(action): action is GroupPluginPanelActionProps =>
action.position === 'group'
)
.map((action) => (
<IconBtn
key={action.name}
title={action.label}
shape="square"
icon={action.icon}
iconClassName="text-2xl"
onClick={() =>
action.onClick({
groupId: props.groupId,
panelId: props.panelId,
})
}
/>
)),
<IconBtn
key="open"
title={t('在新窗口打开')}
shape="square"
icon="mdi:dock-window"
iconClassName="text-2xl"
onClick={openPanelWindow}
/>,
<IconBtn
key="members"
title={t('成员列表')}
shape="square"
icon="mdi:account-supervisor-outline"
iconClassName="text-2xl"
onClick={() =>
setRightPanel({
name: t('成员'),
panel: <MembersPanel groupId={props.groupId} />,
})
}
/>,
]}
>
{props.children}
</CommonPanelWrapper>
</GroupPanelContext.Provider>
);
}
);

@ -5,6 +5,6 @@ GroupIdContext.displayName = 'GroupIdContext';
export const GroupIdContextProvider = GroupIdContext.Provider;
export function useGroupIdContext() {
export function useGroupIdContext(): string {
return useContext(GroupIdContext);
}

@ -0,0 +1,3 @@
export { useGroupIdContext } from '../../context/GroupIdContext';
export { useGroupPanelContext } from '../../context/GroupPanelContext';
export { useSocketContext } from '../../context/SocketContext';

@ -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,

@ -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;
}
/**

Loading…
Cancel
Save