Fix bug from last commit

This commit is contained in:
SleeplessOne1917 2023-06-10 10:08:02 -04:00
parent 46f2dd7457
commit 0c23f0564b

View file

@ -56,7 +56,7 @@ interface PostFormProps {
enableDownvotes?: boolean;
selectedCommunityChoice?: Choice;
onSelectCommunity?: (choice: Choice) => void;
initialCommunities: CommunityView[];
initialCommunities?: CommunityView[];
}
interface PostFormState {
@ -124,24 +124,25 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
},
communitySearchOptions: [selectedCommunityChoice]
.concat(
this.props.initialCommunities.map(
this.props.initialCommunities?.map(
({ community: { id, title } }) => ({
label: title,
value: id.toString(),
})
)
) ?? []
)
.filter(option => option.value !== selectedCommunityChoice.value),
};
} else {
this.state = {
...this.state,
communitySearchOptions: this.props.initialCommunities.map(
({ community: { id, title } }) => ({
label: title,
value: id.toString(),
})
),
communitySearchOptions:
this.props.initialCommunities?.map(
({ community: { id, title } }) => ({
label: title,
value: id.toString(),
})
) ?? [],
};
}