From: Dessalines Date: Mon, 26 Apr 2021 20:06:16 +0000 (-0400) Subject: Fixing an issue with federated search names X-Git-Url: http://these/git/%22https:/join-lemmy.org/%7B%60%24%7BarchiveTodayUrl%7D/%7BallRss%7D?a=commitdiff_plain;h=15305f4b2993ad38351b729eec609d88ff422ee5;p=lemmy-ui.git Fixing an issue with federated search names --- diff --git a/src/shared/components/post-form.tsx b/src/shared/components/post-form.tsx index 81e8f46..b267b45 100644 --- a/src/shared/components/post-form.tsx +++ b/src/shared/components/post-form.tsx @@ -29,7 +29,6 @@ import { isImage, toast, setupTippy, - hostname, pictrsDeleteToast, validTitle, wsSubscribe, @@ -40,6 +39,7 @@ import { communityToChoice, fetchCommunities, choicesConfig, + communitySelectName, } from "../utils"; import autosize from "autosize"; @@ -302,11 +302,7 @@ export class PostForm extends Component { {this.props.communities.map(cv => ( ))} diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 9f0c04e..72bdfcc 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -44,10 +44,11 @@ import { debounce, fetchCommunities, communityToChoice, - hostname, fetchUsers, personToChoice, capitalizeFirstLetter, + communitySelectName, + personSelectName, } from "../utils"; import { PostListing } from "./post-listing"; import { HtmlTags } from "./html-tags"; @@ -570,11 +571,7 @@ export class Search extends Component { > {this.state.communities.map(cv => ( - + ))} @@ -597,11 +594,7 @@ export class Search extends Component { {this.state.creator && ( )} diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 4901c96..c75ac4f 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -1243,7 +1243,7 @@ interface ChoicesValue { export function communityToChoice(cv: CommunityView): ChoicesValue { let choice: ChoicesValue = { value: cv.community.id.toString(), - label: cv.community.name, + label: communitySelectName(cv), }; return choice; } @@ -1251,7 +1251,7 @@ export function communityToChoice(cv: CommunityView): ChoicesValue { export function personToChoice(pvs: PersonViewSafe): ChoicesValue { let choice: ChoicesValue = { value: pvs.person.id.toString(), - label: pvs.person.name, + label: personSelectName(pvs), }; return choice; } @@ -1316,3 +1316,15 @@ export const choicesConfig = { noChoices: "has-no-choices", }, }; + +export function communitySelectName(cv: CommunityView): string { + return cv.community.local + ? cv.community.name + : `${hostname(cv.community.actor_id)}/${cv.community.name}`; +} + +export function personSelectName(pvs: PersonViewSafe): string { + return pvs.person.local + ? pvs.person.name + : `${hostname(pvs.person.actor_id)}/${pvs.person.name}`; +}