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/setup.tsx | |
parent | 05ee5a8b600fdd7a64ad66bb52978befed3a7614 (diff) |
First pass at fixing UI to work with new websocketresponses.
Diffstat (limited to 'ui/src/components/setup.tsx')
-rw-r--r-- | ui/src/components/setup.tsx | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/ui/src/components/setup.tsx b/ui/src/components/setup.tsx index d421e46f..5b081111 100644 --- a/ui/src/components/setup.tsx +++ b/ui/src/components/setup.tsx @@ -3,7 +3,7 @@ import { Subscription } from 'rxjs'; import { retryWhen, delay, take } from 'rxjs/operators'; import { RegisterForm, LoginResponse, UserOperation } from '../interfaces'; import { WebSocketService, UserService } from '../services'; -import { msgOp } from '../utils'; +import { wsJsonToRes } from '../utils'; import { SiteForm } from './site-form'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; @@ -35,14 +35,7 @@ export class Setup extends Component<any, State> { this.state = this.emptyState; 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), @@ -189,20 +182,19 @@ export class Setup extends Component<any, State> { } parseMessage(msg: any) { - let op: UserOperation = msgOp(msg); - if (msg.error) { - alert(i18n.t(msg.error)); + let res = wsJsonToRes(msg); + if (res.error) { + alert(i18n.t(res.error)); this.state.userLoading = false; this.setState(this.state); return; - } else if (op == UserOperation.Register) { + } else if (res.op == UserOperation.Register) { + let data = res.data as LoginResponse; this.state.userLoading = false; this.state.doneRegisteringUser = true; - let res: LoginResponse = msg; - UserService.Instance.login(res); - console.log(res); + UserService.Instance.login(data); this.setState(this.state); - } else if (op == UserOperation.CreateSite) { + } else if (res.op == UserOperation.CreateSite) { this.props.history.push('/'); } } |