bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/plugins-engine/plugin-provided-state/presentation-dropdown/container.tsx
2023-09-25 19:03:34 -03:00

55 lines
1.8 KiB
TypeScript

import { useEffect, useState, useContext } from 'react';
import * as PluginSdk from 'bigbluebutton-html-plugin-sdk';
import {
PluginProvidedStateContainerChildProps, PluginProvidedState,
PluginProvidedStateContainerChild,
} from '../../types';
import { PluginsContext } from '../../../components-data/plugin-context/context';
const PresentationDropdownPluginStateContainer = ((
props: PluginProvidedStateContainerChildProps,
) => {
const {
uuid,
generateItemWithId,
pluginProvidedStateMap,
pluginApi,
} = props;
const [
presentationDropdownItems,
setPresentationDropdownItems,
] = useState<PluginSdk.PresentationDropdownItem[]>([]);
const {
pluginsProvidedAggregatedState,
setPluginsProvidedAggregatedState,
} = useContext(PluginsContext);
useEffect(() => {
// Change this plugin provided toolbar items
pluginProvidedStateMap[uuid].presentationDropdownItems = presentationDropdownItems;
// Update context with computed aggregated list of all plugin provided toolbar items
const aggregatedPresentationDropdownItems = (
[] as PluginSdk.PresentationDropdownItem[]).concat(
...Object.values(pluginProvidedStateMap)
.map((pps: PluginProvidedState) => pps.presentationDropdownItems),
);
setPluginsProvidedAggregatedState(
{
...pluginsProvidedAggregatedState,
presentationDropdownItems: aggregatedPresentationDropdownItems,
},
);
}, [presentationDropdownItems]);
pluginApi.setPresentationDropdownItems = (items: PluginSdk.PresentationDropdownItem[]) => {
const itemsWithId = items.map(generateItemWithId) as PluginSdk.PresentationDropdownItem[];
return setPresentationDropdownItems(itemsWithId);
};
return null;
}) as PluginProvidedStateContainerChild;
export default PresentationDropdownPluginStateContainer;