bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/generic-content/generic-sidekick-content/container.tsx

64 lines
2.6 KiB
TypeScript
Raw Normal View History

import React, { useContext } from 'react';
import * as PluginSdk from 'bigbluebutton-html-plugin-sdk';
2024-06-14 06:30:59 +08:00
import { GenericContentType } from 'bigbluebutton-html-plugin-sdk/dist/cjs/extensible-areas/generic-content-item/enums';
import { PluginsContext } from '/imports/ui/components/components-data/plugin-context/context';
import { PANELS, ACTIONS } from '/imports/ui/components/layout/enums';
import GenericSidekickContent from './component';
2024-06-15 02:32:55 +08:00
import { GenericContentSidekickContainerProps } from '../types';
import logger from '/imports/startup/client/logger';
import { layoutDispatch } from '../../layout/context';
2024-06-15 02:32:55 +08:00
const GenericContentSidekickContainer: React.FC<GenericContentSidekickContainerProps> = (
props: GenericContentSidekickContainerProps,
2024-06-14 06:30:59 +08:00
) => {
const { genericSidekickContentId } = props;
2024-06-14 06:30:59 +08:00
const genericSidekickContentIdIsolated = genericSidekickContentId.replace(PANELS.GENERIC_CONTENT_SIDEKICK, '');
const layoutContextDispatch = layoutDispatch();
const {
pluginsExtensibleAreasAggregatedState,
} = useContext(PluginsContext);
let genericContentSidekickAreaExtensibleArea = [] as PluginSdk.GenericContentSidekickArea[];
if (pluginsExtensibleAreasAggregatedState.genericContentItems) {
const genericContentSidekickArea = pluginsExtensibleAreasAggregatedState.genericContentItems
2024-06-14 06:30:37 +08:00
.filter((g) => g.type === GenericContentType.SIDEKICK_AREA) as PluginSdk.GenericContentSidekickArea[];
genericContentSidekickAreaExtensibleArea = [...genericContentSidekickArea];
}
if (genericContentSidekickAreaExtensibleArea.length === 0) {
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: false,
});
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.NONE,
});
return null;
}
const pickedGenericSidekickContent = genericContentSidekickAreaExtensibleArea
2024-06-14 06:30:59 +08:00
.filter((gsc) => gsc.id === genericSidekickContentIdIsolated)[0];
if (!pickedGenericSidekickContent) {
logger.error({
logCode: 'generic_sidekick_content_not_found',
extraInfo: {
genericSidekickContentId,
genericSidekickContentIdIsolated,
},
}, `Generic sidekick content with id ${genericSidekickContentIdIsolated} not found`);
}
return (
<GenericSidekickContent
layoutContextDispatch={layoutContextDispatch}
genericContentId={pickedGenericSidekickContent.id}
renderFunction={pickedGenericSidekickContent.contentFunction}
genericContentLabel={pickedGenericSidekickContent.name}
/>
);
};
2024-06-15 02:32:55 +08:00
export default GenericContentSidekickContainer;