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( const { exportModules: componentExportModules } = parseExports(
path.resolve(__dirname, '../src/plugin/component/index.tsx'), path.resolve(__dirname, '../src/plugin/component/index.tsx'),
{} {}
@ -68,6 +73,11 @@ declare module '@capital/common' {
commonRegExportModules, commonRegExportModules,
existedModules['@capital/common'] existedModules['@capital/common']
)} )}
${exportModulesTemplate(
commonContextExportModules,
existedModules['@capital/common']
)}
} }
/** /**

@ -11,6 +11,7 @@ import {
pluginPanelActions, pluginPanelActions,
} from '@/plugin/common'; } from '@/plugin/common';
import { useUserSessionPreference } from '@/hooks/useUserPreference'; import { useUserSessionPreference } from '@/hooks/useUserPreference';
import { GroupPanelContext } from '@/context/GroupPanelContext';
/** /**
* 访id * 访id
@ -56,10 +57,15 @@ export const GroupPanelWrapper: React.FC<GroupPanelWrapperProps> = React.memo(
} }
if (!props.showHeader) { if (!props.showHeader) {
return <>{props.children}</>; return (
<GroupPanelContext.Provider value={props}>
{props.children}
</GroupPanelContext.Provider>
);
} }
return ( return (
<GroupPanelContext.Provider value={props}>
<CommonPanelWrapper <CommonPanelWrapper
header={panelInfo.name} header={panelInfo.name}
actions={(setRightPanel) => [ actions={(setRightPanel) => [
@ -108,6 +114,7 @@ export const GroupPanelWrapper: React.FC<GroupPanelWrapperProps> = React.memo(
> >
{props.children} {props.children}
</CommonPanelWrapper> </CommonPanelWrapper>
</GroupPanelContext.Provider>
); );
} }
); );

@ -5,6 +5,6 @@ GroupIdContext.displayName = 'GroupIdContext';
export const GroupIdContextProvider = GroupIdContext.Provider; export const GroupIdContextProvider = GroupIdContext.Provider;
export function useGroupIdContext() { export function useGroupIdContext(): string {
return useContext(GroupIdContext); 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'; import _pick from 'lodash/pick';
export * from './reg'; export * from './reg';
export * from './context';
export { useGroupPanelParams } from '@/routes/Main/Content/Group/utils'; export { useGroupPanelParams } from '@/routes/Main/Content/Group/utils';
/** /**
@ -28,7 +29,6 @@ export {
appendUrlSearch, appendUrlSearch,
} from '@/utils/url-helper'; } from '@/utils/url-helper';
export { getServiceWorkerRegistration } from '@/utils/sw-helper'; export { getServiceWorkerRegistration } from '@/utils/sw-helper';
export { useGroupIdContext } from '@/context/GroupIdContext';
import { request, RequestConfig, useUserInfo } from 'tailchat-shared'; import { request, RequestConfig, useUserInfo } from 'tailchat-shared';
export { export {
getServiceUrl, getServiceUrl,

@ -70,8 +70,6 @@ declare module '@capital/common' {
export const getServiceWorkerRegistration: any; export const getServiceWorkerRegistration: any;
export const useGroupIdContext: any;
export const getServiceUrl: () => string; export const getServiceUrl: () => string;
export const getCachedUserInfo: ( export const getCachedUserInfo: (
@ -216,6 +214,15 @@ declare module '@capital/common' {
*/ */
required?: string[]; required?: string[];
}) => void; }) => void;
export const useGroupIdContext: () => string;
export const useGroupPanelContext: () => {
groupId: string;
panelId: string;
} | null;
export const useSocketContext: any;
} }
/** /**

Loading…
Cancel
Save