diff --git a/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee b/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee index 8dbcb903..2606a3fa 100644 --- a/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee @@ -31,10 +31,10 @@ class UserTimelineController extends mixOf(taiga.Controller, taiga.PageMixin, ta constructor: (@userTimelineService) -> @.timelineList = Immutable.List() @.page = 1 - @.loadingData = false + @.scrollDisabled = false loadTimeline: () -> - @.loadingData = true + @.scrollDisabled = true if @.projectId @userTimelineService @@ -50,7 +50,9 @@ class UserTimelineController extends mixOf(taiga.Controller, taiga.PageMixin, ta _timelineLoaded: (newTimelineList) -> @.timelineList = @.timelineList.concat(newTimelineList) @.page++ - @.loadingData = false + + if newTimelineList.size + @.scrollDisabled = false angular.module("taigaUserTimeline") .controller("UserTimeline", UserTimelineController) diff --git a/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee b/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee index c0dc090c..6c5ec00e 100644 --- a/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee @@ -47,7 +47,7 @@ describe "UserTimelineController", -> { fake: "fake"} ]) - it "the loadingData variable must be true during the timeline load", () -> + it "the scrollDisabled variable must be true during the timeline load", () -> myCtrl = controller "UserTimeline" myCtrl.userId = mockUser.id @@ -59,15 +59,39 @@ describe "UserTimelineController", -> then: thenStub }) - expect(myCtrl.loadingData).to.be.false + expect(myCtrl.scrollDisabled).to.be.false myCtrl.loadTimeline() - expect(myCtrl.loadingData).to.be.true + expect(myCtrl.scrollDisabled).to.be.true thenStub.callArgWith(0, timelineList) - expect(myCtrl.loadingData).to.be.false + expect(myCtrl.scrollDisabled).to.be.false + + it "disable scroll when no more content", () -> + emptyTimelineList = Immutable.fromJS([]) + + myCtrl = controller "UserTimeline" + myCtrl.userId = mockUser.id + + thenStub = sinon.stub() + + mocks.userTimelineService.getTimeline = sinon.stub() + .withArgs(mockUser.id, myCtrl.page) + .returns({ + then: thenStub + }) + + expect(myCtrl.scrollDisabled).to.be.false + + myCtrl.loadTimeline() + + expect(myCtrl.scrollDisabled).to.be.true + + thenStub.callArgWith(0, emptyTimelineList) + + expect(myCtrl.scrollDisabled).to.be.true it "pagiantion increase one every call to loadTimeline", () -> myCtrl = controller "UserTimeline" diff --git a/app/modules/user-timeline/user-timeline/user-timeline.jade b/app/modules/user-timeline/user-timeline/user-timeline.jade index 4c57d15a..e3c80b78 100644 --- a/app/modules/user-timeline/user-timeline/user-timeline.jade +++ b/app/modules/user-timeline/user-timeline/user-timeline.jade @@ -1,3 +1,3 @@ section.profile-timeline - div(infinite-scroll="vm.loadTimeline()", infinite-scroll-distance="3", infinite-scroll-disabled="vm.loadingData") + div(infinite-scroll="vm.loadTimeline()", infinite-scroll-distance="3", infinite-scroll-disabled="vm.scrollDisabled") div(tg-repeat="timeline in vm.timelineList", tg-user-timeline-item="timeline")