From cd4e0ab3c2cfd615e4771fb9181a31ce237b5ceb Mon Sep 17 00:00:00 2001
From: Dessalines <tyhou13@gmx.com>
Date: Wed, 8 Jul 2020 01:02:14 -0400
Subject: HTML title bugs.

- Fixing HTML titles for some pages. Fixes #801
- Removing WebSocketService.Instance.site, fetching site on demand now.
---
 ui/src/components/inbox.tsx | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

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

diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx
index 3b963a79..a88d45c5 100644
--- a/ui/src/components/inbox.tsx
+++ b/ui/src/components/inbox.tsx
@@ -16,6 +16,7 @@ import {
   GetPrivateMessagesForm,
   PrivateMessagesResponse,
   PrivateMessageResponse,
+  GetSiteResponse,
 } from '../interfaces';
 import { WebSocketService, UserService } from '../services';
 import {
@@ -56,6 +57,7 @@ interface InboxState {
   messages: Array<PrivateMessageI>;
   sort: SortType;
   page: number;
+  enableDownvotes: boolean;
 }
 
 export class Inbox extends Component<any, InboxState> {
@@ -68,6 +70,7 @@ export class Inbox extends Component<any, InboxState> {
     messages: [],
     sort: SortType.New,
     page: 1,
+    enableDownvotes: undefined,
   };
 
   constructor(props: any, context: any) {
@@ -85,18 +88,13 @@ export class Inbox extends Component<any, InboxState> {
       );
 
     this.refetch();
+    WebSocketService.Instance.getSite();
   }
 
   componentWillUnmount() {
     this.subscription.unsubscribe();
   }
 
-  componentDidMount() {
-    document.title = `/u/${UserService.Instance.user.username} ${i18n.t(
-      'inbox'
-    )} - ${WebSocketService.Instance.site.name}`;
-  }
-
   render() {
     return (
       <div class="container">
@@ -270,6 +268,7 @@ export class Inbox extends Component<any, InboxState> {
               noIndent
               markable
               showContext
+              enableDownvotes={this.state.enableDownvotes}
             />
           ) : (
             <PrivateMessage privateMessage={i} />
@@ -287,6 +286,7 @@ export class Inbox extends Component<any, InboxState> {
           noIndent
           markable
           showContext
+          enableDownvotes={this.state.enableDownvotes}
         />
       </div>
     );
@@ -301,6 +301,7 @@ export class Inbox extends Component<any, InboxState> {
             noIndent
             markable
             showContext
+            enableDownvotes={this.state.enableDownvotes}
           />
         ))}
       </div>
@@ -522,6 +523,13 @@ export class Inbox extends Component<any, InboxState> {
       let data = res.data as CommentResponse;
       createCommentLikeRes(data, this.state.replies);
       this.setState(this.state);
+    } else if (res.op == UserOperation.GetSite) {
+      let data = res.data as GetSiteResponse;
+      this.state.enableDownvotes = data.site.enable_downvotes;
+      this.setState(this.state);
+      document.title = `/u/${UserService.Instance.user.username} ${i18n.t(
+        'inbox'
+      )} - ${data.site.name}`;
     }
   }
 
-- 
cgit v1.2.3

