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/navbar.tsx | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

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

diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx
index 9fa1e3dc..50bf19c7 100644
--- a/ui/src/components/navbar.tsx
+++ b/ui/src/components/navbar.tsx
@@ -14,7 +14,7 @@ import {
   Comment,
 } from '../interfaces';
 import {
-  msgOp,
+  wsJsonToRes,
   pictshareAvatarThumbnail,
   showAvatars,
   fetchLimit,
@@ -182,16 +182,16 @@ export class Navbar extends Component<any, NavbarState> {
   }
 
   parseMessage(msg: any) {
-    let op: UserOperation = msgOp(msg);
-    if (msg.error) {
-      if (msg.error == 'not_logged_in') {
+    let res = wsJsonToRes(msg);
+    if (res.error) {
+      if (res.error == 'not_logged_in') {
         UserService.Instance.logout();
         location.reload();
       }
       return;
-    } else if (op == UserOperation.GetReplies) {
-      let res: GetRepliesResponse = msg;
-      let unreadReplies = res.replies.filter(r => !r.read);
+    } else if (res.op == UserOperation.GetReplies) {
+      let data = res.data as GetRepliesResponse;
+      let unreadReplies = data.replies.filter(r => !r.read);
       if (
         unreadReplies.length > 0 &&
         this.state.fetchCount > 1 &&
@@ -203,9 +203,9 @@ export class Navbar extends Component<any, NavbarState> {
       this.state.replies = unreadReplies;
       this.setState(this.state);
       this.sendUnreadCount();
-    } else if (op == UserOperation.GetUserMentions) {
-      let res: GetUserMentionsResponse = msg;
-      let unreadMentions = res.mentions.filter(r => !r.read);
+    } else if (res.op == UserOperation.GetUserMentions) {
+      let data = res.data as GetUserMentionsResponse;
+      let unreadMentions = data.mentions.filter(r => !r.read);
       if (
         unreadMentions.length > 0 &&
         this.state.fetchCount > 1 &&
@@ -217,12 +217,12 @@ export class Navbar extends Component<any, NavbarState> {
       this.state.mentions = unreadMentions;
       this.setState(this.state);
       this.sendUnreadCount();
-    } else if (op == UserOperation.GetSite) {
-      let res: GetSiteResponse = msg;
+    } else if (res.op == UserOperation.GetSite) {
+      let data = res.data as GetSiteResponse;
 
-      if (res.site) {
-        this.state.siteName = res.site.name;
-        WebSocketService.Instance.site = res.site;
+      if (data.site) {
+        this.state.siteName = data.site.name;
+        WebSocketService.Instance.site = data.site;
         this.setState(this.state);
       }
     }
-- 
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/navbar.tsx | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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

diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx
index 50bf19c7..fac54212 100644
--- a/ui/src/components/navbar.tsx
+++ b/ui/src/components/navbar.tsx
@@ -12,6 +12,7 @@ import {
   SortType,
   GetSiteResponse,
   Comment,
+  WebSocketJsonResponse,
 } from '../interfaces';
 import {
   wsJsonToRes,
@@ -181,7 +182,7 @@ export class Navbar extends Component<any, NavbarState> {
     i.setState(i.state);
   }
 
-  parseMessage(msg: any) {
+  parseMessage(msg: WebSocketJsonResponse) {
     let res = wsJsonToRes(msg);
     if (res.error) {
       if (res.error == 'not_logged_in') {
-- 
cgit v1.2.3

