From bf54d404335a43ea15a9162171249d1fc3ba8782 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Fri, 23 Jun 2023 15:14:16 -0400 Subject: [PATCH] fix: Use Interface Language instead --- .../components/comment/comment-form.tsx | 11 +++++----- src/shared/components/post/post-form.tsx | 13 ++++++----- src/shared/utils/app/index.ts | 4 ++-- .../utils/app/user-interface-language.ts | 22 +++++++++++++++++++ src/shared/utils/app/user-primary-language.ts | 9 -------- 5 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 src/shared/utils/app/user-interface-language.ts delete mode 100644 src/shared/utils/app/user-primary-language.ts diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 11366fc4..0226e23e 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -1,5 +1,5 @@ import { myAuthRequired } from "@utils/app"; -import getUserPrimaryLanguage from "@utils/app/user-primary-language"; +import getUserInterfaceLangId from "@utils/app/user-interface-language"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component } from "inferno"; import { T } from "inferno-i18next-dess"; @@ -41,9 +41,10 @@ export class CommentForm extends Component { : undefined : undefined; - const userPrimaryLanguage = getUserPrimaryLanguage( - UserService?.Instance?.myUserInfo - ); + const userInterfaceLangId = getUserInterfaceLangId({ + myUserInfo: UserService.Instance.myUserInfo, + allLanguages: this.props.allLanguages, + }); return (
{ {UserService.Instance.myUserInfo ? ( { } render() { - const userPrimaryLanguage = getUserPrimaryLanguage( - UserService?.Instance?.myUserInfo - ); - const url = this.state.form.url; + const userInterfaceLangId = getUserInterfaceLangId({ + myUserInfo: UserService.Instance.myUserInfo, + allLanguages: this.props.allLanguages, + }); + return (
{
{ + return i18nLang.indexOf(lang.code) === 0; + }); + + // Return the ID of that language object + return userLang.id || 0; +} diff --git a/src/shared/utils/app/user-primary-language.ts b/src/shared/utils/app/user-primary-language.ts deleted file mode 100644 index 06ae2595..00000000 --- a/src/shared/utils/app/user-primary-language.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { UserService } from "../../services"; - -export default function getUserPrimaryLanguage( - myUserInfo = UserService.Instance.myUserInfo -): number { - // Get first language in discussion languages array that isn't equal to "0", - // which is the language selection "Undetermined" - return myUserInfo?.discussion_languages.find(lang => lang !== 0) || 0; -}