From f0375889d3c9a558cbb5978110bf4b334326c7df Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Thu, 22 Jun 2023 00:54:07 -0400 Subject: [PATCH 1/6] feat: Default language dropdowns to user's primary language --- src/shared/components/comment/comment-form.tsx | 6 ++++++ src/shared/components/post/post-form.tsx | 8 +++++--- src/shared/utils/app/index.ts | 2 ++ src/shared/utils/app/user-primary-language.ts | 9 +++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) create 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 294960a8..11366fc4 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -1,4 +1,5 @@ import { myAuthRequired } from "@utils/app"; +import getUserPrimaryLanguage from "@utils/app/user-primary-language"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component } from "inferno"; import { T } from "inferno-i18next-dess"; @@ -40,6 +41,10 @@ export class CommentForm extends Component { : undefined : undefined; + const userPrimaryLanguage = getUserPrimaryLanguage( + UserService?.Instance?.myUserInfo + ); + return (
{ {UserService.Instance.myUserInfo ? ( { } render() { - const firstLang = this.state.form.language_id; - const selectedLangs = firstLang ? Array.of(firstLang) : undefined; + const userPrimaryLanguage = getUserPrimaryLanguage( + UserService?.Instance?.myUserInfo + ); const url = this.state.form.url; @@ -494,8 +496,8 @@ export class PostForm extends Component {
diff --git a/src/shared/utils/app/index.ts b/src/shared/utils/app/index.ts index cdae2677..2d2f09e6 100644 --- a/src/shared/utils/app/index.ts +++ b/src/shared/utils/app/index.ts @@ -52,6 +52,7 @@ import showScores from "./show-scores"; import siteBannerCss from "./site-banner-css"; import updateCommunityBlock from "./update-community-block"; import updatePersonBlock from "./update-person-block"; +import getUserPrimaryLanguage from "./user-primary-language"; export { buildCommentsTree, @@ -86,6 +87,7 @@ export { getIdFromProps, getRecipientIdFromProps, getUpdatedSearchId, + getUserPrimaryLanguage, initializeSite, insertCommentIntoTree, isAuthPath, diff --git a/src/shared/utils/app/user-primary-language.ts b/src/shared/utils/app/user-primary-language.ts new file mode 100644 index 00000000..06ae2595 --- /dev/null +++ b/src/shared/utils/app/user-primary-language.ts @@ -0,0 +1,9 @@ +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; +} From bf54d404335a43ea15a9162171249d1fc3ba8782 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Fri, 23 Jun 2023 15:14:16 -0400 Subject: [PATCH 2/6] 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; -} From ccf0a6dbaa86fbc755cdfcce2481eebac338b768 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Fri, 23 Jun 2023 17:21:10 -0400 Subject: [PATCH 3/6] fix: Fix language selection bug --- src/shared/components/comment/comment-form.tsx | 10 ++++++---- src/shared/components/common/markdown-textarea.tsx | 6 +++++- src/shared/components/post/post-form.tsx | 10 ++++++---- src/shared/utils/app/user-interface-language.ts | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 0226e23e..5cce2b53 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -41,10 +41,12 @@ export class CommentForm extends Component { : 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 (
{ 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 ( diff --git a/src/shared/utils/app/user-interface-language.ts b/src/shared/utils/app/user-interface-language.ts index 5ccd61c3..707526d7 100644 --- a/src/shared/utils/app/user-interface-language.ts +++ b/src/shared/utils/app/user-interface-language.ts @@ -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; } From 251592c1bffd134121db1bc4d0e44df0e321aae8 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Fri, 23 Jun 2023 22:09:27 -0400 Subject: [PATCH 4/6] fix: Use simpler syntax for languageId array --- src/shared/components/common/markdown-textarea.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index 119913d3..2d306dca 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -264,7 +264,7 @@ export class MarkdownTextArea extends Component< // in the dropdown; otherwise, set it to 0 (Undetermined) selectedLanguageIds={ languageId && this.props.siteLanguages.includes(languageId) - ? Array.of(languageId) + ? [languageId] : [0] } siteLanguages={this.props.siteLanguages} From 8184e33c9f0143f7df0201449b9738ba2440bd78 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sat, 24 Jun 2023 00:03:49 -0400 Subject: [PATCH 5/6] fix: Fix up some interface language logic and design --- src/shared/components/comment/comment-form.tsx | 7 +------ src/shared/components/common/language-select.tsx | 2 +- src/shared/components/post/post-form.tsx | 7 +------ src/shared/utils/app/user-interface-language.ts | 14 +++++--------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 5cce2b53..c9937c62 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -41,12 +41,7 @@ export class CommentForm extends Component { : undefined : undefined; - const userInterfaceLangId = !UserService.Instance.myUserInfo - ? 0 - : getUserInterfaceLangId({ - myUserInfo: UserService.Instance.myUserInfo, - allLanguages: this.props.allLanguages, - }); + const userInterfaceLangId = getUserInterfaceLangId(this.props.allLanguages); return (
{ return this.props.iconVersion ? ( this.selectBtn ) : ( -
+