Fixing an issue with federated search names

This commit is contained in:
Dessalines 2021-04-26 16:06:16 -04:00
parent a136d064ae
commit 15305f4b29
3 changed files with 20 additions and 19 deletions

View file

@ -29,7 +29,6 @@ import {
isImage, isImage,
toast, toast,
setupTippy, setupTippy,
hostname,
pictrsDeleteToast, pictrsDeleteToast,
validTitle, validTitle,
wsSubscribe, wsSubscribe,
@ -40,6 +39,7 @@ import {
communityToChoice, communityToChoice,
fetchCommunities, fetchCommunities,
choicesConfig, choicesConfig,
communitySelectName,
} from "../utils"; } from "../utils";
import autosize from "autosize"; import autosize from "autosize";
@ -302,11 +302,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
<option>{i18n.t("select_a_community")}</option> <option>{i18n.t("select_a_community")}</option>
{this.props.communities.map(cv => ( {this.props.communities.map(cv => (
<option value={cv.community.id}> <option value={cv.community.id}>
{cv.community.local {communitySelectName(cv)}
? cv.community.name
: `${hostname(cv.community.actor_id)}/${
cv.community.name
}`}
</option> </option>
))} ))}
</select> </select>

View file

@ -44,10 +44,11 @@ import {
debounce, debounce,
fetchCommunities, fetchCommunities,
communityToChoice, communityToChoice,
hostname,
fetchUsers, fetchUsers,
personToChoice, personToChoice,
capitalizeFirstLetter, capitalizeFirstLetter,
communitySelectName,
personSelectName,
} from "../utils"; } from "../utils";
import { PostListing } from "./post-listing"; import { PostListing } from "./post-listing";
import { HtmlTags } from "./html-tags"; import { HtmlTags } from "./html-tags";
@ -570,11 +571,7 @@ export class Search extends Component<any, SearchState> {
> >
<option value="0">{i18n.t("all")}</option> <option value="0">{i18n.t("all")}</option>
{this.state.communities.map(cv => ( {this.state.communities.map(cv => (
<option value={cv.community.id}> <option value={cv.community.id}>{communitySelectName(cv)}</option>
{cv.community.local
? cv.community.name
: `${hostname(cv.community.actor_id)}/${cv.community.name}`}
</option>
))} ))}
</select> </select>
</div> </div>
@ -597,11 +594,7 @@ export class Search extends Component<any, SearchState> {
<option value="0">{i18n.t("all")}</option> <option value="0">{i18n.t("all")}</option>
{this.state.creator && ( {this.state.creator && (
<option value={this.state.creator.person.id}> <option value={this.state.creator.person.id}>
{this.state.creator.person.local {personSelectName(this.state.creator)}
? this.state.creator.person.name
: `${hostname(this.state.creator.person.actor_id)}/${
this.state.creator.person.name
}`}
</option> </option>
)} )}
</select> </select>

View file

@ -1243,7 +1243,7 @@ interface ChoicesValue {
export function communityToChoice(cv: CommunityView): ChoicesValue { export function communityToChoice(cv: CommunityView): ChoicesValue {
let choice: ChoicesValue = { let choice: ChoicesValue = {
value: cv.community.id.toString(), value: cv.community.id.toString(),
label: cv.community.name, label: communitySelectName(cv),
}; };
return choice; return choice;
} }
@ -1251,7 +1251,7 @@ export function communityToChoice(cv: CommunityView): ChoicesValue {
export function personToChoice(pvs: PersonViewSafe): ChoicesValue { export function personToChoice(pvs: PersonViewSafe): ChoicesValue {
let choice: ChoicesValue = { let choice: ChoicesValue = {
value: pvs.person.id.toString(), value: pvs.person.id.toString(),
label: pvs.person.name, label: personSelectName(pvs),
}; };
return choice; return choice;
} }
@ -1316,3 +1316,15 @@ export const choicesConfig = {
noChoices: "has-no-choices", 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}`;
}