]> Untitled Git - lemmy-ui.git/commitdiff
fix: Fix language selection bug
authorJay Sitter <jay@jaysitter.com>
Fri, 23 Jun 2023 21:21:10 +0000 (17:21 -0400)
committerJay Sitter <jay@jaysitter.com>
Fri, 23 Jun 2023 21:24:07 +0000 (17:24 -0400)
src/shared/components/comment/comment-form.tsx
src/shared/components/common/markdown-textarea.tsx
src/shared/components/post/post-form.tsx
src/shared/utils/app/user-interface-language.ts

index 0226e23ef13cdcce5bc54c57d98ca3f6242d9ac9..5cce2b5322694fc025ea9a695a2ef37b96ba6937 100644 (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
index 97d1d1424d626f87327ea3c2f28beea78fe5fa10..119913d36d0ba62f5f56b6b69b31feb5368d58c0 100644 (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}
index f14eac739372092650d088ad11ab0e7c18218e06..780ea797af2bc8527bb01740706387177138bf16 100644 (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)}>
index 5ccd61c31b97320bfc636bee830161495c8fecaa..707526d780ec856511ac11978f5e861112c4b4f9 100644 (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;
 }