Skip to content

Commit

Permalink
comments: Don't load more while loading and update menu on login.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed Nov 28, 2019
1 parent 1cb310a commit 4f3b196
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/app/releases/details/release.comment.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class ReleaseCommentCtrl {
* @param {CommentResource} CommentResource
* @ngInject
*/
constructor(AuthService, ApiHelper, CommentResource) {
constructor($scope, AuthService, ApiHelper, CommentResource) {
this.AuthService = AuthService;
this.ApiHelper = ApiHelper;
this.CommentResource = CommentResource;
Expand All @@ -37,9 +37,11 @@ export default class ReleaseCommentCtrl {
this.editing = false;
this.menuMoveTo = '';
this.onMoved = () => {};

$scope.$watch(() => this.AuthService.user, () => this._updateMenus());
}

$onInit() {
_updateMenus() {
const isOwner = this.AuthService.user && this.AuthService.user.id === this.comment.from.id;
this.hasMoveToMenu = this.menuMoveTo && this.AuthService.hasPermission('releases/moderate');
this.hasEditMenu = isOwner || this.AuthService.hasPermission('releases/moderate');
Expand Down
5 changes: 5 additions & 0 deletions src/app/releases/details/release.details.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,16 @@ export default class ReleaseDetailsCtrl {
}

loadMoreComments() {
if (this.commentsLoading) {
return;
}
this.commentsLoading = true;
this.ReleaseCommentResource.query({
releaseId: this.release.id,
per_page: this.commentsPagesize,
page: ++this.fetchedCommentPages
}, res => {
this.commentsLoading = false;
this._addCommentsToHead(res.data);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/releases/details/release.details.pug
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ include ../../template/_mixins
.zigzag(ng-show="vm.hiddenComments > 0")
.panel.panel--inner
| {{ vm.hiddenComments }} hidden comments
label.a(ng-click="vm.loadMoreComments()") Load more...
label.a(ng-click="vm.loadMoreComments()") {{ vm.commentsLoading ? 'Loading...' : 'Load more...' }}
release-comment(ng-repeat="comment in vm.commentsTail track by comment.id",
comment="comment",
release="vm.release",
Expand Down

0 comments on commit 4f3b196

Please sign in to comment.