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