]> Untitled Git - lemmy-ui.git/commitdiff
Fixing an issue with federated search names
authorDessalines <tyhou13@gmx.com>
Mon, 26 Apr 2021 20:06:16 +0000 (16:06 -0400)
committerDessalines <tyhou13@gmx.com>
Mon, 26 Apr 2021 20:06:16 +0000 (16:06 -0400)
src/shared/components/post-form.tsx
src/shared/components/search.tsx
src/shared/utils.ts

index 81e8f4685445d4263a08cc8513703c4cc1af8a9b..b267b4508f682807af389094fc804b38885ee100 100644 (file)
@@ -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<PostFormProps, PostFormState> {
                   <option>{i18n.t("select_a_community")}</option>
                   {this.props.communities.map(cv => (
                     <option value={cv.community.id}>
-                      {cv.community.local
-                        ? cv.community.name
-                        : `${hostname(cv.community.actor_id)}/${
-                            cv.community.name
-                          }`}
+                      {communitySelectName(cv)}
                     </option>
                   ))}
                 </select>
index 9f0c04ee8ef2f0dbd1c25579edbc41a7d584183b..72bdfcc80428073a35e4958eb1888cf034a4da1b 100644 (file)
@@ -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<any, SearchState> {
           >
             <option value="0">{i18n.t("all")}</option>
             {this.state.communities.map(cv => (
-              <option value={cv.community.id}>
-                {cv.community.local
-                  ? cv.community.name
-                  : `${hostname(cv.community.actor_id)}/${cv.community.name}`}
-              </option>
+              <option value={cv.community.id}>{communitySelectName(cv)}</option>
             ))}
           </select>
         </div>
@@ -597,11 +594,7 @@ export class Search extends Component<any, SearchState> {
             <option value="0">{i18n.t("all")}</option>
             {this.state.creator && (
               <option value={this.state.creator.person.id}>
-                {this.state.creator.person.local
-                  ? this.state.creator.person.name
-                  : `${hostname(this.state.creator.person.actor_id)}/${
-                      this.state.creator.person.name
-                    }`}
+                {personSelectName(this.state.creator)}
               </option>
             )}
           </select>
index 4901c964d844c111abd3a14def0bcff6012182de..c75ac4f37267dfa5f77cf8ad9bc6f9540ba20875 100644 (file)
@@ -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}`;
+}