From a044718066623f19d51196d444bd199c1231cebe Mon Sep 17 00:00:00 2001
From: Dessalines <tyhou13@gmx.com>
Date: Sat, 18 Jan 2020 23:54:10 -0500
Subject: First pass at fixing UI to work with new websocketresponses.

---
 ui/src/components/setup.tsx | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

(limited to 'ui/src/components/setup.tsx')

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('/');
     }
   }
-- 
cgit v1.2.3


From dcd60228ed753a146bcb56bb5bf51166835acfb7 Mon Sep 17 00:00:00 2001
From: Dessalines <tyhou13@gmx.com>
Date: Sun, 19 Jan 2020 00:38:45 -0500
Subject: Strongly typing WebsocketJsonResponse. Forgot comment-form.tsx

---
 ui/src/components/setup.tsx | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'ui/src/components/setup.tsx')

diff --git a/ui/src/components/setup.tsx b/ui/src/components/setup.tsx
index 5b081111..c4c9dc63 100644
--- a/ui/src/components/setup.tsx
+++ b/ui/src/components/setup.tsx
@@ -1,7 +1,12 @@
 import { Component, linkEvent } from 'inferno';
 import { Subscription } from 'rxjs';
 import { retryWhen, delay, take } from 'rxjs/operators';
-import { RegisterForm, LoginResponse, UserOperation } from '../interfaces';
+import {
+  RegisterForm,
+  LoginResponse,
+  UserOperation,
+  WebSocketJsonResponse,
+} from '../interfaces';
 import { WebSocketService, UserService } from '../services';
 import { wsJsonToRes } from '../utils';
 import { SiteForm } from './site-form';
@@ -181,7 +186,7 @@ export class Setup extends Component<any, State> {
     i.setState(i.state);
   }
 
-  parseMessage(msg: any) {
+  parseMessage(msg: WebSocketJsonResponse) {
     let res = wsJsonToRes(msg);
     if (res.error) {
       alert(i18n.t(res.error));
-- 
cgit v1.2.3

