summaryrefslogtreecommitdiffstats
path: root/ui/src/components/community-form.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/community-form.tsx
parent39d1fb4450cb418d9c11b31ea99484c2a177fab6 (diff)
parentb45c83682c187737b092080e83ba741c39cfa695 (diff)
Done merging http-api and private_message
Diffstat (limited to 'ui/src/components/community-form.tsx')
-rw-r--r--ui/src/components/community-form.tsx37
1 files changed, 19 insertions, 18 deletions
diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx
index ec58b010..4dc7bfcb 100644
--- a/ui/src/components/community-form.tsx
+++ b/ui/src/components/community-form.tsx
@@ -8,9 +8,10 @@ import {
ListCategoriesResponse,
CommunityResponse,
GetSiteResponse,
+ WebSocketJsonResponse,
} from '../interfaces';
import { WebSocketService } from '../services';
-import { msgOp, capitalizeFirstLetter, toast } from '../utils';
+import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils';
import autosize from 'autosize';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
@@ -239,34 +240,34 @@ export class CommunityForm extends Component<
i.props.onCancel();
}
- parseMessage(msg: any) {
- let op: UserOperation = msgOp(msg);
+ parseMessage(msg: WebSocketJsonResponse) {
+ let res = wsJsonToRes(msg);
console.log(msg);
- if (msg.error) {
+ if (res.error) {
toast(i18n.t(msg.error), 'danger');
this.state.loading = false;
this.setState(this.state);
return;
- } else if (op == UserOperation.ListCategories) {
- let res: ListCategoriesResponse = msg;
- this.state.categories = res.categories;
+ } else if (res.op == UserOperation.ListCategories) {
+ let data = res.data as ListCategoriesResponse;
+ this.state.categories = data.categories;
if (!this.props.community) {
- this.state.communityForm.category_id = res.categories[0].id;
+ this.state.communityForm.category_id = data.categories[0].id;
}
this.setState(this.state);
- } else if (op == UserOperation.CreateCommunity) {
- let res: CommunityResponse = msg;
+ } else if (res.op == UserOperation.CreateCommunity) {
+ let data = res.data as CommunityResponse;
this.state.loading = false;
- this.props.onCreate(res.community);
+ this.props.onCreate(data.community);
}
- // TODO is ths necessary
- else if (op == UserOperation.EditCommunity) {
- let res: CommunityResponse = msg;
+ // TODO is this necessary
+ else if (res.op == UserOperation.EditCommunity) {
+ let data = res.data as CommunityResponse;
this.state.loading = false;
- this.props.onEdit(res.community);
- } else if (op == UserOperation.GetSite) {
- let res: GetSiteResponse = msg;
- this.state.enable_nsfw = res.site.enable_nsfw;
+ this.props.onEdit(data.community);
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ this.state.enable_nsfw = data.site.enable_nsfw;
this.setState(this.state);
}
}