Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"requiredSdkVersion": "~0.0.59",
"name": "TypedCaptions",
"version": "0.0.4",
"javascriptEntrypointUrl": "TypedCaptions.js",
"localesBaseUrl": "locales",
"dataChannels": [
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/react": "^18.2.13",
"@types/react-dom": "^18.2.6",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"bigbluebutton-html-plugin-sdk": "0.0.93",
"bigbluebutton-html-plugin-sdk": "0.0.94",
"path": "^0.12.7",
"react-intl": "^6.6.8",
"react": "^18.2.0",
Expand Down
7 changes: 7 additions & 0 deletions public/locales/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
"en.json",
"fr-FR.json",
"fr.json",
"index.json",
"pt-BR.json"
]
3 changes: 2 additions & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ export interface CaptionMessage {
locale: string;
}

export interface CaptionMenu {
export interface ActiveCaptionMenuInformation {
captionLocale: string;
userId: string;
}

export interface sidekickMenuLocale {
Expand Down
167 changes: 0 additions & 167 deletions src/components/main/component.tsx

This file was deleted.

95 changes: 20 additions & 75 deletions src/components/modal/component.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import * as BbbPluginSdk from 'bigbluebutton-html-plugin-sdk';
import { defineMessages, IntlShape } from 'react-intl';
import * as React from 'react';
import Styled from './styles';
import * as Styled from './styles';
import LocalesDropdown from './locales-dropdown/component';
import './styles.css';
import { AVAILABLE_LOCALES, CAPTIONS_CONFIG_LANGUAGES } from './constants';
import { AvailableLocaleObject, CaptionMenu } from '../../common/types';
import { AvailableLocaleObject } from '../../common/types';

interface TypedCaptionsModalProps {
interface TypedCaptionsModalComponentProps {
isOpen: boolean;
intl: IntlShape;
onRequestClose: () => void;
setIsOpen: (value: boolean) => void;
availableCaptionMenus: BbbPluginSdk.DataChannelEntryResponseType<CaptionMenu>[];
pushCaptionMenu: BbbPluginSdk.PushEntryFunction<CaptionMenu>;
handleStart: React.MouseEventHandler<HTMLButtonElement>;
handleChange: (event: React.ChangeEvent<HTMLSelectElement>) => void;
availableLocales: AvailableLocaleObject[];
captionLocale: string;
setCaptionLocale: (value: string) => void;
pluginApi: BbbPluginSdk.PluginApi;
errorMessage: string;
}

const TIMEOUT_RENDER_ERROR = 3000;

const intlMessages = defineMessages({
selectorLabel: {
id: 'plugin.actionButtonDropdown.modal.selectorLabel',
Expand All @@ -36,82 +30,33 @@ const intlMessages = defineMessages({
},
});

function TypedCaptionsModal(props: TypedCaptionsModalProps) {
function TypedCaptionsModalComponent(props: TypedCaptionsModalComponentProps) {
const {
isOpen,
onRequestClose,
setIsOpen,
availableCaptionMenus,
pushCaptionMenu,
captionLocale: locale,
setCaptionLocale: setLocale,
pluginApi,
intl,
handleChange,
availableLocales,
captionLocale,
errorMessage,
handleStart,
} = props;

const [availableLocales, setAvailableLocales] = React.useState<AvailableLocaleObject[]>([]);
const [errorMessage, setErrorMessage] = React.useState('');

React.useEffect(() => {
const filteredLocales = AVAILABLE_LOCALES.filter(
(l) => CAPTIONS_CONFIG_LANGUAGES.includes(l?.locale),
);
setAvailableLocales(filteredLocales as AvailableLocaleObject[]);

return () => {
setIsOpen(false);
setAvailableLocales([]);
};
}, []);

const setError = (message: string) => {
setErrorMessage(message);
setTimeout(() => {
setErrorMessage('');
}, TIMEOUT_RENDER_ERROR);
};

const handleStart: React.MouseEventHandler<HTMLButtonElement> = () => {
const alreadyUsedEntryId = availableCaptionMenus?.filter(
(item) => item.payloadJson.captionLocale === locale,
)[0]?.entryId;
if (locale !== '' && !alreadyUsedEntryId) {
pluginApi.serverCommands.caption.addLocale(locale);
pushCaptionMenu({ captionLocale: locale });
setIsOpen(false);
} else if (locale === '') {
setError('Please select a language!');
} else if (alreadyUsedEntryId) {
setError('This language is already in the typed-captions menu');
}
};

const handleCloseModal = () => {
setIsOpen(false);
};

const handleChange: React.EventHandler<React.ChangeEvent<HTMLSelectElement>> = (event) => {
setLocale(event.target.value);
};

if (!intl) return null;
const selectorLabel = intl.formatMessage(intlMessages.selectorLabel);
return isOpen && (
<Styled.TypedCaptionsModal
portalClassName="modal-low"
parentSelector={() => document.querySelector('#modals-container')}
overlayClassName="modal-overlay"
{...{
isOpen,
onRequestClose,
setIsOpen,
}}
parentSelector={() => document.querySelector('#modals-container') as HTMLElement}
overlayClassName="modalOverlay"
isOpen={isOpen}
onRequestClose={onRequestClose}
>
<Styled.CloseButton
type="button"
className="clickable-close"
onClick={() => {
handleCloseModal();
onRequestClose();
}}
>
<i
Expand All @@ -130,7 +75,7 @@ function TypedCaptionsModal(props: TypedCaptionsModalProps) {
<LocalesDropdown
allLocales={availableLocales}
handleChange={handleChange}
value={locale}
value={captionLocale}
elementId="captionsLangSelector"
intl={intl}
selectMessage={intl.formatMessage(intlMessages.selectPlaceholder)}
Expand All @@ -152,4 +97,4 @@ function TypedCaptionsModal(props: TypedCaptionsModalProps) {
);
}

export { TypedCaptionsModal };
export { TypedCaptionsModalComponent };
Loading