diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index d1b8ee09..e9fcb61e 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -1,4 +1,9 @@ -import { enableDownvotes, enableNsfw, setIsoData } from "@utils/app"; +import { + communityToChoice, + enableDownvotes, + enableNsfw, + setIsoData, +} from "@utils/app"; import { getIdFromString, getQueryParams } from "@utils/helpers"; import type { QueryParams } from "@utils/types"; import { Choice, RouteDataResponse } from "@utils/types"; @@ -85,10 +90,9 @@ export class CreatePost extends Component< }; if (communityRes?.state === "success") { - const communityChoice: Choice = { - label: communityRes.data.community_view.community.title, - value: communityRes.data.community_view.community.id.toString(), - }; + const communityChoice = communityToChoice( + communityRes.data.community_view, + ); this.state = { ...this.state, @@ -107,10 +111,7 @@ export class CreatePost extends Component< }); if (res.state === "success") { this.setState({ - selectedCommunityChoice: { - label: res.data.community_view.community.title, - value: res.data.community_view.community.id.toString(), - }, + selectedCommunityChoice: communityToChoice(res.data.community_view), loading: false, }); } diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 2733ff79..9c9c8d28 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -263,26 +263,16 @@ export class PostForm extends Component { community_id: getIdFromString(selectedCommunityChoice.value), }, communitySearchOptions: [selectedCommunityChoice].concat( - ( - this.props.initialCommunities?.map( - ({ community: { id, title } }) => ({ - label: title, - value: id.toString(), - }), - ) ?? [] - ).filter(option => option.value !== selectedCommunityChoice.value), + (this.props.initialCommunities?.map(communityToChoice) ?? []).filter( + option => option.value !== selectedCommunityChoice.value, + ), ), }; } else { this.state = { ...this.state, communitySearchOptions: - this.props.initialCommunities?.map( - ({ community: { id, title } }) => ({ - label: title, - value: id.toString(), - }), - ) ?? [], + this.props.initialCommunities?.map(communityToChoice) ?? [], }; }