mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 20:31:13 +00:00
* Fixing communityToChoice. Fixes #2231 . Fixes #2232 . * Fixing map. --------- Co-authored-by: SleeplessOne1917 <insomnia_void@protonmail.com>
This commit is contained in:
parent
8a722c939c
commit
39f86d421e
2 changed files with 14 additions and 23 deletions
|
@ -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 { getIdFromString, getQueryParams } from "@utils/helpers";
|
||||||
import type { QueryParams } from "@utils/types";
|
import type { QueryParams } from "@utils/types";
|
||||||
import { Choice, RouteDataResponse } from "@utils/types";
|
import { Choice, RouteDataResponse } from "@utils/types";
|
||||||
|
@ -85,10 +90,9 @@ export class CreatePost extends Component<
|
||||||
};
|
};
|
||||||
|
|
||||||
if (communityRes?.state === "success") {
|
if (communityRes?.state === "success") {
|
||||||
const communityChoice: Choice = {
|
const communityChoice = communityToChoice(
|
||||||
label: communityRes.data.community_view.community.title,
|
communityRes.data.community_view,
|
||||||
value: communityRes.data.community_view.community.id.toString(),
|
);
|
||||||
};
|
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
...this.state,
|
...this.state,
|
||||||
|
@ -107,10 +111,7 @@ export class CreatePost extends Component<
|
||||||
});
|
});
|
||||||
if (res.state === "success") {
|
if (res.state === "success") {
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedCommunityChoice: {
|
selectedCommunityChoice: communityToChoice(res.data.community_view),
|
||||||
label: res.data.community_view.community.title,
|
|
||||||
value: res.data.community_view.community.id.toString(),
|
|
||||||
},
|
|
||||||
loading: false,
|
loading: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,26 +263,16 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
community_id: getIdFromString(selectedCommunityChoice.value),
|
community_id: getIdFromString(selectedCommunityChoice.value),
|
||||||
},
|
},
|
||||||
communitySearchOptions: [selectedCommunityChoice].concat(
|
communitySearchOptions: [selectedCommunityChoice].concat(
|
||||||
(
|
(this.props.initialCommunities?.map(communityToChoice) ?? []).filter(
|
||||||
this.props.initialCommunities?.map(
|
option => option.value !== selectedCommunityChoice.value,
|
||||||
({ community: { id, title } }) => ({
|
),
|
||||||
label: title,
|
|
||||||
value: id.toString(),
|
|
||||||
}),
|
|
||||||
) ?? []
|
|
||||||
).filter(option => option.value !== selectedCommunityChoice.value),
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.state = {
|
this.state = {
|
||||||
...this.state,
|
...this.state,
|
||||||
communitySearchOptions:
|
communitySearchOptions:
|
||||||
this.props.initialCommunities?.map(
|
this.props.initialCommunities?.map(communityToChoice) ?? [],
|
||||||
({ community: { id, title } }) => ({
|
|
||||||
label: title,
|
|
||||||
value: id.toString(),
|
|
||||||
}),
|
|
||||||
) ?? [],
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue