11import * as React from 'react' ;
22import * as ReactDOM from 'react-dom/client' ;
3- import { createIntl , defineMessages } from 'react-intl' ;
43
54import {
6- ActionButtonDropdownOption ,
7- ActionButtonDropdownSeparator ,
8- BbbPluginSdk ,
5+ MediaAreaOption ,
6+ MediaAreaSeparator ,
97 DataChannelTypes ,
108 GenericContentSidekickArea ,
11- PluginApi ,
129} from 'bigbluebutton-html-plugin-sdk' ;
1310
14- import { TypedCaptionsProps } from './types' ;
1511import { TypedCaptionsModal } from '../modal/component' ;
1612import { CaptionMenu } from '../../common/types' ;
1713import { TypedCaptionsSidekickArea } from '../typed-captions-sidekick-content/component' ;
14+ import { TypedCaptionsProps } from './types' ;
15+ import { intlMessages } from '../../intlMessages' ;
1816
19- const intlMessages = defineMessages ( {
20- writeCC : {
21- id : 'plugin.actionButtonDropdown.write' ,
22- description : 'action button dropdown label to start writing' ,
23- } ,
24- stopCC : {
25- id : 'plugin.actionButtonDropdown.remove' ,
26- description : 'action button dropdown label to start writing' ,
27- } ,
28- sectionName : {
29- id : 'plugin.actionButtonDropdown.sidekickComponent.sectionName' ,
30- description : 'name of the sidekick component section' ,
31- } ,
32- menuTitle : {
33- id : 'plugin.actionButtonDropdown.sidekickComponent.menuTitle' ,
34- description : 'title of the sidekick component menu (internal part)' ,
35- } ,
36- } ) ;
37-
38- function TypedCaptions (
39- { pluginUuid : uuid } : TypedCaptionsProps ,
40- ) : React . ReactElement {
41- BbbPluginSdk . initialize ( uuid ) ;
42-
43- const pluginApi : PluginApi = BbbPluginSdk . getPluginApi ( uuid ) ;
44-
17+ function TypedCaptions ( { intl, pluginApi, uuid } : TypedCaptionsProps ) : React . ReactElement {
4518 const {
4619 data : captionMenusResponseFromDataChannel ,
4720 pushEntry : pushCaptionMenuResponseFromDataChannel ,
4821 deleteEntry : excludeCaptionMenuResponseFromDataChannel ,
4922 } = pluginApi . useDataChannel < CaptionMenu > ( 'typed-captions-data-channel' , DataChannelTypes . ALL_ITEMS , 'caption-menus' ) ;
5023
51- const {
52- messages,
53- currentLocale,
54- loading : localeMessagesLoading ,
55- } = pluginApi . useLocaleMessages ( {
56- headers : {
57- 'ngrok-skip-browser-warning' : 'any' ,
58- } ,
59- } ) ;
60-
61- const intl = ( ! localeMessagesLoading && messages ) ? createIntl ( {
62- locale : currentLocale ,
63- messages,
64- fallbackOnEmptyString : true ,
65- } ) : null ;
66-
6724 const [ captionLocale , setCaptionLocale ] = React . useState ( '' ) ;
6825
6926 const currentUserResponse = pluginApi . useCurrentUser ( ) ;
@@ -76,7 +33,7 @@ function TypedCaptions(
7633
7734 /// contentFunction, name, section, buttonIcon
7835 React . useEffect ( ( ) => {
79- if ( ! localeMessagesLoading && captionMenusResponseFromDataChannel ?. data && currentUserResponse ?. data ?. role === 'MODERATOR' ) {
36+ if ( captionMenusResponseFromDataChannel ?. data && currentUserResponse ?. data ?. role === 'MODERATOR' ) {
8037 const sectionName = intl . formatMessage ( intlMessages . sectionName ) ;
8138 const sidekickMenuComponentList = captionMenusResponseFromDataChannel ?. data
8239 . map ( ( menu ) => new GenericContentSidekickArea ( {
@@ -102,7 +59,7 @@ function TypedCaptions(
10259 } ) ) ;
10360 pluginApi . setGenericContentItems ( sidekickMenuComponentList ) ;
10461 }
105- } , [ captionMenusResponseFromDataChannel , localeMessagesLoading , messages ] ) ;
62+ } , [ captionMenusResponseFromDataChannel ] ) ;
10663
10764 React . useEffect ( ( ) => {
10865 if ( currentUserResponse ?. data ?. role === 'MODERATOR' ) {
@@ -131,23 +88,21 @@ function TypedCaptions(
13188 } ;
13289 } else actionButtonDropdownLabel = intl . formatMessage ( intlMessages . stopCC ) ;
13390 }
134- if ( ! localeMessagesLoading ) {
135- pluginApi . setActionButtonDropdownItems ( [
136- new ActionButtonDropdownSeparator ( ) ,
137- new ActionButtonDropdownOption ( {
138- icon : 'closed_caption' ,
139- label : actionButtonDropdownLabel ,
140- tooltip : 'this is a button injected by plugin' ,
141- allowed : true ,
142- onClick : actionButtonDropdownOnClick ,
143- } ) ,
144- ] ) ;
145- }
91+ pluginApi . setMediaAreaItems ( [
92+ new MediaAreaSeparator ( { } ) ,
93+ new MediaAreaOption ( {
94+ icon : 'closed_caption' ,
95+ label : actionButtonDropdownLabel ,
96+ tooltip : 'this is a button injected by plugin' ,
97+ allowed : true ,
98+ onClick : actionButtonDropdownOnClick ,
99+ } ) ,
100+ ] ) ;
146101 } else {
147- pluginApi . setActionButtonDropdownItems ( [ ] ) ;
102+ pluginApi . setMediaAreaItems ( [ ] ) ;
148103 pluginApi . setGenericContentItems ( [ ] ) ;
149104 }
150- } , [ currentUserResponse , captionMenusResponseFromDataChannel , localeMessagesLoading , messages ] ) ;
105+ } , [ currentUserResponse , captionMenusResponseFromDataChannel ] ) ;
151106
152107 return (
153108 < TypedCaptionsModal
0 commit comments