fix: Fix language selection bug

This commit is contained in:
Jay Sitter 2023-06-23 17:21:10 -04:00
parent bf54d40433
commit ccf0a6dbaa
4 changed files with 18 additions and 10 deletions

View file

@ -41,10 +41,12 @@ export class CommentForm extends Component<CommentFormProps, any> {
: undefined
: undefined;
const userInterfaceLangId = getUserInterfaceLangId({
myUserInfo: UserService.Instance.myUserInfo,
allLanguages: this.props.allLanguages,
});
const userInterfaceLangId = !UserService.Instance.myUserInfo
? 0
: getUserInterfaceLangId({
myUserInfo: UserService.Instance.myUserInfo,
allLanguages: this.props.allLanguages,
});
return (
<div

View file

@ -260,8 +260,12 @@ export class MarkdownTextArea extends Component<
<LanguageSelect
iconVersion
allLanguages={this.props.allLanguages}
// Only set the selected language ID if it exists as an option
// in the dropdown; otherwise, set it to 0 (Undetermined)
selectedLanguageIds={
languageId ? Array.of(languageId) : undefined
languageId && this.props.siteLanguages.includes(languageId)
? Array.of(languageId)
: [0]
}
siteLanguages={this.props.siteLanguages}
onChange={this.handleLanguageChange}

View file

@ -326,10 +326,12 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
render() {
const url = this.state.form.url;
const userInterfaceLangId = getUserInterfaceLangId({
myUserInfo: UserService.Instance.myUserInfo,
allLanguages: this.props.allLanguages,
});
const userInterfaceLangId = !UserService.Instance.myUserInfo
? 0
: getUserInterfaceLangId({
myUserInfo: UserService.Instance.myUserInfo,
allLanguages: this.props.allLanguages,
});
return (
<form className="post-form" onSubmit={linkEvent(this, handlePostSubmit)}>

View file

@ -17,6 +17,6 @@ export default function getUserInterfaceLanguageId({
return i18nLang.indexOf(lang.code) === 0;
});
// Return the ID of that language object
// Return the ID of that language object, or "0" for Undetermined
return userLang.id || 0;
}