2024-03-26 05:13:57 +08:00
|
|
|
import React, { useContext, useRef } from 'react';
|
2024-02-19 18:59:45 +08:00
|
|
|
import * as PluginSdk from 'bigbluebutton-html-plugin-sdk';
|
|
|
|
|
|
|
|
import {
|
|
|
|
layoutDispatch,
|
|
|
|
layoutSelectInput,
|
|
|
|
layoutSelectOutput,
|
|
|
|
} from '../layout/context';
|
|
|
|
import {
|
2024-03-26 05:13:57 +08:00
|
|
|
DispatcherFunction,
|
2024-02-19 18:59:45 +08:00
|
|
|
GenericComponent as GenericComponentFromLayout,
|
|
|
|
Input,
|
|
|
|
Output,
|
|
|
|
} from '../layout/layoutTypes';
|
|
|
|
import { PluginsContext } from '../components-data/plugin-context/context';
|
|
|
|
import GenericComponentContent from './component';
|
2024-03-26 05:13:57 +08:00
|
|
|
import { ACTIONS, PRESENTATION_AREA } from '../layout/enums';
|
|
|
|
import getDifferenceBetweenLists from './utils';
|
|
|
|
import { GenericComponentContainerProps } from './types';
|
2024-02-19 18:59:45 +08:00
|
|
|
|
|
|
|
const GenericComponentContainer: React.FC<GenericComponentContainerProps> = (props: GenericComponentContainerProps) => {
|
2024-03-26 05:13:57 +08:00
|
|
|
const { genericComponentId } = props;
|
2024-02-19 18:59:45 +08:00
|
|
|
|
2024-03-26 05:13:57 +08:00
|
|
|
const previousPluginGenericComponents = useRef<PluginSdk.GenericComponent[]>([]);
|
2024-02-19 18:59:45 +08:00
|
|
|
const {
|
|
|
|
pluginsExtensibleAreasAggregatedState,
|
|
|
|
} = useContext(PluginsContext);
|
2024-03-26 05:13:57 +08:00
|
|
|
const layoutContextDispatch: DispatcherFunction = layoutDispatch();
|
2024-02-19 18:59:45 +08:00
|
|
|
let genericComponentExtensibleArea = [] as PluginSdk.GenericComponent[];
|
2024-03-26 05:13:57 +08:00
|
|
|
|
2024-02-19 18:59:45 +08:00
|
|
|
if (pluginsExtensibleAreasAggregatedState.genericComponents) {
|
|
|
|
genericComponentExtensibleArea = [
|
|
|
|
...pluginsExtensibleAreasAggregatedState.genericComponents as PluginSdk.GenericComponent[],
|
|
|
|
];
|
2024-03-26 05:13:57 +08:00
|
|
|
const [
|
|
|
|
genericComponentsAdded,
|
|
|
|
genericComponentsRemoved,
|
|
|
|
] = getDifferenceBetweenLists(previousPluginGenericComponents.current, genericComponentExtensibleArea);
|
|
|
|
if (genericComponentsAdded.length > 0 || genericComponentsRemoved.length > 0) {
|
|
|
|
previousPluginGenericComponents.current = [...genericComponentExtensibleArea];
|
|
|
|
genericComponentsAdded.forEach((g) => {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
|
|
|
|
value: {
|
|
|
|
content: PRESENTATION_AREA.GENERIC_COMPONENT,
|
|
|
|
open: true,
|
|
|
|
genericComponentId: g.id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
genericComponentsRemoved.forEach((g) => {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
|
|
|
|
value: {
|
|
|
|
content: PRESENTATION_AREA.GENERIC_COMPONENT,
|
|
|
|
open: false,
|
|
|
|
genericComponentId: g.id,
|
|
|
|
},
|
|
|
|
});
|
2024-02-19 18:59:45 +08:00
|
|
|
});
|
|
|
|
}
|
2024-03-26 05:13:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const genericComponentLayoutInformation: GenericComponentFromLayout = layoutSelectOutput(
|
|
|
|
(i: Output) => i.genericComponent,
|
|
|
|
);
|
2024-02-19 18:59:45 +08:00
|
|
|
|
|
|
|
const cameraDock = layoutSelectInput((i: Input) => i.cameraDock);
|
|
|
|
const { isResizing } = cameraDock;
|
|
|
|
|
2024-03-26 05:13:57 +08:00
|
|
|
if (!genericComponentExtensibleArea
|
|
|
|
|| genericComponentExtensibleArea.length === 0
|
|
|
|
|| !genericComponentId) return null;
|
2024-02-19 18:59:45 +08:00
|
|
|
return (
|
|
|
|
<GenericComponentContent
|
2024-03-26 05:13:57 +08:00
|
|
|
genericComponentId={genericComponentId}
|
2024-02-19 18:59:45 +08:00
|
|
|
renderFunctionComponents={genericComponentExtensibleArea}
|
|
|
|
isResizing={isResizing}
|
2024-03-26 05:13:57 +08:00
|
|
|
genericComponentLayoutInformation={genericComponentLayoutInformation}
|
2024-02-19 18:59:45 +08:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GenericComponentContainer;
|