-
+
|
- {community.category_name} |
-
- {community.number_of_subscribers}
+ | {cv.category.name} |
+ {cv.counts.subscribers} |
+
+ {cv.counts.posts}
|
- {community.number_of_posts}
- |
-
- {community.number_of_comments}
+ {cv.counts.comments}
|
- {community.subscribed ? (
+ {cv.subscribed ? (
@@ -154,7 +151,7 @@ export class Communities extends Component {
@@ -212,64 +209,68 @@ export class Communities extends Component {
}
handleUnsubscribe(communityId: number) {
- let form: FollowCommunityForm = {
+ let form: FollowCommunity = {
community_id: communityId,
follow: false,
+ auth: UserService.Instance.authField(),
};
- WebSocketService.Instance.followCommunity(form);
+ WebSocketService.Instance.client.followCommunity(form);
}
handleSubscribe(communityId: number) {
- let form: FollowCommunityForm = {
+ let form: FollowCommunity = {
community_id: communityId,
follow: true,
+ auth: UserService.Instance.authField(),
};
- WebSocketService.Instance.followCommunity(form);
+ WebSocketService.Instance.client.followCommunity(form);
}
refetch() {
- let listCommunitiesForm: ListCommunitiesForm = {
+ let listCommunitiesForm: ListCommunities = {
sort: SortType.TopAll,
limit: communityLimit,
page: this.state.page,
+ auth: UserService.Instance.authField(false),
};
- WebSocketService.Instance.listCommunities(listCommunitiesForm);
+ WebSocketService.Instance.client.listCommunities(listCommunitiesForm);
}
static fetchInitialData(req: InitialFetchRequest): Promise[] {
let pathSplit = req.path.split('/');
let page = pathSplit[3] ? Number(pathSplit[3]) : 1;
- let listCommunitiesForm: ListCommunitiesForm = {
+ let listCommunitiesForm: ListCommunities = {
sort: SortType.TopAll,
limit: communityLimit,
page,
+ auth: req.auth,
};
- setAuth(listCommunitiesForm, req.auth);
return [req.client.listCommunities(listCommunitiesForm)];
}
- parseMessage(msg: WebSocketJsonResponse) {
- console.log(msg);
- let res = wsJsonToRes(msg);
+ parseMessage(msg: any) {
+ let op = wsUserOp(msg);
if (msg.error) {
toast(i18n.t(msg.error), 'danger');
return;
- } else if (res.op == UserOperation.ListCommunities) {
- let data = res.data as ListCommunitiesResponse;
+ } else if (op == UserOperation.ListCommunities) {
+ let data = wsJsonToRes(msg).data;
this.state.communities = data.communities;
this.state.communities.sort(
- (a, b) => b.number_of_subscribers - a.number_of_subscribers
+ (a, b) => b.counts.subscribers - a.counts.subscribers
);
this.state.loading = false;
window.scrollTo(0, 0);
this.setState(this.state);
- } else if (res.op == UserOperation.FollowCommunity) {
- let data = res.data as CommunityResponse;
- let found = this.state.communities.find(c => c.id == data.community.id);
- found.subscribed = data.community.subscribed;
- found.number_of_subscribers = data.community.number_of_subscribers;
+ } else if (op == UserOperation.FollowCommunity) {
+ let data = wsJsonToRes(msg).data;
+ let found = this.state.communities.find(
+ c => c.community.id == data.community_view.community.id
+ );
+ found.subscribed = data.community_view.subscribed;
+ found.counts.subscribers = data.community_view.counts.subscribers;
this.setState(this.state);
}
}
diff --git a/src/shared/components/community-form.tsx b/src/shared/components/community-form.tsx
index de7b6b2d..4a3dad4b 100644
--- a/src/shared/components/community-form.tsx
+++ b/src/shared/components/community-form.tsx
@@ -2,20 +2,21 @@ import { Component, linkEvent } from 'inferno';
import { Prompt } from 'inferno-router';
import { Subscription } from 'rxjs';
import {
- CommunityForm as CommunityFormI,
+ EditCommunity,
+ CreateCommunity,
UserOperation,
Category,
CommunityResponse,
- WebSocketJsonResponse,
- Community,
+ CommunityView,
} from 'lemmy-js-client';
-import { WebSocketService } from '../services';
+import { UserService, WebSocketService } from '../services';
import {
wsJsonToRes,
capitalizeFirstLetter,
toast,
randomStr,
wsSubscribe,
+ wsUserOp,
} from '../utils';
import { i18n } from '../i18next';
@@ -23,16 +24,16 @@ import { MarkdownTextArea } from './markdown-textarea';
import { ImageUploadForm } from './image-upload-form';
interface CommunityFormProps {
- community?: Community; // If a community is given, that means this is an edit
+ community_view?: CommunityView; // If a community is given, that means this is an edit
categories: Category[];
onCancel?(): any;
- onCreate?(community: Community): any;
- onEdit?(community: Community): any;
+ onCreate?(community: CommunityView): any;
+ onEdit?(community: CommunityView): any;
enableNsfw: boolean;
}
interface CommunityFormState {
- communityForm: CommunityFormI;
+ communityForm: CreateCommunity;
loading: boolean;
}
@@ -51,6 +52,7 @@ export class CommunityForm extends Component<
nsfw: false,
icon: null,
banner: null,
+ auth: UserService.Instance.authField(),
},
loading: false,
};
@@ -70,17 +72,17 @@ export class CommunityForm extends Component<
this.handleBannerUpload = this.handleBannerUpload.bind(this);
this.handleBannerRemove = this.handleBannerRemove.bind(this);
- if (this.props.community) {
+ let cv = this.props.community_view;
+ if (cv) {
this.state.communityForm = {
- name: this.props.community.name,
- title: this.props.community.title,
- category_id: this.props.community.category_id,
- description: this.props.community.description,
- edit_id: this.props.community.id,
- nsfw: this.props.community.nsfw,
- icon: this.props.community.icon,
- banner: this.props.community.banner,
- auth: null,
+ name: cv.community.name,
+ title: cv.community.title,
+ category_id: cv.category.id,
+ description: cv.community.description,
+ nsfw: cv.community.nsfw,
+ icon: cv.community.icon,
+ banner: cv.community.banner,
+ auth: UserService.Instance.authField(),
};
}
@@ -88,6 +90,7 @@ export class CommunityForm extends Component<
this.subscription = wsSubscribe(this.parseMessage);
}
+ // TODO this should be checked out
componentDidUpdate() {
if (
!this.state.loading &&
@@ -119,7 +122,7 @@ export class CommunityForm extends Component<
message={i18n.t('block_leaving')}
/>
|