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
: undefined; : undefined;
const userInterfaceLangId = getUserInterfaceLangId({ const userInterfaceLangId = !UserService.Instance.myUserInfo
myUserInfo: UserService.Instance.myUserInfo, ? 0
allLanguages: this.props.allLanguages, : getUserInterfaceLangId({
}); myUserInfo: UserService.Instance.myUserInfo,
allLanguages: this.props.allLanguages,
});
return ( return (
<div <div

View file

@ -260,8 +260,12 @@ export class MarkdownTextArea extends Component<
<LanguageSelect <LanguageSelect
iconVersion iconVersion
allLanguages={this.props.allLanguages} 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={ selectedLanguageIds={
languageId ? Array.of(languageId) : undefined languageId && this.props.siteLanguages.includes(languageId)
? Array.of(languageId)
: [0]
} }
siteLanguages={this.props.siteLanguages} siteLanguages={this.props.siteLanguages}
onChange={this.handleLanguageChange} onChange={this.handleLanguageChange}

View file

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