2024-06-11 03:31:30 +08:00
|
|
|
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,
|
|
|
|
GenericMainContent as GenericContentFromLayout,
|
|
|
|
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';
|
2024-06-11 03:31:30 +08:00
|
|
|
import GenericMainContent from './component';
|
|
|
|
import { ACTIONS, PRESENTATION_AREA } from '/imports/ui/components/layout/enums';
|
|
|
|
import getDifferenceBetweenLists from '../utils';
|
|
|
|
import { GenericMainContentContainerProps } from '../types';
|
|
|
|
|
2024-06-14 06:30:59 +08:00
|
|
|
const GenericMainContentContainer: React.FC<GenericMainContentContainerProps> = (
|
|
|
|
props: GenericMainContentContainerProps,
|
|
|
|
) => {
|
2024-06-11 03:31:30 +08:00
|
|
|
const { genericMainContentId } = props;
|
|
|
|
|
2024-06-14 06:30:37 +08:00
|
|
|
const previousPluginGenericContainerContents = useRef<PluginSdk.GenericContentMainArea[]>([]);
|
2024-06-11 03:31:30 +08:00
|
|
|
const {
|
|
|
|
pluginsExtensibleAreasAggregatedState,
|
|
|
|
} = useContext(PluginsContext);
|
|
|
|
const layoutContextDispatch: DispatcherFunction = layoutDispatch();
|
2024-06-14 06:30:37 +08:00
|
|
|
let genericContainerContentExtensibleArea = [] as PluginSdk.GenericContentMainArea[];
|
2024-06-11 03:31:30 +08:00
|
|
|
|
2024-06-15 00:48:25 +08:00
|
|
|
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[];
|
2024-06-11 03:31:30 +08:00
|
|
|
genericContainerContentExtensibleArea = [
|
|
|
|
...genericContainerContent,
|
|
|
|
];
|
|
|
|
const [
|
2024-06-15 00:48:25 +08:00
|
|
|
genericContentItemsAdded,
|
|
|
|
genericContentItemsRemoved,
|
2024-06-14 06:30:59 +08:00
|
|
|
] = getDifferenceBetweenLists(
|
|
|
|
previousPluginGenericContainerContents.current,
|
|
|
|
genericContainerContentExtensibleArea,
|
|
|
|
);
|
2024-06-15 00:48:25 +08:00
|
|
|
if (genericContentItemsAdded.length > 0 || genericContentItemsRemoved.length > 0) {
|
2024-06-11 03:31:30 +08:00
|
|
|
previousPluginGenericContainerContents.current = [...genericContainerContentExtensibleArea];
|
2024-06-15 00:48:25 +08:00
|
|
|
genericContentItemsAdded.forEach((g) => {
|
2024-06-11 03:31:30 +08:00
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
|
|
|
|
value: {
|
|
|
|
content: PRESENTATION_AREA.GENERIC_CONTENT,
|
|
|
|
open: true,
|
|
|
|
genericContentId: g.id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2024-06-15 00:48:25 +08:00
|
|
|
genericContentItemsRemoved.forEach((g) => {
|
2024-06-11 03:31:30 +08:00
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
|
|
|
|
value: {
|
|
|
|
content: PRESENTATION_AREA.GENERIC_CONTENT,
|
|
|
|
open: false,
|
|
|
|
genericContentId: g.id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const genericContentLayoutInformation: GenericContentFromLayout = 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}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GenericMainContentContainer;
|