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

93 lines
3.4 KiB
TypeScript
Raw Normal View History

import React, { useContext, useRef } from 'react';
import * as PluginSdk from 'bigbluebutton-html-plugin-sdk';
import {
layoutDispatch,
layoutSelectInput,
layoutSelectOutput,
} from '/imports/ui/components/layout/context';
import {
DispatcherFunction,
2024-06-15 02:32:55 +08:00
GenericContentMainArea as GenericContentMainAreaFromLayout,
Input,
Output,
} from '/imports/ui/components/layout/layoutTypes';
import { PluginsContext } from '/imports/ui/components/components-data/plugin-context/context';
2024-06-14 06:30:59 +08:00
import { GenericContentType } from 'bigbluebutton-html-plugin-sdk/dist/cjs/extensible-areas/generic-content-item/enums';
import GenericMainContent from './component';
import { ACTIONS, PRESENTATION_AREA } from '/imports/ui/components/layout/enums';
import getDifferenceBetweenLists from '../utils';
2024-06-15 02:32:55 +08:00
import { GenericContentMainAreaContainerProps } from '../types';
2024-06-15 02:32:55 +08:00
const GenericContentMainAreaContainer: React.FC<GenericContentMainAreaContainerProps> = (
props: GenericContentMainAreaContainerProps,
2024-06-14 06:30:59 +08:00
) => {
const { genericMainContentId } = props;
2024-06-14 06:30:37 +08:00
const previousPluginGenericContainerContents = useRef<PluginSdk.GenericContentMainArea[]>([]);
const {
pluginsExtensibleAreasAggregatedState,
} = useContext(PluginsContext);
const layoutContextDispatch: DispatcherFunction = layoutDispatch();
2024-06-14 06:30:37 +08:00
let genericContainerContentExtensibleArea = [] as PluginSdk.GenericContentMainArea[];
if (pluginsExtensibleAreasAggregatedState.genericContentItems) {
const genericContainerContent = pluginsExtensibleAreasAggregatedState.genericContentItems
2024-06-14 06:30:37 +08:00
.filter((g) => g.type === GenericContentType.MAIN_AREA) as PluginSdk.GenericContentMainArea[];
genericContainerContentExtensibleArea = [
...genericContainerContent,
];
const [
genericContentItemsAdded,
genericContentItemsRemoved,
2024-06-14 06:30:59 +08:00
] = getDifferenceBetweenLists(
previousPluginGenericContainerContents.current,
genericContainerContentExtensibleArea,
);
if (genericContentItemsAdded.length > 0 || genericContentItemsRemoved.length > 0) {
previousPluginGenericContainerContents.current = [...genericContainerContentExtensibleArea];
genericContentItemsAdded.forEach((g) => {
layoutContextDispatch({
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
value: {
content: PRESENTATION_AREA.GENERIC_CONTENT,
open: true,
genericContentId: g.id,
},
});
});
genericContentItemsRemoved.forEach((g) => {
layoutContextDispatch({
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
value: {
content: PRESENTATION_AREA.GENERIC_CONTENT,
open: false,
genericContentId: g.id,
},
});
});
}
}
2024-06-15 02:32:55 +08:00
const genericContentLayoutInformation: GenericContentMainAreaFromLayout = layoutSelectOutput(
(i: Output) => i.genericMainContent,
);
const cameraDock = layoutSelectInput((i: Input) => i.cameraDock);
const { isResizing } = cameraDock;
if (!genericContainerContentExtensibleArea
|| genericContainerContentExtensibleArea.length === 0
|| !genericMainContentId) return null;
return (
<GenericMainContent
genericContentId={genericMainContentId}
renderFunctionComponents={genericContainerContentExtensibleArea}
isResizing={isResizing}
genericContentLayoutInformation={genericContentLayoutInformation}
/>
);
};
2024-06-15 02:32:55 +08:00
export default GenericContentMainAreaContainer;