From 15305f4b2993ad38351b729eec609d88ff422ee5 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 26 Apr 2021 16:06:16 -0400 Subject: [PATCH] Fixing an issue with federated search names --- src/shared/components/post-form.tsx | 8 ++------ src/shared/components/search.tsx | 15 ++++----------- src/shared/utils.ts | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 19 deletions(-) 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}`; +} -- 2.44.1