import {
Choice,
QueryParams,
+ WithPromiseKeys,
enableDownvotes,
enableNsfw,
getIdFromString,
communityId?: number;
}
+interface CreatePostData {
+ communityResponse?: GetCommunityResponse;
+}
+
function getCreatePostQueryParams() {
return getQueryParams<CreatePostProps>({
communityId: getIdFromString,
RouteComponentProps<Record<string, never>>,
CreatePostState
> {
- private isoData = setIsoData(this.context);
+ private isoData = setIsoData<CreatePostData>(this.context);
private subscription?: Subscription;
state: CreatePostState = {
siteRes: this.isoData.site_res,
// Only fetch the data if coming from another route
if (this.isoData.path === this.context.router.route.match.url) {
- const communityRes = this.isoData.routeData[0] as
- | GetCommunityResponse
- | undefined;
+ const { communityResponse } = this.isoData.routeData;
- if (communityRes) {
+ if (communityResponse) {
const communityChoice: Choice = {
- label: communityRes.community_view.community.name,
- value: communityRes.community_view.community.id.toString(),
+ label: communityResponse.community_view.community.name,
+ value: communityResponse.community_view.community.id.toString(),
};
this.state = {
client,
query: { communityId },
auth,
- }: InitialFetchRequest<QueryParams<CreatePostProps>>): Promise<any>[] {
- const promises: Promise<any>[] = [];
+ }: InitialFetchRequest<
+ QueryParams<CreatePostProps>
+ >): WithPromiseKeys<CreatePostData> {
+ const data: WithPromiseKeys<CreatePostData> = {};
if (communityId) {
const form: GetCommunity = {
id: getIdFromString(communityId),
};
- promises.push(client.getCommunity(form));
- } else {
- promises.push(Promise.resolve());
+ data.communityResponse = client.getCommunity(form);
}
- return promises;
+ return data;
}
parseMessage(msg: any) {