1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { connect } from 'react-redux' ;
4
- import { FormattedMessage } from 'react-intl' ;
4
+ import { FormattedMessage , intlShape , injectIntl } from 'react-intl' ;
5
5
import ISO6391 from 'iso-639-1' ;
6
6
import List from '@material-ui/core/List' ;
7
7
import ListItem from '@material-ui/core/ListItem' ;
8
8
import ListItemText from '@material-ui/core/ListItemText' ;
9
9
import Paper from '@material-ui/core/Paper' ;
10
10
import CheckIcon from '@material-ui/icons/Check' ;
11
+ import WarningIcon from '@material-ui/icons/Warning' ;
11
12
import { Button } from '@material-ui/core' ;
12
13
import Dialog from '@material-ui/core/Dialog' ;
13
14
import DialogTitle from '@material-ui/core/DialogTitle' ;
14
15
import DialogContent from '@material-ui/core/DialogContent' ;
15
16
import DialogActions from '@material-ui/core/DialogActions' ;
17
+ import DialogContentText from '@material-ui/core/DialogContentText' ;
16
18
import Slide from '@material-ui/core/Slide' ;
19
+ import Select from '@material-ui/core/Select' ;
20
+ import InputLabel from '@material-ui/core/InputLabel' ;
21
+ import FormControl from '@material-ui/core/FormControl' ;
22
+ import MenuItem from '@material-ui/core/MenuItem' ;
23
+ import Divider from '@material-ui/core/Divider' ;
24
+ import CircularProgress from '@material-ui/core/CircularProgress' ;
17
25
import ReactMarkdown from 'react-markdown' ;
18
26
19
27
import FullScreenDialog from '../../UI/FullScreenDialog' ;
@@ -28,6 +36,7 @@ const Transition = React.forwardRef(function Transition(props, ref) {
28
36
29
37
class Language extends React . Component {
30
38
static propTypes = {
39
+ intl : intlShape . isRequired ,
31
40
/**
32
41
* Languages to display
33
42
*/
@@ -48,7 +57,16 @@ class Language extends React.Component {
48
57
* Callback fired when submitting selected language
49
58
*/
50
59
onSubmitLang : PropTypes . func . isRequired ,
51
- language : PropTypes . object . isRequired
60
+ language : PropTypes . object . isRequired ,
61
+ /**
62
+ * TTS engines list
63
+ */
64
+ ttsEngines : PropTypes . arrayOf ( PropTypes . object ) ,
65
+ /**
66
+ * TTS default engine
67
+ */
68
+ ttsEngine : PropTypes . object ,
69
+ setTtsEngine : PropTypes . func . isRequired
52
70
} ;
53
71
54
72
static defaultProps = {
@@ -61,6 +79,9 @@ class Language extends React.Component {
61
79
62
80
this . state = {
63
81
moreLangDialog : false ,
82
+ loading : false ,
83
+ ttsEngine : props . ttsEngine . name ,
84
+ openTtsEngineError : false ,
64
85
markdown : ''
65
86
} ;
66
87
}
@@ -94,6 +115,32 @@ class Language extends React.Component {
94
115
}
95
116
}
96
117
118
+ componentDidUpdate ( prevProps ) {
119
+ if ( this . props . ttsEngine . name !== prevProps . ttsEngine . name ) {
120
+ this . setState ( {
121
+ ttsEngine : this . props . ttsEngine . name ,
122
+ loading : false
123
+ } ) ;
124
+ }
125
+ }
126
+
127
+ async handleTtsEngineChange ( event ) {
128
+ const { setTtsEngine } = this . props ;
129
+ this . setState ( {
130
+ ttsEngine : event . target . value ,
131
+ loading : true
132
+ } ) ;
133
+ try {
134
+ await setTtsEngine ( event . target . value ) ;
135
+ } catch ( err ) {
136
+ this . setState ( {
137
+ ttsEngine : this . props . ttsEngine . name ,
138
+ loading : false ,
139
+ openTtsEngineError : true
140
+ } ) ;
141
+ }
142
+ }
143
+
97
144
handleMoreLangClick ( ) {
98
145
this . setState ( { moreLangDialog : true } ) ;
99
146
}
@@ -102,9 +149,15 @@ class Language extends React.Component {
102
149
this . setState ( { moreLangDialog : false } ) ;
103
150
}
104
151
152
+ handleTtsErrorDialogClose ( ) {
153
+ this . setState ( { openTtsEngineError : false } ) ;
154
+ }
155
+
105
156
render ( ) {
106
157
const {
107
158
langs,
159
+ intl,
160
+ ttsEngines,
108
161
selectedLang,
109
162
onLangClick,
110
163
onClose,
@@ -152,7 +205,76 @@ class Language extends React.Component {
152
205
onSubmit = { onSubmitLang }
153
206
>
154
207
< Paper >
155
- < List > { langItems } </ List >
208
+ { isCordova ( ) && (
209
+ < React . Fragment >
210
+ < div className = "Settings__Language__TTSEnginesContainer" >
211
+ < FormControl
212
+ className = "Settings__Language__TTSEnginesContainer__Select"
213
+ variant = "standard"
214
+ error = { this . state . ttsEngineError }
215
+ disabled = { this . state . loading }
216
+ >
217
+ < InputLabel id = "tts-engines-select-label" >
218
+ < FormattedMessage { ...messages . ttsEngines } />
219
+ </ InputLabel >
220
+ < Select
221
+ labelId = "tts-engines-select-label"
222
+ id = "tts-engines-select"
223
+ autoWidth = { false }
224
+ value = { this . state . ttsEngine }
225
+ onChange = { this . handleTtsEngineChange . bind ( this ) }
226
+ inputProps = { {
227
+ name : 'tts-engine' ,
228
+ id : 'language-tts-engine'
229
+ } }
230
+ >
231
+ { ttsEngines . map ( ( ttsEng , i ) => (
232
+ < MenuItem key = { i } value = { ttsEng . name } >
233
+ { ttsEng . label }
234
+ </ MenuItem >
235
+ ) ) }
236
+ </ Select >
237
+ </ FormControl >
238
+ </ div >
239
+ < Divider variant = "middle" />
240
+ </ React . Fragment >
241
+ ) }
242
+ { this . state . loading ? (
243
+ < CircularProgress
244
+ size = { 60 }
245
+ className = "Settings__Language__Spinner"
246
+ thickness = { 5 }
247
+ />
248
+ ) : (
249
+ < List > { langItems } </ List >
250
+ ) }
251
+ < Dialog
252
+ onClose = { this . handleTtsErrorDialogClose . bind ( this ) }
253
+ aria-labelledby = "tts-error-dialog"
254
+ open = { this . state . openTtsEngineError }
255
+ className = "CommunicatorDialog__boardInfoDialog"
256
+ >
257
+ < DialogTitle
258
+ id = "tts-error-dialog-title"
259
+ onClose = { this . handleTtsErrorDialogClose . bind ( this ) }
260
+ >
261
+ < WarningIcon />
262
+ { intl . formatMessage ( messages . ttsEngines ) }
263
+ </ DialogTitle >
264
+ < DialogContent >
265
+ < DialogContentText >
266
+ { intl . formatMessage ( messages . ttsEngineError ) }
267
+ </ DialogContentText >
268
+ </ DialogContent >
269
+ < DialogActions >
270
+ < Button
271
+ onClick = { this . handleTtsErrorDialogClose . bind ( this ) }
272
+ color = "primary"
273
+ >
274
+ { intl . formatMessage ( messages . close ) }
275
+ </ Button >
276
+ </ DialogActions >
277
+ </ Dialog >
156
278
</ Paper >
157
279
< div className = "Settings__Language__MoreLang" >
158
280
< Button color = "primary" onClick = { this . handleMoreLangClick . bind ( this ) } >
@@ -200,4 +322,4 @@ const mapDispatchToProps = {};
200
322
export default connect (
201
323
mapStateToProps ,
202
324
mapDispatchToProps
203
- ) ( Language ) ;
325
+ ) ( injectIntl ( Language ) ) ;
0 commit comments