diff options
author | Dessalines <tyhou13@gmx.com> | 2020-01-18 23:54:10 -0500 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-01-18 23:54:10 -0500 |
commit | a044718066623f19d51196d444bd199c1231cebe (patch) | |
tree | cbffb18d826df1330ce2b7f1a814205ba45148d1 /ui/src/components/community-form.tsx | |
parent | 05ee5a8b600fdd7a64ad66bb52978befed3a7614 (diff) |
First pass at fixing UI to work with new websocketresponses.
Diffstat (limited to 'ui/src/components/community-form.tsx')
-rw-r--r-- | ui/src/components/community-form.tsx | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index 2085da28..93f4d649 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -10,8 +10,8 @@ import { GetSiteResponse, } from '../interfaces'; import { WebSocketService } from '../services'; -import { msgOp, capitalizeFirstLetter } from '../utils'; -import * as autosize from 'autosize'; +import { wsJsonToRes, capitalizeFirstLetter } from '../utils'; +import autosize from 'autosize'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; @@ -67,14 +67,7 @@ export class CommunityForm extends Component< } this.subscription = WebSocketService.Instance.subject - .pipe( - retryWhen(errors => - errors.pipe( - delay(3000), - take(10) - ) - ) - ) + .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) .subscribe( msg => this.parseMessage(msg), err => console.error(err), @@ -247,33 +240,33 @@ export class CommunityForm extends Component< } parseMessage(msg: any) { - let op: UserOperation = msgOp(msg); + let res = wsJsonToRes(msg); console.log(msg); - if (msg.error) { - alert(i18n.t(msg.error)); + if (res.error) { + alert(i18n.t(res.error)); 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); } } |