diff options
author | Dessalines <dessalines@users.noreply.github.com> | 2020-07-09 20:03:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-09 20:03:33 -0400 |
commit | 85c07e7154c82e5b387bb6a02aae70645cf1d8e0 (patch) | |
tree | 3b5a56578b8b504faf366555466422f0b14b2770 | |
parent | d222c60cef289b57f0ce350e9f24ce2df4792ef5 (diff) |
Correctly hide next / prev in paginators. Fixes #914 (#927)
-rw-r--r-- | ui/src/components/communities.tsx | 2 | ||||
-rw-r--r-- | ui/src/components/community.tsx | 2 | ||||
-rw-r--r-- | ui/src/components/inbox.tsx | 30 | ||||
-rw-r--r-- | ui/src/components/main.tsx | 2 | ||||
-rw-r--r-- | ui/src/components/search.tsx | 30 | ||||
-rw-r--r-- | ui/src/components/user.tsx | 14 |
6 files changed, 44 insertions, 36 deletions
diff --git a/ui/src/components/communities.tsx b/ui/src/components/communities.tsx index 441f7bb1..10a3ab80 100644 --- a/ui/src/components/communities.tsx +++ b/ui/src/components/communities.tsx @@ -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)} diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx index ff50c3dc..fc999b25 100644 --- a/ui/src/components/community.tsx +++ b/ui/src/components/community.tsx @@ -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)} diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index a88d45c5..2bf1fb47 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -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 + ); } } diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 9e9027d6..9063a039 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -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)} diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index 2588528a..dd219ba9 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -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 ); } diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index 7e679ed1..af72a397 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -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> ); } |