From: Jay Sitter Date: Thu, 22 Jun 2023 04:54:07 +0000 (-0400) Subject: feat: Default language dropdowns to user's primary language X-Git-Url: http://these/git/%7B%60/feeds/%7B%60%24%7BarchiveUrl%7D/%7BimageThumbnailer%28this.getImage%28%29%29%7D?a=commitdiff_plain;h=f0375889d3c9a558cbb5978110bf4b334326c7df;p=lemmy-ui.git feat: Default language dropdowns to user's primary language --- diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 294960a..11366fc 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 cdae267..2d2f09e 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 0000000..06ae259 --- /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; +}