summaryrefslogtreecommitdiffstats
path: root/ui/src/components/communities.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-01-23 19:17:42 -0500
committerDessalines <tyhou13@gmx.com>2020-01-23 19:17:42 -0500
commitac1d5f2b86b0816cc9b5794dc6c38a38365ed839 (patch)
treebedaab04ca797113990e5702cad36f5e34e9e6e8 /ui/src/components/communities.tsx
parent39d1fb4450cb418d9c11b31ea99484c2a177fab6 (diff)
parentb45c83682c187737b092080e83ba741c39cfa695 (diff)
Done merging http-api and private_message
Diffstat (limited to 'ui/src/components/communities.tsx')
-rw-r--r--ui/src/components/communities.tsx25
1 files changed, 13 insertions, 12 deletions
diff --git a/ui/src/components/communities.tsx b/ui/src/components/communities.tsx
index 129051fb..867cfd81 100644
--- a/ui/src/components/communities.tsx
+++ b/ui/src/components/communities.tsx
@@ -10,9 +10,10 @@ import {
FollowCommunityForm,
ListCommunitiesForm,
SortType,
+ WebSocketJsonResponse,
} from '../interfaces';
import { WebSocketService } from '../services';
-import { msgOp, toast } from '../utils';
+import { wsJsonToRes, toast } from '../utils';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
@@ -231,15 +232,15 @@ export class Communities extends Component<any, CommunitiesState> {
WebSocketService.Instance.listCommunities(listCommunitiesForm);
}
- parseMessage(msg: any) {
+ parseMessage(msg: WebSocketJsonResponse) {
console.log(msg);
- let op: UserOperation = msgOp(msg);
- if (msg.error) {
+ let res = wsJsonToRes(msg);
+ if (res.error) {
toast(i18n.t(msg.error), 'danger');
return;
- } else if (op == UserOperation.ListCommunities) {
- let res: ListCommunitiesResponse = msg;
- this.state.communities = res.communities;
+ } else if (res.op == UserOperation.ListCommunities) {
+ let data = res.data as ListCommunitiesResponse;
+ this.state.communities = data.communities;
this.state.communities.sort(
(a, b) => b.number_of_subscribers - a.number_of_subscribers
);
@@ -248,11 +249,11 @@ export class Communities extends Component<any, CommunitiesState> {
this.setState(this.state);
let table = document.querySelector('#community_table');
Sortable.initTable(table);
- } else if (op == UserOperation.FollowCommunity) {
- let res: CommunityResponse = msg;
- let found = this.state.communities.find(c => c.id == res.community.id);
- found.subscribed = res.community.subscribed;
- found.number_of_subscribers = res.community.number_of_subscribers;
+ } 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;
this.setState(this.state);
}
}