]> Untitled Git - lemmy.git/commitdiff
Correctly hide next / prev in paginators. Fixes #914 (#927)
authorDessalines <dessalines@users.noreply.github.com>
Fri, 10 Jul 2020 00:03:33 +0000 (20:03 -0400)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 00:03:33 +0000 (20:03 -0400)
ui/src/components/communities.tsx
ui/src/components/community.tsx
ui/src/components/inbox.tsx
ui/src/components/main.tsx
ui/src/components/search.tsx
ui/src/components/user.tsx

index 441f7bb148686f4ef9bb7e15a7411f4839b09792..10a3ab803e4e01e2e7e9fb73af45ee62c379e95d 100644 (file)
@@ -160,7 +160,7 @@ export class Communities extends Component<any, CommunitiesState> {
           </button>
         )}
 
-        {this.state.communities.length == communityLimit && (
+        {this.state.communities.length > 0 && (
           <button
             class="btn btn-sm btn-secondary"
             onClick={linkEvent(this, this.nextPage)}
index ff50c3dc72d70f37559c9ff3c14e5a338550f2e3..fc999b25abd508f7e276e76e1d3df908eabfd3b7 100644 (file)
@@ -260,7 +260,7 @@ export class Community extends Component<any, State> {
             {i18n.t('prev')}
           </button>
         )}
-        {this.state.posts.length == fetchLimit && (
+        {this.state.posts.length > 0 && (
           <button
             class="btn btn-sm btn-secondary"
             onClick={linkEvent(this, this.nextPage)}
index a88d45c52b4c2efc3b9096631b3d101cfc3a4703..2bf1fb471d73d722d8e9baeaa7a528b47918b5e9 100644 (file)
@@ -329,12 +329,14 @@ export class Inbox extends Component<any, InboxState> {
             {i18n.t('prev')}
           </button>
         )}
-        <button
-          class="btn btn-sm btn-secondary"
-          onClick={linkEvent(this, this.nextPage)}
-        >
-          {i18n.t('next')}
-        </button>
+        {this.unreadCount() > 0 && (
+          <button
+            class="btn btn-sm btn-secondary"
+            onClick={linkEvent(this, this.nextPage)}
+          >
+            {i18n.t('next')}
+          </button>
+        )}
       </div>
     );
   }
@@ -534,15 +536,19 @@ export class Inbox extends Component<any, InboxState> {
   }
 
   sendUnreadCount() {
-    let count =
+    UserService.Instance.user.unreadCount = this.unreadCount();
+    UserService.Instance.sub.next({
+      user: UserService.Instance.user,
+    });
+  }
+
+  unreadCount(): number {
+    return (
       this.state.replies.filter(r => !r.read).length +
       this.state.mentions.filter(r => !r.read).length +
       this.state.messages.filter(
         r => !r.read && r.creator_id !== UserService.Instance.user.id
-      ).length;
-    UserService.Instance.user.unreadCount = count;
-    UserService.Instance.sub.next({
-      user: UserService.Instance.user,
-    });
+      ).length
+    );
   }
 }
index 9e9027d63fbab8c3253f45ec81bed7321da75b19..9063a03969ae564a315afbdb4936c251556398c9 100644 (file)
@@ -497,7 +497,7 @@ export class Main extends Component<any, MainState> {
             {i18n.t('prev')}
           </button>
         )}
-        {this.state.posts.length == fetchLimit && (
+        {this.state.posts.length > 0 && (
           <button
             class="btn btn-sm btn-secondary"
             onClick={linkEvent(this, this.nextPage)}
index 2588528a73d798583599b553330a30171f0bf4b5..dd219ba96e46fce33fc89e6b2b33ac2307024413 100644 (file)
@@ -148,7 +148,7 @@ export class Search extends Component<any, SearchState> {
         {this.state.type_ == SearchType.Posts && this.posts()}
         {this.state.type_ == SearchType.Communities && this.communities()}
         {this.state.type_ == SearchType.Users && this.users()}
-        {this.noResults()}
+        {this.resultsCount() == 0 && <span>{i18n.t('no_results')}</span>}
         {this.paginator()}
       </div>
     );
@@ -383,26 +383,26 @@ export class Search extends Component<any, SearchState> {
             {i18n.t('prev')}
           </button>
         )}
-        <button
-          class="btn btn-sm btn-secondary"
-          onClick={linkEvent(this, this.nextPage)}
-        >
-          {i18n.t('next')}
-        </button>
+
+        {this.resultsCount() > 0 && (
+          <button
+            class="btn btn-sm btn-secondary"
+            onClick={linkEvent(this, this.nextPage)}
+          >
+            {i18n.t('next')}
+          </button>
+        )}
       </div>
     );
   }
 
-  noResults() {
+  resultsCount(): number {
     let res = this.state.searchResponse;
     return (
-      <div>
-        {res &&
-          res.posts.length == 0 &&
-          res.comments.length == 0 &&
-          res.communities.length == 0 &&
-          res.users.length == 0 && <span>{i18n.t('no_results')}</span>}
-      </div>
+      res.posts.length +
+      res.comments.length +
+      res.communities.length +
+      res.users.length
     );
   }
 
index 7e679ed1bf1dc9befab39b33abe2742f3428eaf6..af72a3974f347acde0c3ee1bd1525d638c2ca642 100644 (file)
@@ -893,12 +893,14 @@ export class User extends Component<any, UserState> {
             {i18n.t('prev')}
           </button>
         )}
-        <button
-          class="btn btn-sm btn-secondary"
-          onClick={linkEvent(this, this.nextPage)}
-        >
-          {i18n.t('next')}
-        </button>
+        {this.state.comments.length + this.state.posts.length > 0 && (
+          <button
+            class="btn btn-sm btn-secondary"
+            onClick={linkEvent(this, this.nextPage)}
+          >
+            {i18n.t('next')}
+          </button>
+        )}
       </div>
     );
   }