2019-05-17 04:11:10 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-10-16 03:07:13 +08:00
|
|
|
import Service from '/imports/ui/components/captions/service';
|
2022-02-15 22:57:07 +08:00
|
|
|
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';
|
2019-05-17 04:11:10 +08:00
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
2019-06-15 06:33:01 +08:00
|
|
|
subtitle: {
|
|
|
|
id: 'app.captions.menu.subtitle',
|
|
|
|
description: 'Subtitle for the closed captions writer menu',
|
|
|
|
},
|
2019-05-17 04:11:10 +08:00
|
|
|
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',
|
|
|
|
},
|
2019-05-17 04:11:10 +08:00
|
|
|
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',
|
|
|
|
},
|
2019-05-17 04:11:10 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
2021-10-16 03:07:13 +08:00
|
|
|
availableLocales: PropTypes.arrayOf(PropTypes.object).isRequired,
|
2019-05-17 04:11:10 +08:00
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class WriterMenu extends PureComponent {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2021-10-16 03:07:13 +08:00
|
|
|
const { availableLocales, intl } = this.props;
|
2019-06-15 06:33:01 +08:00
|
|
|
|
2021-10-16 03:07:13 +08:00
|
|
|
const candidate = availableLocales.filter(
|
2021-04-27 07:04:34 +08:00
|
|
|
(l) => l.locale.substring(0, 2) === intl.locale.substring(0, 2),
|
2019-06-15 06:33:01 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
locale: candidate && candidate[0] ? candidate[0].locale : null,
|
|
|
|
};
|
2019-05-17 04:11:10 +08:00
|
|
|
|
|
|
|
this.handleChange = this.handleChange.bind(this);
|
|
|
|
this.handleStart = this.handleStart.bind(this);
|
|
|
|
}
|
|
|
|
|
2021-09-02 03:54:09 +08:00
|
|
|
componentWillUnmount() {
|
2023-03-23 22:56:00 +08:00
|
|
|
const { setIsOpen } = this.props;
|
2021-09-02 03:54:09 +08:00
|
|
|
|
2023-03-23 22:56:00 +08:00
|
|
|
setIsOpen(false);
|
2021-09-02 03:54:09 +08:00
|
|
|
}
|
|
|
|
|
2019-05-17 04:11:10 +08:00
|
|
|
handleChange(event) {
|
|
|
|
this.setState({ locale: event.target.value });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleStart() {
|
2021-10-16 03:07:13 +08:00
|
|
|
const {
|
2023-03-23 22:56:00 +08:00
|
|
|
setIsOpen,
|
2021-10-16 03:07:13 +08:00
|
|
|
layoutContextDispatch,
|
|
|
|
} = this.props;
|
2019-05-17 04:11:10 +08:00
|
|
|
|
2021-10-16 03:07:13 +08:00
|
|
|
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,
|
|
|
|
});
|
2019-05-17 04:11:10 +08:00
|
|
|
|
2023-03-23 22:56:00 +08:00
|
|
|
setIsOpen(false);
|
2019-05-17 04:11:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
intl,
|
2021-10-16 03:07:13 +08:00
|
|
|
availableLocales,
|
2023-03-23 22:56:00 +08:00
|
|
|
setIsOpen,
|
2019-05-17 04:11:10 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-05-23 22:51:01 +08:00
|
|
|
const { locale } = this.state;
|
2021-01-30 00:17:35 +08:00
|
|
|
|
2019-05-17 04:11:10 +08:00
|
|
|
return (
|
2021-10-30 01:10:20 +08:00
|
|
|
<Styled.WriterMenuModal
|
2019-05-17 04:11:10 +08:00
|
|
|
hideBorder
|
|
|
|
contentLabel={intl.formatMessage(intlMessages.title)}
|
2022-11-11 02:09:21 +08:00
|
|
|
title={intl.formatMessage(intlMessages.title)}
|
2023-03-23 22:56:00 +08:00
|
|
|
{...this.props}
|
2019-05-17 04:11:10 +08:00
|
|
|
>
|
2021-10-30 01:10:20 +08:00
|
|
|
<Styled.Content>
|
2021-08-09 22:24:02 +08:00
|
|
|
<span>
|
2019-06-15 06:33:01 +08:00
|
|
|
{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-01-30 00:17:35 +08:00
|
|
|
|
2021-10-30 01:10:20 +08:00
|
|
|
<Styled.WriterMenuSelect>
|
|
|
|
<LocalesDropdown
|
2021-10-16 03:07:13 +08:00
|
|
|
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
|
2019-05-17 04:11:10 +08:00
|
|
|
label={intl.formatMessage(intlMessages.start)}
|
2019-06-06 23:04:02 +08:00
|
|
|
aria-label={intl.formatMessage(intlMessages.ariaStart)}
|
|
|
|
aria-describedby="descriptionStart"
|
2019-05-17 04:11:10 +08:00
|
|
|
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-05-17 04:11:10 +08:00
|
|
|
/>
|
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>
|
2019-05-17 04:11:10 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WriterMenu.propTypes = propTypes;
|
|
|
|
|
2023-03-23 22:56:00 +08:00
|
|
|
export default injectIntl(WriterMenu);
|