-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dropdown Select by Language #9
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,12 @@ const VoiceDropdown = () => { | |
}) | ||
|
||
voices.then((voices) => { | ||
// Sort voices by language | ||
voices.sort((a, b) => a.lang.localeCompare(b.lang)); | ||
|
||
// Limit number of voices shown to 250 | ||
voices = voices.slice(0, 250); | ||
|
||
setVoices(voices); | ||
}) | ||
}, []); | ||
|
@@ -28,21 +34,38 @@ const VoiceDropdown = () => { | |
setSelectedVoice(event.target.value); | ||
setVoice(voices.find(voice => voice.name === event.target.value)); | ||
}; | ||
|
||
const handleLanguageChange = (event) => { | ||
setSelectedLanguage(event.target.value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method doesn't exist in this PR. |
||
// Filter voices by selected language | ||
const filteredVoices = voices.filter(voice => voice.lang === event.target.value); | ||
|
||
// Set selected voice to the first voice in the filtered voices | ||
setSelectedVoice(filteredVoices[0].name); | ||
setVoice(filteredVoices[0]); | ||
}; | ||
|
||
return ( | ||
<div style={{ display: "flex", alignItems: 'flex-end', justifyContent: "space-between" }}> | ||
<label style={{ paddingRight:" 10px" }}> | ||
Voice | ||
</label> | ||
<select value={ selectedVoice } onChange={handleChange}> | ||
{voices.map((voice) => ( | ||
<option key={voice.name} value={voice.name}> | ||
{voice.name} ({voice.lang}) | ||
</option> | ||
))} | ||
<select value={ selectedLanguage } onChange={handleLanguageChange}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please reformat the code using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I will do |
||
{voices.map((voice) => ( | ||
<option key={voice.name} value={voice.lang}> | ||
{voice.lang} | ||
</option> | ||
))} | ||
</select> | ||
<select value={ selectedVoice } onChange={handleVoiceChange}> | ||
{voices.map((voice) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this list be filtered by the chosen language? We should filter a new list on change and display that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly |
||
<option key={voice.name} value={voice.name}> | ||
{voice.name} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
); | ||
}; | ||
|
||
export default VoiceDropdown ; | ||
export default VoiceDropdown ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?