Skip to content

Commit

Permalink
Dont preselect new post language
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Nutomic committed May 13, 2023
1 parent 2d7c766 commit 3da238b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lemmy-translations
Submodule lemmy-translations updated 54 files
+13 −0 .woodpecker.yml
+3 −1 README.md
+16 −16 email/fi.json
+11 −11 email/it.json
+16 −16 email/ko.json
+16 −16 email/pt.json
+486 −486 translations/ar.json
+78 −78 translations/as.json
+393 −393 translations/bg.json
+106 −106 translations/bn.json
+309 −309 translations/ca.json
+373 −373 translations/cs.json
+28 −28 translations/cy.json
+478 −281 translations/da.json
+357 −357 translations/de.json
+463 −463 translations/el.json
+481 −481 translations/en.json
+478 −475 translations/eo.json
+478 −475 translations/es.json
+439 −439 translations/eu.json
+297 −297 translations/fa.json
+467 −467 translations/fi.json
+376 −376 translations/fr.json
+330 −330 translations/ga.json
+455 −455 translations/gl.json
+35 −35 translations/got.json
+64 −64 translations/hi.json
+414 −414 translations/hu.json
+398 −398 translations/id.json
+419 −419 translations/it.json
+458 −415 translations/ja.json
+227 −227 translations/ka.json
+440 −440 translations/ko.json
+278 −278 translations/lt.json
+182 −182 translations/ml.json
+15 −15 translations/mnc.json
+43 −43 translations/nb_NO.json
+393 −393 translations/nl.json
+412 −412 translations/oc.json
+478 −478 translations/pl.json
+414 −414 translations/pt.json
+464 −460 translations/pt_BR.json
+410 −410 translations/ru.json
+28 −28 translations/sk.json
+239 −239 translations/sq.json
+56 −56 translations/sr_Latn.json
+360 −360 translations/sv.json
+139 −139 translations/th.json
+250 −250 translations/tr.json
+323 −323 translations/uk.json
+376 −376 translations/vi.json
+379 −379 translations/zh.json
+396 −396 translations/zh_Hant.json
+140 −140 translators.json
11 changes: 0 additions & 11 deletions src/shared/components/comment/comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { UserService, WebSocketService } from "../../services";
import {
capitalizeFirstLetter,
myAuth,
myFirstDiscussionLanguageId,
wsClient,
wsSubscribe,
} from "../../utils";
Expand Down Expand Up @@ -77,21 +76,11 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
: 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 (
<div className="mb-3">
{UserService.Instance.myUserInfo ? (
<MarkdownTextArea
initialContent={initialContent}
initialLanguageId={selectedLang}
showLanguage
buttonTitle={this.state.buttonTitle}
finished={this.state.finished}
Expand Down
5 changes: 5 additions & 0 deletions src/shared/components/common/language-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export class LanguageSelect extends Component<LanguageSelectProps, any> {
multiple={this.props.multiple}
disabled={this.props.disabled}
>
{!this.props.multiple && (
<option selected disabled hidden>
{i18n.t("language_select_placeholder")}
</option>
)}
{filteredLangs.map(l => (
<option
key={l.id}
Expand Down
9 changes: 1 addition & 8 deletions src/shared/components/post/post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
ghostArchiveUrl,
isImage,
myAuth,
myFirstDiscussionLanguageId,
pictrsDeleteToast,
relTags,
setupTippy,
Expand Down Expand Up @@ -187,13 +186,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
}

render() {
let firstLang =
this.state.form.language_id ??
myFirstDiscussionLanguageId(
this.props.allLanguages,
this.props.siteLanguages,
UserService.Instance.myUserInfo
);
let firstLang = this.state.form.language_id;
let selectedLangs = firstLang ? Array.of(firstLang) : undefined;

let url = this.state.form.url;
Expand Down
14 changes: 0 additions & 14 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
siteRes: GetSiteResponse,
myUserInfo = UserService.Instance.myUserInfo
Expand Down

0 comments on commit 3da238b

Please sign in to comment.