From 682413613e75618489d262bd033c3101da96abd7 Mon Sep 17 00:00:00 2001
From: Dessalines <tyhou13@gmx.com>
Date: Sat, 20 Apr 2019 11:17:00 -0700
Subject: Mostly working, before merge

---
 ui/src/components/navbar.tsx | 16 ++++++++++++----
 1 file changed, 12 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 be98912e..fed49e6f 100644
--- a/ui/src/components/navbar.tsx
+++ b/ui/src/components/navbar.tsx
@@ -7,12 +7,14 @@ interface NavbarState {
   isLoggedIn: boolean;
   expanded: boolean;
   expandUserDropdown: boolean;
+  unreadCount: number;
 }
 
 export class Navbar extends Component<any, NavbarState> {
 
   emptyState: NavbarState = {
-    isLoggedIn: UserService.Instance.user !== undefined,
+    isLoggedIn: (UserService.Instance.user !== undefined),
+    unreadCount: 0,
     expanded: false,
     expandUserDropdown: false
   }
@@ -24,8 +26,9 @@ export class Navbar extends Component<any, NavbarState> {
 
     // Subscribe to user changes
     UserService.Instance.sub.subscribe(user => {
-      let loggedIn: boolean = user !== undefined;
-      this.setState({isLoggedIn: loggedIn});
+      this.state.isLoggedIn = user.user !== undefined;
+      this.state.unreadCount = user.unreadCount;
+      this.setState(this.state);
     });
   }
 
@@ -65,9 +68,13 @@ export class Navbar extends Component<any, NavbarState> {
           <ul class="navbar-nav ml-auto mr-2">
             {this.state.isLoggedIn ? 
             <>
+              {
               <li className="nav-item">
-                <Link class="nav-link" to="/communities">🖂</Link>
+                <Link class="nav-link" to="/inbox">🖂 
+                  {this.state.unreadCount> 0 && <span class="badge badge-light">{this.state.unreadCount}</span>}
+                </Link>
               </li>
+            }
               <li className={`nav-item dropdown ${this.state.expandUserDropdown && 'show'}`}>
                 <a class="pointer nav-link dropdown-toggle" onClick={linkEvent(this, this.expandUserDropdown)} role="button">
                   {UserService.Instance.user.username}
@@ -95,6 +102,7 @@ export class Navbar extends Component<any, NavbarState> {
   handleLogoutClick(i: Navbar) {
     i.state.expandUserDropdown = false;
     UserService.Instance.logout();
+    i.context.router.history.push('/');
   }
 
   handleOverviewClick(i: Navbar) {
-- 
cgit v1.2.3

