2022-08-31 15:57:31 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
|
|
|
import React, { useState, useEffect, useCallback } from 'react';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
2022-09-05 11:24:13 +00:00
|
|
|
import { IState } from '../../app/types';
|
2022-08-31 15:57:31 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import { Dialog } from '../../base/dialog';
|
|
|
|
// @ts-ignore
|
|
|
|
import { LANGUAGES, TRANSLATION_LANGUAGES_HEAD, TRANSLATION_LANGUAGES_EXCLUDE } from '../../base/i18n';
|
2022-09-05 11:24:13 +00:00
|
|
|
import { connect } from '../../base/redux/functions';
|
2022-08-31 15:57:31 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import { updateTranslationLanguage, setRequestingSubtitles, toggleLangugeSelectorDialog } from '../actions';
|
|
|
|
|
|
|
|
import LanguageList from './LanguageList';
|
|
|
|
|
|
|
|
interface ILanguageSelectorDialogProps {
|
2022-09-08 09:52:36 +00:00
|
|
|
_language: string;
|
|
|
|
t: Function;
|
2022-08-31 15:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that renders the subtitle language selector dialog.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
|
|
|
const LanguageSelectorDialog = ({ _language }: ILanguageSelectorDialogProps) => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const off = 'transcribing.subtitlesOff';
|
|
|
|
const [ language, setLanguage ] = useState(off);
|
|
|
|
|
|
|
|
const importantLanguages = TRANSLATION_LANGUAGES_HEAD.map((lang: string) => `languages:${lang}`);
|
|
|
|
const fixedItems = [ off, ...importantLanguages ];
|
|
|
|
|
|
|
|
const languages = LANGUAGES
|
|
|
|
.filter((lang: string) => !TRANSLATION_LANGUAGES_EXCLUDE.includes(lang))
|
|
|
|
.map((lang: string) => `languages:${lang}`)
|
|
|
|
.filter((lang: string) => !(lang === language || importantLanguages.includes(lang)));
|
|
|
|
|
|
|
|
const listItems = (fixedItems.includes(language)
|
|
|
|
? [ ...fixedItems, ...languages ]
|
|
|
|
: [ ...fixedItems, language, ...languages ])
|
|
|
|
.map((lang, index) => {
|
|
|
|
return {
|
|
|
|
id: lang + index,
|
|
|
|
lang,
|
|
|
|
selected: lang === language
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
_language ? setLanguage(_language) : setLanguage(off);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const onLanguageSelected = useCallback((e: string) => {
|
|
|
|
setLanguage(e);
|
|
|
|
dispatch(updateTranslationLanguage(e));
|
|
|
|
dispatch(setRequestingSubtitles(e !== off));
|
|
|
|
dispatch(toggleLangugeSelectorDialog());
|
|
|
|
}, [ _language ]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog
|
|
|
|
hideCancelButton = { true }
|
|
|
|
submitDisabled = { true }
|
|
|
|
titleKey = 'transcribing.subtitles'
|
|
|
|
width = { 'small' }>
|
|
|
|
<LanguageList
|
|
|
|
items = { listItems }
|
|
|
|
onLanguageSelected = { onLanguageSelected }
|
|
|
|
selectedLanguage = { language } />
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
* {@code LanguageSelectorDialog} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
2022-09-05 11:24:13 +00:00
|
|
|
function mapStateToProps(state: IState) {
|
2022-08-31 15:57:31 +00:00
|
|
|
const {
|
|
|
|
conference
|
|
|
|
} = state['features/base/conference'];
|
|
|
|
|
|
|
|
const {
|
|
|
|
_language
|
|
|
|
} = state['features/subtitles'];
|
|
|
|
|
|
|
|
return {
|
|
|
|
_conference: conference,
|
|
|
|
_language
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-05 11:24:13 +00:00
|
|
|
export default connect(mapStateToProps)(LanguageSelectorDialog);
|