bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/plugins-engine/plugin-hooks-handler/container.tsx
Guilherme Pereira Leme 92c9ba971e
feature: Plugin UI extensible area for user list dropdown and associated refactors (#18607)
* [user-list-dropdown-plugin-implementation] - basic structure[

* [user-list-dropdown-plugin-implementation] - refactor for userListDropdown objects

* [user-list-dropdown-plugin-implementation] - Stabilized version

* [user-list-dropdown-plugin-implementation] - changes in review

* [user-list-dropdown-plugin-implementation] - changes in review

* [user-list-dropdown-plugin-implementation] - remove debug logs

* refactor hook usage count

* [user-list-dropdown-plugin] - lint errors

* [user-list-dropdown-plugin] - changes in review and fix first rendering

* [user-list-dropdown-plugin] - change users query to be global and reusable

* [user-list-dropdown-plugin] - bump SDK version

* [user-list-dropdown-plugin] -  new menu structure refactor

---------

Co-authored-by: Tainan Felipe <tainanfelipe214@gmail.com>
2023-09-05 09:49:55 -03:00

57 lines
2.1 KiB
TypeScript

import React, { useEffect, useState } from 'react';
import * as PluginSdk from 'bigbluebutton-html-plugin-sdk';
import CurrentPresentationHookContainer from './use-current-presentation/container'
import LoadedUserListHookContainer from './use-loaded-user-list/container'
const hooksMap:{
[key: string]: React.FunctionComponent
} = {
[PluginSdk.Internal.BbbHooks.UseCurrentPresentation]: CurrentPresentationHookContainer,
[PluginSdk.Internal.BbbHooks.UseLoadedUserList]: LoadedUserListHookContainer,
};
const PluginHooksHandlerContainer = () => {
const [
hookUtilizationCount,
setHookUtilizationCount,
] = useState(new Map<string, number>());
useEffect(() => {
const updateHookUsage = (hookName: string, delta: number):void => {
setHookUtilizationCount((mapObj) => {
const newMap = new Map<string, number>(mapObj.entries());
newMap.set(hookName, (mapObj.get(hookName) || 0) + delta);
return newMap;
});
};
const subscribeHandler: EventListener = (
(event: PluginSdk.CustomEventHookWrapper<void>) => {
updateHookUsage(event.detail.hook, 1);
}) as EventListener;
const unsubscribeHandler: EventListener = (
(event: PluginSdk.CustomEventHookWrapper<void>) => {
updateHookUsage(event.detail.hook, -1);
}) as EventListener;
window.addEventListener(PluginSdk.Internal.BbbHookEvents.Subscribe, subscribeHandler);
window.addEventListener(PluginSdk.Internal.BbbHookEvents.Unsubscribe, unsubscribeHandler);
return () => {
window.removeEventListener(PluginSdk.Internal.BbbHookEvents.Subscribe, subscribeHandler);
window.removeEventListener(PluginSdk.Internal.BbbHookEvents.Unsubscribe, unsubscribeHandler);
};
}, []);
return (
Object.keys(hooksMap)
.filter((hookName: string) => hookUtilizationCount.get(hookName)
&& hookUtilizationCount.get(hookName)! > 0)
.map((hookName: string) => {
const HookComponent = hooksMap[hookName];
return <HookComponent key={hookName}/>;
})
);
};
export default PluginHooksHandlerContainer;