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,
};
}
{this.communityInfo(res)}
<div className="d-block d-md-none">
<button
- className="btn btn-secondary d-inline-block mb-2 mr-3"
+ className="btn btn-secondary d-inline-block mb-2 me-3"
onClick={linkEvent(this, this.handleShowSidebarMobile)}
>
{i18n.t("sidebar")}{" "}
}
render() {
- return <div className="container-lg">{this.renderCommunity()}</div>;
+ return (
+ <div className="community container-lg">{this.renderCommunity()}</div>
+ );
}
sidebar(res: GetCommunityResponse) {
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}
return (
<div className="mb-3">
- <span className="mr-3">
+ <span className="me-3">
<DataTypeSelect
type_={dataType}
onChange={this.handleDataTypeChange}
/>
</span>
- <span className="mr-2">
+ <span className="me-2">
<SortSelect sort={sort} onChange={this.handleSortChange} />
</span>
{communityRss && (
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;
+ }
+ });
}
}