mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-29 15:51:14 +00:00
Dont preselect new post language (#1008)
Lemmy-ui currently preselects the first language in the user settings when creating a new post or comment. This is a bad idea because this language might not actually be allowed in the community. It is better to pass the language as None if the user didnt specify it explicitly, because then the backend can smartly choose a language based on the overlap of user languages and community languages. This fixes the problem described in [this thread](https://lemmy.ml/post/1066608), where a user tries to post in a community that has only English allowed, with all languages enabled in user settings. In this case lemmy-ui preselects "undetermined language" as default, which is not allowed and results in an error. This PR fixes the issue because it lets the backend automatically select the correct language (English).
This commit is contained in:
parent
2d7c7664ee
commit
1683a745b5
5 changed files with 7 additions and 34 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 007e53683768aeba63e9e4c179c1d240217bcee2
|
Subproject commit a1fff8b481f4b02327e4ee04088606af627628f2
|
|
@ -17,7 +17,6 @@ import { UserService, WebSocketService } from "../../services";
|
||||||
import {
|
import {
|
||||||
capitalizeFirstLetter,
|
capitalizeFirstLetter,
|
||||||
myAuth,
|
myAuth,
|
||||||
myFirstDiscussionLanguageId,
|
|
||||||
wsClient,
|
wsClient,
|
||||||
wsSubscribe,
|
wsSubscribe,
|
||||||
} from "../../utils";
|
} from "../../utils";
|
||||||
|
@ -77,21 +76,11 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
||||||
: undefined
|
: undefined
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
let selectedLang =
|
|
||||||
typeof this.props.node !== "number"
|
|
||||||
? this.props.node.comment_view.comment.language_id
|
|
||||||
: myFirstDiscussionLanguageId(
|
|
||||||
this.props.allLanguages,
|
|
||||||
this.props.siteLanguages,
|
|
||||||
UserService.Instance.myUserInfo
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
{UserService.Instance.myUserInfo ? (
|
{UserService.Instance.myUserInfo ? (
|
||||||
<MarkdownTextArea
|
<MarkdownTextArea
|
||||||
initialContent={initialContent}
|
initialContent={initialContent}
|
||||||
initialLanguageId={selectedLang}
|
|
||||||
showLanguage
|
showLanguage
|
||||||
buttonTitle={this.state.buttonTitle}
|
buttonTitle={this.state.buttonTitle}
|
||||||
finished={this.state.finished}
|
finished={this.state.finished}
|
||||||
|
|
|
@ -111,6 +111,11 @@ export class LanguageSelect extends Component<LanguageSelectProps, any> {
|
||||||
multiple={this.props.multiple}
|
multiple={this.props.multiple}
|
||||||
disabled={this.props.disabled}
|
disabled={this.props.disabled}
|
||||||
>
|
>
|
||||||
|
{!this.props.multiple && (
|
||||||
|
<option selected disabled hidden>
|
||||||
|
{i18n.t("language_select_placeholder")}
|
||||||
|
</option>
|
||||||
|
)}
|
||||||
{filteredLangs.map(l => (
|
{filteredLangs.map(l => (
|
||||||
<option
|
<option
|
||||||
key={l.id}
|
key={l.id}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import {
|
||||||
ghostArchiveUrl,
|
ghostArchiveUrl,
|
||||||
isImage,
|
isImage,
|
||||||
myAuth,
|
myAuth,
|
||||||
myFirstDiscussionLanguageId,
|
|
||||||
pictrsDeleteToast,
|
pictrsDeleteToast,
|
||||||
relTags,
|
relTags,
|
||||||
setupTippy,
|
setupTippy,
|
||||||
|
@ -187,13 +186,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let firstLang =
|
let firstLang = this.state.form.language_id;
|
||||||
this.state.form.language_id ??
|
|
||||||
myFirstDiscussionLanguageId(
|
|
||||||
this.props.allLanguages,
|
|
||||||
this.props.siteLanguages,
|
|
||||||
UserService.Instance.myUserInfo
|
|
||||||
);
|
|
||||||
let selectedLangs = firstLang ? Array.of(firstLang) : undefined;
|
let selectedLangs = firstLang ? Array.of(firstLang) : undefined;
|
||||||
|
|
||||||
let url = this.state.form.url;
|
let url = this.state.form.url;
|
||||||
|
|
|
@ -1453,20 +1453,6 @@ export function postToCommentSortType(sort: SortType): CommentSortType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function myFirstDiscussionLanguageId(
|
|
||||||
allLanguages: Language[],
|
|
||||||
siteLanguages: number[],
|
|
||||||
myUserInfo = UserService.Instance.myUserInfo
|
|
||||||
): number | undefined {
|
|
||||||
return selectableLanguages(
|
|
||||||
allLanguages,
|
|
||||||
siteLanguages,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
myUserInfo
|
|
||||||
).at(0)?.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function canCreateCommunity(
|
export function canCreateCommunity(
|
||||||
siteRes: GetSiteResponse,
|
siteRes: GetSiteResponse,
|
||||||
myUserInfo = UserService.Instance.myUserInfo
|
myUserInfo = UserService.Instance.myUserInfo
|
||||||
|
|
Loading…
Reference in a new issue