2019-05-17 04:11:10 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { Session } from 'meteor/session';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Modal from '/imports/ui/components/modal/simple/component';
|
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
import { styles } from './styles';
|
|
|
|
|
2019-05-29 22:31:27 +08:00
|
|
|
const DEFAULT_VALUE = 'select';
|
2019-06-15 06:33:01 +08:00
|
|
|
|
2019-05-17 04:11:10 +08:00
|
|
|
const DEFAULT_KEY = -1;
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
takeOwnership: PropTypes.func.isRequired,
|
|
|
|
availableLocales: PropTypes.arrayOf(PropTypes.object).isRequired,
|
2019-05-29 22:31:27 +08:00
|
|
|
closeModal: PropTypes.func.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);
|
2019-06-15 06:33:01 +08:00
|
|
|
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,
|
|
|
|
};
|
2019-05-17 04:11:10 +08:00
|
|
|
|
|
|
|
this.handleChange = this.handleChange.bind(this);
|
|
|
|
this.handleStart = this.handleStart.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange(event) {
|
|
|
|
this.setState({ locale: event.target.value });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleStart() {
|
|
|
|
const { closeModal, takeOwnership } = this.props;
|
|
|
|
const { locale } = this.state;
|
|
|
|
|
|
|
|
takeOwnership(locale);
|
|
|
|
Session.set('captionsLocale', locale);
|
|
|
|
Session.set('openPanel', 'captions');
|
|
|
|
|
|
|
|
closeModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
availableLocales,
|
|
|
|
closeModal,
|
|
|
|
} = this.props;
|
|
|
|
|
2019-05-23 22:51:01 +08:00
|
|
|
const { locale } = this.state;
|
2019-06-15 06:33:01 +08:00
|
|
|
const defaultLocale = locale || DEFAULT_VALUE;
|
2019-05-17 04:11:10 +08:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
overlayClassName={styles.overlay}
|
|
|
|
className={styles.modal}
|
|
|
|
onRequestClose={closeModal}
|
|
|
|
hideBorder
|
|
|
|
contentLabel={intl.formatMessage(intlMessages.title)}
|
|
|
|
>
|
|
|
|
<header className={styles.header}>
|
|
|
|
<h3 className={styles.title}>
|
|
|
|
{intl.formatMessage(intlMessages.title)}
|
|
|
|
</h3>
|
|
|
|
</header>
|
|
|
|
<div className={styles.content}>
|
2019-06-15 06:33:01 +08:00
|
|
|
<label>
|
|
|
|
{intl.formatMessage(intlMessages.subtitle)}
|
|
|
|
</label>
|
2019-06-06 23:04:02 +08:00
|
|
|
<label
|
|
|
|
aria-hidden
|
|
|
|
htmlFor="captionsLangSelector"
|
|
|
|
aria-label={intl.formatMessage(intlMessages.ariaSelect)}
|
|
|
|
/>
|
2019-05-17 04:11:10 +08:00
|
|
|
<select
|
2019-06-06 23:04:02 +08:00
|
|
|
id="captionsLangSelector"
|
2019-05-17 04:11:10 +08:00
|
|
|
className={styles.select}
|
|
|
|
onChange={this.handleChange}
|
2019-06-15 06:33:01 +08:00
|
|
|
defaultValue={defaultLocale}
|
2019-05-17 04:11:10 +08:00
|
|
|
>
|
|
|
|
<option disabled key={DEFAULT_KEY} value={DEFAULT_VALUE}>
|
|
|
|
{intl.formatMessage(intlMessages.select)}
|
|
|
|
</option>
|
2019-05-29 22:31:27 +08:00
|
|
|
{availableLocales.map(localeItem => (
|
|
|
|
<option key={localeItem.locale} value={localeItem.locale}>
|
|
|
|
{localeItem.name}
|
2019-05-17 04:11:10 +08:00
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
<Button
|
|
|
|
className={styles.startBtn}
|
|
|
|
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}
|
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>
|
2019-05-17 04:11:10 +08:00
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WriterMenu.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default injectIntl(withModalMounter(WriterMenu));
|