mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2025-01-17 12:11:26 +00:00
feat: Default language dropdowns to user's primary language
This commit is contained in:
parent
cda9bd0a79
commit
f0375889d3
src/shared
|
@ -1,4 +1,5 @@
|
||||||
import { myAuthRequired } from "@utils/app";
|
import { myAuthRequired } from "@utils/app";
|
||||||
|
import getUserPrimaryLanguage from "@utils/app/user-primary-language";
|
||||||
import { capitalizeFirstLetter } from "@utils/helpers";
|
import { capitalizeFirstLetter } from "@utils/helpers";
|
||||||
import { Component } from "inferno";
|
import { Component } from "inferno";
|
||||||
import { T } from "inferno-i18next-dess";
|
import { T } from "inferno-i18next-dess";
|
||||||
|
@ -40,6 +41,10 @@ export class CommentForm extends Component<CommentFormProps, any> {
|
||||||
: undefined
|
: undefined
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
const userPrimaryLanguage = getUserPrimaryLanguage(
|
||||||
|
UserService?.Instance?.myUserInfo
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={["comment-form", "mb-3", this.props.containerClass].join(
|
className={["comment-form", "mb-3", this.props.containerClass].join(
|
||||||
|
@ -49,6 +54,7 @@ export class CommentForm extends Component<CommentFormProps, any> {
|
||||||
{UserService.Instance.myUserInfo ? (
|
{UserService.Instance.myUserInfo ? (
|
||||||
<MarkdownTextArea
|
<MarkdownTextArea
|
||||||
initialContent={initialContent}
|
initialContent={initialContent}
|
||||||
|
initialLanguageId={userPrimaryLanguage}
|
||||||
showLanguage
|
showLanguage
|
||||||
buttonTitle={this.buttonTitle}
|
buttonTitle={this.buttonTitle}
|
||||||
finished={this.props.finished}
|
finished={this.props.finished}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
myAuth,
|
myAuth,
|
||||||
myAuthRequired,
|
myAuthRequired,
|
||||||
} from "@utils/app";
|
} from "@utils/app";
|
||||||
|
import getUserPrimaryLanguage from "@utils/app/user-primary-language";
|
||||||
import {
|
import {
|
||||||
capitalizeFirstLetter,
|
capitalizeFirstLetter,
|
||||||
debounce,
|
debounce,
|
||||||
|
@ -323,8 +324,9 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const firstLang = this.state.form.language_id;
|
const userPrimaryLanguage = getUserPrimaryLanguage(
|
||||||
const selectedLangs = firstLang ? Array.of(firstLang) : undefined;
|
UserService?.Instance?.myUserInfo
|
||||||
|
);
|
||||||
|
|
||||||
const url = this.state.form.url;
|
const url = this.state.form.url;
|
||||||
|
|
||||||
|
@ -494,8 +496,8 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
</div>
|
</div>
|
||||||
<LanguageSelect
|
<LanguageSelect
|
||||||
allLanguages={this.props.allLanguages}
|
allLanguages={this.props.allLanguages}
|
||||||
|
selectedLanguageIds={[userPrimaryLanguage]}
|
||||||
siteLanguages={this.props.siteLanguages}
|
siteLanguages={this.props.siteLanguages}
|
||||||
selectedLanguageIds={selectedLangs}
|
|
||||||
multiple={false}
|
multiple={false}
|
||||||
onChange={this.handleLanguageChange}
|
onChange={this.handleLanguageChange}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -52,6 +52,7 @@ import showScores from "./show-scores";
|
||||||
import siteBannerCss from "./site-banner-css";
|
import siteBannerCss from "./site-banner-css";
|
||||||
import updateCommunityBlock from "./update-community-block";
|
import updateCommunityBlock from "./update-community-block";
|
||||||
import updatePersonBlock from "./update-person-block";
|
import updatePersonBlock from "./update-person-block";
|
||||||
|
import getUserPrimaryLanguage from "./user-primary-language";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
buildCommentsTree,
|
buildCommentsTree,
|
||||||
|
@ -86,6 +87,7 @@ export {
|
||||||
getIdFromProps,
|
getIdFromProps,
|
||||||
getRecipientIdFromProps,
|
getRecipientIdFromProps,
|
||||||
getUpdatedSearchId,
|
getUpdatedSearchId,
|
||||||
|
getUserPrimaryLanguage,
|
||||||
initializeSite,
|
initializeSite,
|
||||||
insertCommentIntoTree,
|
insertCommentIntoTree,
|
||||||
isAuthPath,
|
isAuthPath,
|
||||||
|
|
9
src/shared/utils/app/user-primary-language.ts
Normal file
9
src/shared/utils/app/user-primary-language.ts
Normal file
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in a new issue