bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/captions/writer-menu/component.jsx

155 lines
4.3 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
2022-02-15 23:54:55 +08:00
import { withModalMounter } from '/imports/ui/components/common/modal/service';
import PropTypes from 'prop-types';
import Service from '/imports/ui/components/captions/service';
import LocalesDropdown from '/imports/ui/components/common/locales-dropdown/component';
2021-10-30 01:10:20 +08:00
import Styled from './styles';
2021-05-18 04:25:07 +08:00
import { PANELS, ACTIONS } from '../../layout/enums';
const intlMessages = defineMessages({
closeLabel: {
id: 'app.captions.menu.closeLabel',
description: 'Label for closing captions menu',
},
title: {
id: 'app.captions.menu.title',
description: 'Title for the closed captions menu',
},
subtitle: {
id: 'app.captions.menu.subtitle',
description: 'Subtitle for the closed captions writer menu',
},
start: {
id: 'app.captions.menu.start',
description: 'Write closed captions',
},
2019-06-06 23:04:02 +08:00
ariaStart: {
id: 'app.captions.menu.ariaStart',
description: 'aria label for start captions button',
},
ariaStartDesc: {
id: 'app.captions.menu.ariaStartDesc',
description: 'aria description for start captions button',
},
select: {
id: 'app.captions.menu.select',
description: 'Select closed captions available language',
},
2019-06-06 23:04:02 +08:00
ariaSelect: {
id: 'app.captions.menu.ariaSelect',
description: 'Aria label for captions language selector',
},
});
const propTypes = {
availableLocales: PropTypes.arrayOf(PropTypes.object).isRequired,
2019-05-29 22:31:27 +08:00
closeModal: PropTypes.func.isRequired,
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
};
class WriterMenu extends PureComponent {
constructor(props) {
super(props);
const { availableLocales, intl } = this.props;
const candidate = availableLocales.filter(
(l) => l.locale.substring(0, 2) === intl.locale.substring(0, 2),
);
this.state = {
locale: candidate && candidate[0] ? candidate[0].locale : null,
};
this.handleChange = this.handleChange.bind(this);
this.handleStart = this.handleStart.bind(this);
}
componentWillUnmount() {
const { closeModal } = this.props;
closeModal();
}
handleChange(event) {
this.setState({ locale: event.target.value });
}
handleStart() {
const {
closeModal,
layoutContextDispatch,
} = this.props;
const { locale } = this.state;
Service.createCaptions(locale);
2021-05-18 04:25:07 +08:00
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: true,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.CAPTIONS,
});
closeModal();
}
render() {
const {
intl,
availableLocales,
closeModal,
} = this.props;
2019-05-23 22:51:01 +08:00
const { locale } = this.state;
return (
2021-10-30 01:10:20 +08:00
<Styled.WriterMenuModal
onRequestClose={closeModal}
hideBorder
contentLabel={intl.formatMessage(intlMessages.title)}
title={intl.formatMessage(intlMessages.title)}
>
2021-10-30 01:10:20 +08:00
<Styled.Content>
2021-08-09 22:24:02 +08:00
<span>
{intl.formatMessage(intlMessages.subtitle)}
2021-08-09 22:24:02 +08:00
</span>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
2019-06-06 23:04:02 +08:00
<label
aria-hidden
htmlFor="captionsLangSelector"
aria-label={intl.formatMessage(intlMessages.ariaSelect)}
/>
2021-10-30 01:10:20 +08:00
<Styled.WriterMenuSelect>
<LocalesDropdown
allLocales={availableLocales}
2021-10-30 01:10:20 +08:00
handleChange={this.handleChange}
value={locale}
elementId="captionsLangSelector"
selectMessage={intl.formatMessage(intlMessages.select)}
/>
</Styled.WriterMenuSelect>
<Styled.StartBtn
label={intl.formatMessage(intlMessages.start)}
2019-06-06 23:04:02 +08:00
aria-label={intl.formatMessage(intlMessages.ariaStart)}
aria-describedby="descriptionStart"
onClick={this.handleStart}
2019-05-23 22:51:01 +08:00
disabled={locale == null}
2023-01-10 21:39:18 +08:00
data-test="startWritingClosedCaptions"
/>
2019-06-06 23:04:02 +08:00
<div id="descriptionStart" hidden>{intl.formatMessage(intlMessages.ariaStartDesc)}</div>
2021-10-30 01:10:20 +08:00
</Styled.Content>
</Styled.WriterMenuModal>
);
}
}
WriterMenu.propTypes = propTypes;
export default injectIntl(withModalMounter(WriterMenu));