Skip to content

Commit

Permalink
Fixing communityToChoice. Fixes #2231 . Fixes #2232 . (#2271)
Browse files Browse the repository at this point in the history
* Fixing communityToChoice. Fixes #2231 . Fixes #2232 .

* Fixing map.

---------

Co-authored-by: SleeplessOne1917 <insomnia_void@protonmail.com>
  • Loading branch information
dessalines and SleeplessOne1917 authored Dec 6, 2023
1 parent 8a722c9 commit 39f86d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
19 changes: 10 additions & 9 deletions src/shared/components/post/create-post.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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,
});
}
Expand Down
18 changes: 4 additions & 14 deletions src/shared/components/post/post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,16 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
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) ?? [],
};
}

Expand Down

0 comments on commit 39f86d4

Please sign in to comment.