@@ -12,8 +12,8 @@ import { Check } from '@openedx/paragon/icons';
12
12
import { connect , useDispatch } from 'react-redux' ;
13
13
import { useIntl } from '@edx/frontend-platform/i18n' ;
14
14
import { thunkActions , selectors } from '../../../../../../data/redux' ;
15
- import { videoTranscriptLanguages } from '../../../../../../data/constants/video' ;
16
15
import { FileInput , fileInput } from '../../../../../../sharedComponents/FileInput' ;
16
+ import { getLanguageName } from '../../../../../../data/constants/video' ;
17
17
import messages from './messages' ;
18
18
19
19
export const hooks = {
@@ -45,27 +45,27 @@ export const hooks = {
45
45
} ;
46
46
47
47
const LanguageSelector = ( {
48
- index, // For a unique id for the form control
48
+ index,
49
49
language,
50
- // Redux
51
- openLanguages, // Only allow those languages not already associated with a transcript to be selected
50
+ openLanguages,
52
51
} ) => {
53
52
const intl = useIntl ( ) ;
53
+ const dispatch = useDispatch ( ) ;
54
+
54
55
const [ localLang , setLocalLang ] = React . useState ( language ) ;
55
- const input = fileInput ( { onAddFile : hooks . addFileCallback ( { dispatch : useDispatch ( ) , localLang } ) } ) ;
56
+ const input = fileInput ( { onAddFile : hooks . addFileCallback ( { dispatch, localLang } ) } ) ;
56
57
const onLanguageChange = hooks . onSelectLanguage ( {
57
- dispatch : useDispatch ( ) , languageBeforeChange : localLang , setLocalLang, triggerupload : input . click ,
58
+ dispatch, languageBeforeChange : localLang , setLocalLang, triggerupload : input . click ,
58
59
} ) ;
59
60
60
61
const getTitle = ( ) => {
61
- if ( Object . prototype . hasOwnProperty . call ( videoTranscriptLanguages , language ) ) {
62
+ if ( language ) {
62
63
return (
63
64
< ActionRow >
64
- { videoTranscriptLanguages [ language ] }
65
+ { getLanguageName ( language ) }
65
66
< ActionRow . Spacer />
66
67
< Icon className = "text-primary-500" src = { Check } />
67
68
</ ActionRow >
68
-
69
69
) ;
70
70
}
71
71
return (
@@ -78,10 +78,7 @@ const LanguageSelector = ({
78
78
79
79
return (
80
80
< >
81
-
82
- < Dropdown
83
- className = "w-100 mb-2"
84
- >
81
+ < Dropdown className = "w-100 mb-2" >
85
82
< Dropdown . Toggle
86
83
iconAs = { Button }
87
84
aria-label = { intl . formatMessage ( messages . languageSelectLabel ) }
@@ -93,14 +90,25 @@ const LanguageSelector = ({
93
90
{ getTitle ( ) }
94
91
</ Dropdown . Toggle >
95
92
< Dropdown . Menu >
96
- { Object . entries ( videoTranscriptLanguages ) . map ( ( [ lang , text ] ) => {
93
+ { openLanguages . map ( lang => {
94
+ const name = getLanguageName ( lang ) ;
95
+
97
96
if ( language === lang ) {
98
- return ( < Dropdown . Item > { text } < Icon className = "text-primary-500" src = { Check } /> </ Dropdown . Item > ) ;
99
- }
100
- if ( openLanguages . some ( row => row . includes ( lang ) ) ) {
101
- return ( < Dropdown . Item onClick = { ( ) => onLanguageChange ( { newLang : lang } ) } > { text } </ Dropdown . Item > ) ;
97
+ return (
98
+ < Dropdown . Item key = { lang } >
99
+ { name }
100
+ < Icon className = "text-primary-500" src = { Check } />
101
+ </ Dropdown . Item >
102
+ ) ;
102
103
}
103
- return ( < Dropdown . Item className = "disabled" > { text } </ Dropdown . Item > ) ;
104
+ return (
105
+ < Dropdown . Item
106
+ key = { lang }
107
+ onClick = { ( ) => onLanguageChange ( { newLang : lang } ) }
108
+ >
109
+ { name }
110
+ </ Dropdown . Item >
111
+ ) ;
104
112
} ) }
105
113
</ Dropdown . Menu >
106
114
</ Dropdown >
0 commit comments