From afeb64009b1f5b44e831d35cc67c3c79e21292b7 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 19 Dec 2022 10:57:29 -0500 Subject: [PATCH] Adding Community Language fixes. #783 (#868) * Partially done with language tagging. #783 * A few more updates. --- .prettierrc.js | 4 - .prettierrc.json | 4 + lemmy-translations | 2 +- package.json | 14 +-- src/assets/css/main.css | 10 +- .../components/comment/comment-form.tsx | 10 +- .../components/comment/comment-node.tsx | 4 + .../components/comment/comment-nodes.tsx | 2 + .../components/comment/comment-report.tsx | 1 + .../components/common/language-select.tsx | 65 ++++++---- .../components/common/markdown-textarea.tsx | 24 ++-- .../common/registration-application.tsx | 1 + .../components/community/community-form.tsx | 24 ++++ src/shared/components/community/community.tsx | 27 ++++- .../components/community/create-community.tsx | 7 +- src/shared/components/community/sidebar.tsx | 10 +- src/shared/components/home/home.tsx | 2 + src/shared/components/home/signup.tsx | 1 + src/shared/components/home/site-form.tsx | 112 +++++++++--------- src/shared/components/person/inbox.tsx | 4 + .../components/person/person-details.tsx | 5 + src/shared/components/person/profile.tsx | 1 + src/shared/components/person/settings.tsx | 5 +- src/shared/components/post/create-post.tsx | 1 + src/shared/components/post/post-form.tsx | 13 +- src/shared/components/post/post-listing.tsx | 2 + src/shared/components/post/post-listings.tsx | 2 + src/shared/components/post/post-report.tsx | 1 + src/shared/components/post/post.tsx | 7 ++ .../private_message/private-message-form.tsx | 1 + src/shared/components/search.tsx | 4 + src/shared/utils.ts | 48 +++++++- yarn.lock | 73 ++++++++---- 33 files changed, 360 insertions(+), 131 deletions(-) delete mode 100644 .prettierrc.js create mode 100644 .prettierrc.json diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 8d36af38..00000000 --- a/.prettierrc.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = Object.assign(require("eslint-plugin-prettier"), { - arrowParens: "avoid", - semi: true, -}); diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 00000000..15bc4fef --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,4 @@ +{ + "arrowParens": "avoid", + "semi": true +} diff --git a/lemmy-translations b/lemmy-translations index a2f59fcb..c9700569 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit a2f59fcbf7529a1f7dd5cda894381ef2000b9ef5 +Subproject commit c97005696d132acf2cad3506df4f3c2256142349 diff --git a/package.json b/package.json index 002db3f5..9d144465 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:prod": "webpack --mode=production", "clean": "yarn run rimraf dist", "dev": "yarn start", - "lint": "node generate_translations.js && tsc --noEmit && eslint --report-unused-disable-directives --ext .js,.ts,.tsx src", + "lint": "node generate_translations.js && tsc --noEmit && eslint --report-unused-disable-directives --ext .js,.ts,.tsx src && prettier --check 'src/**/*.tsx'", "prebuild:dev": "yarn clean && node generate_translations.js", "prebuild:prod": "yarn clean && node generate_translations.js", "prepare": "husky install", @@ -38,16 +38,16 @@ "express": "~4.18.1", "html-to-text": "^8.2.1", "i18next": "^21.8.14", - "inferno": "^8.0.3", - "inferno-create-element": "^8.0.3", + "inferno": "^8.0.5", + "inferno-create-element": "^8.0.5", "inferno-helmet": "^5.2.1", - "inferno-hydrate": "^8.0.3", + "inferno-hydrate": "^8.0.5", "inferno-i18next-dess": "0.0.2", - "inferno-router": "^8.0.3", - "inferno-server": "^8.0.3", + "inferno-router": "^8.0.5", + "inferno-server": "^8.0.5", "isomorphic-cookie": "^1.2.4", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.17.0-rc.56", + "lemmy-js-client": "0.17.0-rc.57", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", "markdown-it-footnote": "^3.0.3", diff --git a/src/assets/css/main.css b/src/assets/css/main.css index a2a2a65c..98e98d26 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -385,4 +385,12 @@ br.big { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; -} \ No newline at end of file +} + +.lang-select-action { + width: 100px; +} + +.lang-select-action:focus { + width: auto; +} diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index d9630fda..a74cc8be 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -35,6 +35,7 @@ interface CommentFormProps { focus?: boolean; onReplyCancel?(): any; allLanguages: Language[]; + siteLanguages: number[]; } interface CommentFormState { @@ -81,7 +82,13 @@ export class CommentForm extends Component { let selectedLang = this.props.node .left() .map(n => n.comment_view.comment.language_id) - .or(myFirstDiscussionLanguageId(UserService.Instance.myUserInfo)); + .or( + myFirstDiscussionLanguageId( + this.props.allLanguages, + this.props.siteLanguages, + UserService.Instance.myUserInfo + ) + ); return (
@@ -100,6 +107,7 @@ export class CommentForm extends Component { onReplyCancel={this.handleReplyCancel} placeholder={Some(i18n.t("comment_here"))} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> ) : (
diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 4555ff58..e37c68e7 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -104,6 +104,7 @@ interface CommentNodeProps { enableDownvotes: boolean; viewType: CommentViewType; allLanguages: Language[]; + siteLanguages: number[]; hideImages?: boolean; } @@ -329,6 +330,7 @@ export class CommentNode extends Component { disabled={this.props.locked} focus allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> )} {!this.state.showEdit && !this.state.collapsed && ( @@ -1015,6 +1017,7 @@ export class CommentNode extends Component { disabled={this.props.locked} focus allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> )} {!this.state.collapsed && node.children.length > 0 && ( @@ -1027,6 +1030,7 @@ export class CommentNode extends Component { enableDownvotes={this.props.enableDownvotes} viewType={this.props.viewType} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} hideImages={this.props.hideImages} /> )} diff --git a/src/shared/components/comment/comment-nodes.tsx b/src/shared/components/comment/comment-nodes.tsx index 5c1f2960..9072e723 100644 --- a/src/shared/components/comment/comment-nodes.tsx +++ b/src/shared/components/comment/comment-nodes.tsx @@ -24,6 +24,7 @@ interface CommentNodesProps { enableDownvotes?: boolean; viewType: CommentViewType; allLanguages: Language[]; + siteLanguages: number[]; hideImages?: boolean; } @@ -55,6 +56,7 @@ export class CommentNodes extends Component { enableDownvotes={this.props.enableDownvotes} viewType={this.props.viewType} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} hideImages={this.props.hideImages} /> ))} diff --git a/src/shared/components/comment/comment-report.tsx b/src/shared/components/comment/comment-report.tsx index b625b447..b90eae41 100644 --- a/src/shared/components/comment/comment-report.tsx +++ b/src/shared/components/comment/comment-report.tsx @@ -65,6 +65,7 @@ export class CommentReport extends Component { viewOnly={true} showCommunity={true} allLanguages={[]} + siteLanguages={[]} hideImages />
diff --git a/src/shared/components/common/language-select.tsx b/src/shared/components/common/language-select.tsx index 746fea4a..c7da2f05 100644 --- a/src/shared/components/common/language-select.tsx +++ b/src/shared/components/common/language-select.tsx @@ -3,14 +3,19 @@ import classNames from "classnames"; import { Component, linkEvent } from "inferno"; import { Language } from "lemmy-js-client"; import { i18n } from "../../i18next"; -import { randomStr } from "../../utils"; +import { UserService } from "../../services/UserService"; +import { randomStr, selectableLanguages } from "../../utils"; import { Icon } from "./icon"; interface LanguageSelectProps { allLanguages: Language[]; + siteLanguages: number[]; selectedLanguageIds: Option; multiple: boolean; onChange(val: number[]): any; + showAll?: boolean; + showSite?: boolean; + iconVersion?: boolean; } export class LanguageSelect extends Component { @@ -42,9 +47,9 @@ export class LanguageSelect extends Component { } render() { - let selectedLangs = this.props.selectedLanguageIds; - - return ( + return this.props.iconVersion ? ( + this.selectBtn + ) : (
@@ -261,6 +272,14 @@ export class CommunityForm extends Component<
+
diff --git a/src/shared/components/community/sidebar.tsx b/src/shared/components/community/sidebar.tsx index 43e863c8..845ef9e4 100644 --- a/src/shared/components/community/sidebar.tsx +++ b/src/shared/components/community/sidebar.tsx @@ -8,6 +8,7 @@ import { CommunityView, DeleteCommunity, FollowCommunity, + Language, PersonViewSafe, PurgeCommunity, RemoveCommunity, @@ -36,9 +37,13 @@ interface SidebarProps { community_view: CommunityView; moderators: CommunityModeratorView[]; admins: PersonViewSafe[]; + allLanguages: Language[]; + siteLanguages: number[]; + communityLanguages: Option; online: number; enableNsfw?: boolean; showIcon?: boolean; + editable?: boolean; } interface SidebarState { @@ -79,6 +84,9 @@ export class Sidebar extends Component { ) : ( {
{this.communityTitle()} - {this.adminButtons()} + {this.props.editable && this.adminButtons()} {this.subscribe()} {this.canPost && this.createPost()} {this.blockCommunity()} diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index 877837be..2b51e8ed 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -589,6 +589,7 @@ export class Home extends Component { enableDownvotes={enableDownvotes(this.state.siteRes)} enableNsfw={enableNsfw(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} /> ) : ( { showContext enableDownvotes={enableDownvotes(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} /> ); } diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index 2f628503..7e35ecd6 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -297,6 +297,7 @@ export class Signup extends Component { onContentChange={this.handleAnswerChange} hideNavigationWarnings allLanguages={[]} + siteLanguages={[]} />
diff --git a/src/shared/components/home/site-form.tsx b/src/shared/components/home/site-form.tsx index 39a6312f..58532b63 100644 --- a/src/shared/components/home/site-form.tsx +++ b/src/shared/components/home/site-form.tsx @@ -272,6 +272,7 @@ export class SiteForm extends Component { onContentChange={this.handleSiteSidebarChange} hideNavigationWarnings allLanguages={[]} + siteLanguages={[]} />
@@ -289,6 +290,7 @@ export class SiteForm extends Component { onContentChange={this.handleSiteLegalInfoChange} hideNavigationWarnings allLanguages={[]} + siteLanguages={[]} /> @@ -307,6 +309,7 @@ export class SiteForm extends Component { onContentChange={this.handleSiteApplicationQuestionChange} hideNavigationWarnings allLanguages={[]} + siteLanguages={[]} /> @@ -568,9 +571,11 @@ export class SiteForm extends Component {
- {siteSetup && ( -
-
{i18n.t("taglines")}
-
- - - - {this.state.siteForm.taglines - .unwrapOr([]) - .map((cv, index) => ( - - + + ))} + +
- - this.handleTaglineChange(this, index, s) - } - hideNavigationWarnings - allLanguages={this.props.siteRes.all_languages} +
+
{i18n.t("taglines")}
+
+ + + + {this.state.siteForm.taglines + .unwrapOr([]) + .map((cv, index) => ( + + + - - - ))} - -
+ + this.handleTaglineChange(this, index, s) + } + hideNavigationWarnings + allLanguages={this.props.siteRes.all_languages} + siteLanguages={ + this.props.siteRes.discussion_languages + } + /> + + - -
- -
+ +
+
- )} +
); @@ -474,6 +477,7 @@ export class Inbox extends Component { showContext enableDownvotes={enableDownvotes(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} /> ))}
diff --git a/src/shared/components/person/person-details.tsx b/src/shared/components/person/person-details.tsx index e228cbdf..f50b6d36 100644 --- a/src/shared/components/person/person-details.tsx +++ b/src/shared/components/person/person-details.tsx @@ -18,6 +18,7 @@ interface PersonDetailsProps { personRes: GetPersonDetailsResponse; admins: PersonViewSafe[]; allLanguages: Language[]; + siteLanguages: number[]; page: number; limit: number; sort: SortType; @@ -102,6 +103,7 @@ export class PersonDetails extends Component { showContext enableDownvotes={this.props.enableDownvotes} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> ); } @@ -118,6 +120,7 @@ export class PersonDetails extends Component { enableDownvotes={this.props.enableDownvotes} enableNsfw={this.props.enableNsfw} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> ); } @@ -176,6 +179,7 @@ export class PersonDetails extends Component { showContext enableDownvotes={this.props.enableDownvotes} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> ); @@ -195,6 +199,7 @@ export class PersonDetails extends Component { enableDownvotes={this.props.enableDownvotes} enableNsfw={this.props.enableNsfw} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} />
diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index 986f9fd9..47399843 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -279,6 +279,7 @@ export class Profile extends Component { view={this.state.view} onPageChange={this.handlePageChange} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} /> diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index 9c1e06ad..0f904d5e 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -168,7 +168,7 @@ export class Settings extends Component { default_sort_type: Some(luv.local_user.default_sort_type), default_listing_type: Some(luv.local_user.default_listing_type), interface_language: Some(luv.local_user.interface_language), - discussion_languages: Some(mui.discussion_languages.map(l => l.id)), + discussion_languages: Some(mui.discussion_languages), avatar: luv.person.avatar, banner: luv.person.banner, display_name: luv.person.display_name, @@ -523,6 +523,7 @@ export class Settings extends Component { buttonTitle={None} hideNavigationWarnings allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} /> @@ -617,8 +618,10 @@ export class Settings extends Component {
diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index 6d4122ce..37c855f6 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -151,6 +151,7 @@ export class CreatePost extends Component { enableDownvotes={enableDownvotes(this.state.siteRes)} enableNsfw={enableNsfw(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} />
diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 0f8ea0bb..abfb5430 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -64,6 +64,7 @@ const MAX_POST_TITLE_LENGTH = 200; interface PostFormProps { post_view: Option; // If a post is given, that means this is an edit allLanguages: Language[]; + siteLanguages: number[]; communities: Option; params: Option; onCancel?(): any; @@ -182,7 +183,13 @@ export class PostForm extends Component { render() { let selectedLangs = this.state.postForm.language_id - .or(myFirstDiscussionLanguageId(UserService.Instance.myUserInfo)) + .or( + myFirstDiscussionLanguageId( + this.props.allLanguages, + this.props.siteLanguages, + UserService.Instance.myUserInfo + ) + ) .map(Array.of); return ( @@ -298,6 +305,7 @@ export class PostForm extends Component { enableDownvotes={this.props.enableDownvotes} enableNsfw={this.props.enableNsfw} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> ), @@ -340,6 +348,7 @@ export class PostForm extends Component { enableDownvotes={this.props.enableDownvotes} enableNsfw={this.props.enableNsfw} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> ), @@ -359,6 +368,7 @@ export class PostForm extends Component { buttonTitle={None} maxLength={None} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> @@ -411,6 +421,7 @@ export class PostForm extends Component { )} ; admins: Option; allLanguages: Language[]; + siteLanguages: number[]; showCommunity?: boolean; showBody?: boolean; hideImage?: boolean; @@ -176,6 +177,7 @@ export class PostListing extends Component { enableNsfw={this.props.enableNsfw} enableDownvotes={this.props.enableDownvotes} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} /> )} diff --git a/src/shared/components/post/post-listings.tsx b/src/shared/components/post/post-listings.tsx index 39d46a71..e5d3e3bc 100644 --- a/src/shared/components/post/post-listings.tsx +++ b/src/shared/components/post/post-listings.tsx @@ -9,6 +9,7 @@ import { PostListing } from "./post-listing"; interface PostListingsProps { posts: PostView[]; allLanguages: Language[]; + siteLanguages: number[]; showCommunity?: boolean; removeDuplicates?: boolean; enableDownvotes: boolean; @@ -43,6 +44,7 @@ export class PostListings extends Component { enableDownvotes={this.props.enableDownvotes} enableNsfw={this.props.enableNsfw} allLanguages={this.props.allLanguages} + siteLanguages={this.props.siteLanguages} />
diff --git a/src/shared/components/post/post-report.tsx b/src/shared/components/post/post-report.tsx index 1ce33817..7cb9e436 100644 --- a/src/shared/components/post/post-report.tsx +++ b/src/shared/components/post/post-report.tsx @@ -60,6 +60,7 @@ export class PostReport extends Component { enableNsfw={true} viewOnly={true} allLanguages={[]} + siteLanguages={[]} hideImage />
diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 50f0e449..d2d5f843 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -367,12 +367,14 @@ export class Post extends Component { enableDownvotes={enableDownvotes(this.state.siteRes)} enableNsfw={enableNsfw(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} />
), @@ -527,6 +530,9 @@ export class Post extends Component { online={res.online} enableNsfw={enableNsfw(this.state.siteRes)} showIcon + allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} + communityLanguages={None} />
), @@ -611,6 +617,7 @@ export class Post extends Component { admins={Some(this.state.siteRes.admins)} enableDownvotes={enableDownvotes(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} />
), diff --git a/src/shared/components/private_message/private-message-form.tsx b/src/shared/components/private_message/private-message-form.tsx index 6c74e2c8..86b58bea 100644 --- a/src/shared/components/private_message/private-message-form.tsx +++ b/src/shared/components/private_message/private-message-form.tsx @@ -136,6 +136,7 @@ export class PrivateMessageForm extends Component< maxLength={None} onContentChange={this.handleContentChange} allLanguages={[]} + siteLanguages={[]} /> diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 52cd73b7..b9aacf3a 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -595,6 +595,7 @@ export class Search extends Component { enableDownvotes={enableDownvotes(this.state.siteRes)} enableNsfw={enableNsfw(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} viewOnly /> )} @@ -617,6 +618,7 @@ export class Search extends Component { noIndent enableDownvotes={enableDownvotes(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} /> )} {i.type_ == "communities" && ( @@ -656,6 +658,7 @@ export class Search extends Component { maxCommentsShown={None} enableDownvotes={enableDownvotes(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} /> ); } @@ -686,6 +689,7 @@ export class Search extends Component { enableDownvotes={enableDownvotes(this.state.siteRes)} enableNsfw={enableNsfw(this.state.siteRes)} allLanguages={this.state.siteRes.all_languages} + siteLanguages={this.state.siteRes.discussion_languages} viewOnly /> diff --git a/src/shared/utils.ts b/src/shared/utils.ts index d541df06..53098325 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -14,6 +14,7 @@ import { CommunityView, GetSiteMetadata, GetSiteResponse, + Language, LemmyHttp, LemmyWebsocket, ListingType, @@ -1480,13 +1481,16 @@ export function arrayGet(arr: Array, index: number): Result { } export function myFirstDiscussionLanguageId( + allLanguages: Language[], + siteLanguages: number[], myUserInfo = UserService.Instance.myUserInfo ): Option { - return myUserInfo.andThen(mui => - arrayGet(mui.discussion_languages, 0) - .ok() - .map(i => i.id) - ); + return arrayGet( + selectableLanguages(allLanguages, siteLanguages, false, false, myUserInfo), + 0 + ) + .map(l => l.id) + .ok(); } export function canCreateCommunity( @@ -1530,3 +1534,37 @@ export function nsfwCheck( export function getRandomFromList(list: T[]): T { return list[Math.floor(Math.random() * list.length)]; } + +/** + * This shows what language you can select + * + * Use showAll for the site form + * Use showSite for the profile and community forms + * Use false for both those to filter on your profile and site ones + */ +export function selectableLanguages( + allLanguages: Language[], + siteLanguages: number[], + showAll: boolean, + showSite: boolean, + myUserInfo = UserService.Instance.myUserInfo +): Language[] { + let allLangIds = allLanguages.map(l => l.id); + let myLangs = myUserInfo + .map(mui => mui.discussion_languages) + .unwrapOr(allLangIds); + myLangs = myLangs.length == 0 ? allLangIds : myLangs; + let siteLangs = siteLanguages.length == 0 ? allLangIds : siteLanguages; + + if (showAll) { + return allLanguages; + } else { + if (showSite) { + return allLanguages.filter(x => siteLangs.includes(x.id)); + } else { + return allLanguages + .filter(x => siteLangs.includes(x.id)) + .filter(x => myLangs.includes(x.id)); + } + } +} diff --git a/yarn.lock b/yarn.lock index 7fe2cd70..46475861 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2655,7 +2655,7 @@ cssesc@^3.0.0: resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee" integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg== -csstype@^3.1.0: +csstype@^3.1.0, csstype@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.1.tgz#841b532c45c758ee546a11d5bd7b7b473c8c30b9" integrity sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw== @@ -4304,6 +4304,13 @@ inferno-create-element@^8.0.3: dependencies: inferno "8.0.3" +inferno-create-element@^8.0.5: + version "8.0.5" + resolved "https://registry.yarnpkg.com/inferno-create-element/-/inferno-create-element-8.0.5.tgz#e5ee57926d05b8eafd52039163a18253e8d6a812" + integrity sha512-Ad3ptKXyEgvQMwd3YkCd83Arw7MihJtAbfp7Mlu2c2RtJoHY0ZnGs9RWSPKweDFeKjGgYyTlmrGj1hibpooiGA== + dependencies: + inferno "8.0.5" + inferno-helmet@^5.2.1: version "5.2.1" resolved "https://registry.yarnpkg.com/inferno-helmet/-/inferno-helmet-5.2.1.tgz#3717f325760aa14abeae82a78af7213f9055a3dc" @@ -4313,12 +4320,12 @@ inferno-helmet@^5.2.1: inferno-side-effect "^1.1.5" object-assign "^4.1.1" -inferno-hydrate@^8.0.3: - version "8.0.3" - resolved "https://registry.yarnpkg.com/inferno-hydrate/-/inferno-hydrate-8.0.3.tgz#75c3c53300a7b7b550dfa93f363956201d86f71f" - integrity sha512-7q1BDuVIy3XCmyKlAJhe+s1CLJhl3+gfFcBpjCq9iA7J/Z3kwo/6xjwJQbcQHNrCr/XZvTM+2uVwfxiX6wgYCQ== +inferno-hydrate@^8.0.5: + version "8.0.5" + resolved "https://registry.yarnpkg.com/inferno-hydrate/-/inferno-hydrate-8.0.5.tgz#c73adb903122e7030f935b1cf189734583acdce5" + integrity sha512-eLbBjstgPhwDSJ+7hcPXbT2nIZQCfesCR3yAu/7AICkXamn2v0f5Zq/5+UlvyHsiuU9BYSOYh95H8hTwHm5zVw== dependencies: - inferno "8.0.3" + inferno "8.0.5" inferno-i18next-dess@0.0.2: version "0.0.2" @@ -4332,22 +4339,22 @@ inferno-i18next-dess@0.0.2: inferno-shared "^8.0.3" inferno-vnode-flags "^8.0.3" -inferno-router@^8.0.3: - version "8.0.3" - resolved "https://registry.yarnpkg.com/inferno-router/-/inferno-router-8.0.3.tgz#ef08da8b0cb158b8920147b260a4f84c64bc3877" - integrity sha512-bWkrFfIBDued0LfS/x6Bot3+J3VwGImH3ukSdIFe/GLFPBljDbvayc1JotriJtNFKA1E+1T/OZyw1E6UqIcDaA== +inferno-router@^8.0.5: + version "8.0.5" + resolved "https://registry.yarnpkg.com/inferno-router/-/inferno-router-8.0.5.tgz#6cf2d4774f1d858ede65a5f61649796c0866e972" + integrity sha512-c1hmVDNsjtG9v7dmArIsYHqX8vR2Z0sNtq6fsW+DHkz7y6VtjM2Po6MheRHBfIn2RSltiIn7+Vew0rtgfPYd8g== dependencies: history "^5.3.0" hoist-non-inferno-statics "^1.1.3" - inferno "8.0.3" + inferno "8.0.5" path-to-regexp-es6 "1.7.0" -inferno-server@^8.0.3: - version "8.0.3" - resolved "https://registry.yarnpkg.com/inferno-server/-/inferno-server-8.0.3.tgz#4030ac5f20d9ddf191163daa10d3ef4e8b0c4593" - integrity sha512-YG9f9e0KsVGV6qByWCkFoGI80SckqIptHtTHMoVHsAbw3krzX414zxwA5H9OTnkubJJsSHBjVtFxaq6hHT/YcA== +inferno-server@^8.0.5: + version "8.0.5" + resolved "https://registry.yarnpkg.com/inferno-server/-/inferno-server-8.0.5.tgz#e2f659caba0419080e018567744af8d505030095" + integrity sha512-I0suUf8o8ftGH3xSPoBpRrDXMPhrj4UN8o1qDz3WDTYuecTqF7JGtSeu8OP9/kMBlRqTN34Mn+xJV/DGGhnCLQ== dependencies: - inferno "8.0.3" + inferno "8.0.5" inferno-shared@^8.0.3: version "8.0.3" @@ -4368,6 +4375,11 @@ inferno-vnode-flags@8.0.3, inferno-vnode-flags@^8.0.3: resolved "https://registry.yarnpkg.com/inferno-vnode-flags/-/inferno-vnode-flags-8.0.3.tgz#1bd78745033719596211155ae673bd648b266a78" integrity sha512-r+wJZNliJWvtcwBd66L3fMSp+M0rinHLilZeLiAX87+ZVPoXKiTDLVmTRI+1j8dm1XmC3IuAHijVfwELnEmoCQ== +inferno-vnode-flags@8.0.5: + version "8.0.5" + resolved "https://registry.yarnpkg.com/inferno-vnode-flags/-/inferno-vnode-flags-8.0.5.tgz#328767cadcd4270d7e70268e8fec93331dc57e27" + integrity sha512-HF/frYUEV/tcCxM73FXwJYgaxKfHZD1fl1UaEwpoFils52ce/1O02GtbGKyd2ts93hZ592W7yu5jKDTM6k/shA== + inferno@8.0.3, inferno@^8.0.3: version "8.0.3" resolved "https://registry.yarnpkg.com/inferno/-/inferno-8.0.3.tgz#99124f050a9c60995dbdeef8ac258a936df7e62e" @@ -4377,6 +4389,15 @@ inferno@8.0.3, inferno@^8.0.3: inferno-vnode-flags "8.0.3" opencollective-postinstall "^2.0.3" +inferno@8.0.5, inferno@^8.0.5: + version "8.0.5" + resolved "https://registry.yarnpkg.com/inferno/-/inferno-8.0.5.tgz#6c480b92eae6acdf2eba9d4986f98b2b71349977" + integrity sha512-dg+h9wdQOR34lTSh9KLhV+62wdnWXI58e7nam9YxXof45IBzgWsKkVuGL0Rp0DkioPNA47bT3v7MvbsGgL58Tg== + dependencies: + csstype "^3.1.1" + inferno-vnode-flags "8.0.5" + opencollective-postinstall "^2.0.3" + inflight@^1.0.4, inflight@~1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -4909,10 +4930,15 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" -lemmy-js-client@0.17.0-rc.54: - version "0.17.0-rc.54" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.54.tgz#cda3aae8149699f944da354b76710b148cf441dc" - integrity sha512-7EhwjfAoq1jmwj6CAFOBNiNQOMOZk/yAsW4kwVRsNGD3pZexW3NrjEoAQx3kFC7mDEUuVbkkRMkl3ND8vUY+Uw== +lemmy-js-client@0.17.0-rc.57: + version "0.17.0-rc.57" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.57.tgz#f7a243ed53542810e7446b0a28ad162f3e913254" + integrity sha512-7kZHi0B+jiKc50itTwngkS5Vxcuvux3LjgD28IXZ049cWQgZDqer6BCmudcbViP+dAoyWs9Fh2SyWkYFhv7bwQ== + dependencies: + "@sniptt/monads" "^0.5.10" + class-transformer "^0.5.1" + node-fetch "2.6.6" + reflect-metadata "^0.1.13" levn@^0.4.1: version "0.4.1" @@ -5580,6 +5606,13 @@ node-fetch-npm@^2.0.2: json-parse-better-errors "^1.0.0" safe-buffer "^5.1.1" +node-fetch@2.6.6: + version "2.6.6" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89" + integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA== + dependencies: + whatwg-url "^5.0.0" + node-fetch@^2.6.1: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"