From 675cf6165488b0a68fe06696fda076c60ff96a76 Mon Sep 17 00:00:00 2001
From: Dessalines <tyhou13@gmx.com>
Date: Tue, 30 Apr 2019 08:19:00 -0700
Subject: Custom site name.

- Fixes #113
---
 ui/src/components/navbar.tsx | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

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

diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx
index ee19e5c5..6861461c 100644
--- a/ui/src/components/navbar.tsx
+++ b/ui/src/components/navbar.tsx
@@ -3,7 +3,7 @@ import { Link } from 'inferno-router';
 import { Subscription } from "rxjs";
 import { retryWhen, delay, take } from 'rxjs/operators';
 import { WebSocketService, UserService } from '../services';
-import { UserOperation, GetRepliesForm, GetRepliesResponse, SortType } from '../interfaces';
+import { UserOperation, GetRepliesForm, GetRepliesResponse, SortType, GetSiteResponse } from '../interfaces';
 import { msgOp } from '../utils';
 import { version } from '../version';
 
@@ -12,6 +12,7 @@ interface NavbarState {
   expanded: boolean;
   expandUserDropdown: boolean;
   unreadCount: number;
+  siteName: string;
 }
 
 export class Navbar extends Component<any, NavbarState> {
@@ -21,7 +22,8 @@ export class Navbar extends Component<any, NavbarState> {
     isLoggedIn: (UserService.Instance.user !== undefined),
     unreadCount: 0,
     expanded: false,
-    expandUserDropdown: false
+    expandUserDropdown: false,
+    siteName: undefined
   }
 
   constructor(props: any, context: any) {
@@ -45,6 +47,8 @@ export class Navbar extends Component<any, NavbarState> {
         (err) => console.error(err),
         () => console.log('complete')
     );
+
+    WebSocketService.Instance.getSite();
   }
 
   render() {
@@ -59,13 +63,12 @@ export class Navbar extends Component<any, NavbarState> {
   }
 
   // TODO class active corresponding to current page
-  // TODO toggle css collapse
   navbar() {
     return (
       <nav class="container navbar navbar-expand-md navbar-light navbar-bg p-0 px-3">
         <Link title={version} class="navbar-brand" to="/">
           <svg class="icon mr-2 mouse-icon"><use xlinkHref="#icon-mouse"></use></svg>
-          Lemmy
+          {this.state.siteName}
         </Link>
         <button class="navbar-toggler" type="button" onClick={linkEvent(this, this.expandNavbar)}>
           <span class="navbar-toggler-icon"></span>
@@ -145,6 +148,14 @@ export class Navbar extends Component<any, NavbarState> {
     } else if (op == UserOperation.GetReplies) {
       let res: GetRepliesResponse = msg;
       this.sendRepliesCount(res);
+    } else if (op == UserOperation.GetSite) {
+      let res: GetSiteResponse = msg;
+
+      if (res.site) {
+        this.state.siteName = res.site.name;
+        WebSocketService.Instance.site = res.site;
+        this.setState(this.state);
+      }
     } 
   }
 
-- 
cgit v1.2.3

