import { CommunityLink } from "./community-link";
type CommunityData = RouteDataResponse<{
- communityResponse: GetCommunityResponse;
- postsResponse?: GetPostsResponse;
- commentsResponse?: GetCommentsResponse;
+ communityRes: GetCommunityResponse;
+ postsRes: GetPostsResponse;
+ commentsRes: GetCommentsResponse;
}>;
interface State {
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
- const {
- communityResponse: communityRes,
- commentsResponse: commentsRes,
- postsResponse: postsRes,
- } = this.isoData.routeData;
+ const { communityRes, commentsRes, postsRes } = this.isoData.routeData;
this.state = {
...this.state,
isIsomorphic: true,
+ commentsRes,
+ communityRes,
+ postsRes,
};
-
- if (communityRes.state === "success") {
- this.state = {
- ...this.state,
- communityRes,
- };
- }
-
- if (postsRes?.state === "success") {
- this.state = {
- ...this.state,
- postsRes,
- };
- }
-
- if (commentsRes?.state === "success") {
- this.state = {
- ...this.state,
- commentsRes,
- };
- }
}
}
const page = getPageFromString(urlPage);
- let postsResponse: RequestState<GetPostsResponse> | undefined = undefined;
- let commentsResponse: RequestState<GetCommentsResponse> | undefined =
- undefined;
+ let postsResponse: RequestState<GetPostsResponse> = { state: "empty" };
+ let commentsResponse: RequestState<GetCommentsResponse> = {
+ state: "empty",
+ };
if (dataType === DataType.Post) {
const getPostsForm: GetPosts = {
}
return {
- communityResponse: await client.getCommunity(communityForm),
- commentsResponse,
- postsResponse,
+ communityRes: await client.getCommunity(communityForm),
+ commentsRes: commentsResponse,
+ postsRes: postsResponse,
};
}
community_view={res.community_view}
moderators={res.moderators}
admins={site_res.admins}
- online={res.online}
enableNsfw={enableNsfw(site_res)}
editable
allLanguages={site_res.all_languages}
const blockCommunityRes = await HttpService.client.blockCommunity(form);
if (blockCommunityRes.state == "success") {
updateCommunityBlock(blockCommunityRes.data);
+ this.setState(s => {
+ if (s.communityRes.state == "success") {
+ s.communityRes.data.community_view.blocked =
+ blockCommunityRes.data.blocked;
+ }
+ });
}
}