]> Untitled Git - lemmy.git/blobdiff - ui/src/components/navbar.tsx
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / ui / src / components / navbar.tsx
index 5584b3b64df102928c0105245c04573270f1470f..4ef5276c36c9a72f030483f0a19c3aafe5ece433 100644 (file)
@@ -18,18 +18,17 @@ import {
   PrivateMessage,
   PrivateMessageResponse,
   WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
 import {
   wsJsonToRes,
   pictrsAvatarThumbnail,
   showAvatars,
   fetchLimit,
-  isCommentType,
   toast,
-  messageToastify,
-  md,
   setTheme,
   getLanguage,
+  notifyComment,
+  notifyPrivateMessage,
 } from '../utils';
 import { i18n } from '../i18next';
 
@@ -82,6 +81,7 @@ export class Navbar extends Component<any, NavbarState> {
       banned: [],
       online: null,
       version: null,
+      federated_instances: null,
     },
     searchParam: '',
     toggleSearch: false,
@@ -137,7 +137,7 @@ export class Navbar extends Component<any, NavbarState> {
       this.context.router.history.push(`/search/`);
     } else {
       this.context.router.history.push(
-        `/search/q/${searchParam}/type/all/sort/topall/page/1`
+        `/search/q/${searchParam}/type/All/sort/TopAll/page/1`
       );
     }
   }
@@ -184,7 +184,7 @@ export class Navbar extends Component<any, NavbarState> {
           {!this.state.siteLoading ? (
             <Link
               title={this.state.siteRes.version}
-              class="d-flex align-items-center navbar-brand mr-1"
+              class="d-flex align-items-center navbar-brand mr-md-3"
               to="/"
             >
               {this.state.siteRes.site.icon && showAvatars() && (
@@ -235,7 +235,7 @@ export class Navbar extends Component<any, NavbarState> {
                 !this.state.expanded && 'collapse'
               } navbar-collapse`}
             >
-              <ul class="ml-3 navbar-nav my-2 mr-auto">
+              <ul class="navbar-nav my-2 mr-auto">
                 <li class="nav-item">
                   <Link
                     class="nav-link"
@@ -369,7 +369,7 @@ export class Navbar extends Component<any, NavbarState> {
                 </>
               ) : (
                 <ul class="navbar-nav my-2">
-                  <li className="nav-item">
+                  <li className="ml-2 nav-item">
                     <Link
                       class="btn btn-success"
                       to="/login"
@@ -435,7 +435,7 @@ export class Navbar extends Component<any, NavbarState> {
           this.state.unreadCount++;
           this.setState(this.state);
           this.sendUnreadCount();
-          this.notify(data.comment);
+          notifyComment(data.comment, this.context.router);
         }
       }
     } else if (res.op == UserOperation.CreatePrivateMessage) {
@@ -447,7 +447,7 @@ export class Navbar extends Component<any, NavbarState> {
           this.state.unreadCount++;
           this.setState(this.state);
           this.sendUnreadCount();
-          this.notify(data.message);
+          notifyPrivateMessage(data.message, this.context.router);
         }
       }
     } else if (res.op == UserOperation.GetSite) {
@@ -477,14 +477,14 @@ export class Navbar extends Component<any, NavbarState> {
   fetchUnreads() {
     console.log('Fetching unreads...');
     let repliesForm: GetRepliesForm = {
-      sort: SortType[SortType.New],
+      sort: SortType.New,
       unread_only: true,
       page: 1,
       limit: fetchLimit,
     };
 
     let userMentionsForm: GetUserMentionsForm = {
-      sort: SortType[SortType.New],
+      sort: SortType.New,
       unread_only: true,
       page: 1,
       limit: fetchLimit,
@@ -541,37 +541,4 @@ export class Navbar extends Component<any, NavbarState> {
       });
     }
   }
-
-  notify(reply: Comment | PrivateMessage) {
-    let creator_name = reply.creator_name;
-    let creator_avatar = reply.creator_avatar
-      ? reply.creator_avatar
-      : `${window.location.protocol}//${window.location.host}/static/assets/apple-touch-icon.png`;
-    let link = isCommentType(reply)
-      ? `/post/${reply.post_id}/comment/${reply.id}`
-      : `/inbox`;
-    let htmlBody = md.render(reply.content);
-    let body = reply.content; // Unfortunately the notifications API can't do html
-
-    messageToastify(
-      creator_name,
-      creator_avatar,
-      htmlBody,
-      link,
-      this.context.router
-    );
-
-    if (Notification.permission !== 'granted') Notification.requestPermission();
-    else {
-      var notification = new Notification(reply.creator_name, {
-        icon: creator_avatar,
-        body: body,
-      });
-
-      notification.onclick = () => {
-        event.preventDefault();
-        this.context.router.history.push(link);
-      };
-    }
-  }
 }