Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 7c1b889

Browse files
fixes #906 infinite scolling for user challenges
1 parent c88f8af commit 7c1b889

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

app/directives/tc-endless-paginator/tc-endless-paginator.directive.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ import angular from 'angular'
1010
template: require('./tc-endless-paginator')(),
1111
scope: {
1212
state: '=',
13-
pageParams: '='
13+
pageParams: '=',
14+
firstLoadMore: '=?'
1415
},
1516
controller: ['$scope', function($scope) {
17+
$scope.firstLoadMore = true
1618
$scope.loadMore = function() {
1719
$scope.pageParams.currentOffset += $scope.pageParams.limit
1820
$scope.pageParams.updated++
21+
$scope.firstLoadMore = false
1922
}
2023
}]
2124
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
div.paginator
22
tc-section(state="state")
3-
button.tc-btn.tc-btn-s(ng-show="pageParams.totalCount > pageParams.currentCount", ng-click="loadMore()") Load More
3+
button.tc-btn.tc-btn-s(ng-show="pageParams.totalCount > pageParams.currentCount && firstLoadMore", ng-click="loadMore()") Load More

app/directives/tc-section/tc-section.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
section(ng-switch="state")
2-
.section-loading(ng-switch-when="loading")
2+
.section-loading(ng-transclude, ng-switch-when="loading")
33

44
.section-error(ng-switch-when="error")
55
p {{errMsg}}

app/my-challenges/my-challenges.controller.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import _ from 'lodash'
2020
vm.loadMore = loadMore
2121
vm.getChallenges = getChallenges
2222
vm.totalCount = 0
23+
vm.firstLoadMore = true
2324
// this will help to keep track of pagination across individual api calls
2425
var counts = {
2526
devDesign: {total: 0, current: 0},
@@ -99,7 +100,7 @@ import _ from 'lodash'
99100

100101
function getDevDesignChallenges(offset) {
101102
var params = {
102-
limit: 12,
103+
limit: CONSTANTS.CHALLENGES_LOADING_CHUNK,
103104
offset: offset,
104105
orderBy: vm.orderBy + ' desc',
105106
filter: 'status=' + vm.statusFilter
@@ -125,7 +126,7 @@ import _ from 'lodash'
125126
_filter = 'status=past&isRatedForMM=true'
126127
}
127128
var params = {
128-
limit: 12,
129+
limit: CONSTANTS.CHALLENGES_LOADING_CHUNK,
129130
offset: offset,
130131
orderBy: vm.statusFilter === 'active' ? 'startDate' : 'endDate desc',
131132
filter: _filter
@@ -142,12 +143,14 @@ import _ from 'lodash'
142143
}
143144

144145
function loadMore() {
145-
currentOffset+=12
146-
vm.getChallenges(currentOffset, false)
146+
if (vm.loading === CONSTANTS.STATE_READY) {
147+
currentOffset += CONSTANTS.CHALLENGES_LOADING_CHUNK
148+
vm.getChallenges(currentOffset, false)
149+
}
147150
}
148151

149152
window.onscroll = function() {
150-
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
153+
if ((window.innerHeight + window.scrollY) >= (document.body.offsetHeight - CONSTANTS.INFINITE_SCROLL_OFFSET)) {
151154
if (vm.totalCount > vm.myChallenges.length) {
152155
vm.loadMore()
153156
}

app/profile/subtrack/subtrack.controller.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import _ from 'lodash'
2626
vm.showNav = showNav
2727
vm.back = back
2828
vm.subTrackStats = []
29-
29+
vm.loadMore = loadMore
3030
vm.pageName = vm.subTrack
31-
31+
vm.firstLoadMore = true
3232
vm.tabs = ['statistics']
3333

3434
if (vm.track !== 'COPILOT') {
@@ -41,7 +41,7 @@ import _ from 'lodash'
4141
// paging params, these are updated by tc-pager
4242
vm.pageParams = {
4343
currentOffset : 0,
44-
limit: 16,
44+
limit: CONSTANTS.CHALLENGES_LOADING_CHUNK,
4545
currentCount: 0,
4646
totalCount: 0,
4747
// counter used to indicate page change
@@ -139,6 +139,7 @@ import _ from 'lodash'
139139
// watches page change counter to reload the data
140140
$scope.$watch('vm.pageParams.updated', function(newValue, oldValue) {
141141
if (newValue !== oldValue) {
142+
vm.firstLoadMore = false
142143
_getChallenges()
143144
}
144145
})
@@ -156,6 +157,21 @@ import _ from 'lodash'
156157
$window.history.back()
157158
}
158159

160+
function loadMore() {
161+
if (vm.status.challenges === CONSTANTS.STATE_READY) {
162+
vm.pageParams.currentOffset += CONSTANTS.CHALLENGES_LOADING_CHUNK
163+
_getChallenges()
164+
}
165+
}
166+
167+
window.onscroll = function() {
168+
if ((window.innerHeight + window.scrollY) >= (document.body.offsetHeight - CONSTANTS.INFINITE_SCROLL_OFFSET)) {
169+
if (vm.pageParams.totalCount > vm.challenges.length && vm.firstLoadMore == false) {
170+
vm.loadMore()
171+
}
172+
}
173+
}
174+
159175
function _getChallenges() {
160176
vm.status.challenges = CONSTANTS.STATE_LOADING
161177
var params = {

app/topcoder.constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ angular.module('CONSTANTS', []).constant('CONSTANTS', {
4343
'REGISTERED' : 'REGISTERED',
4444
'SUBMISSION_TYPE_CONTEST': 'Contest Submission',
4545
'STATUS_ACTIVE' : 'Active',
46-
'STATUS_COMPLETED_WITHOUT_WIN' : 'Completed Without Win'
46+
'STATUS_COMPLETED_WITHOUT_WIN' : 'Completed Without Win',
47+
'CHALLENGES_LOADING_CHUNK' : 12,
48+
'INFINITE_SCROLL_OFFSET' : '400' // footer is 300px and challenge tile is 400px
4749
})

assets/css/directives/tc-section.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
.section-loading {
77
width: 100%;
8+
min-width: 50px;
89
min-height: 100px;
910
background: url(../../images/ripple.gif) no-repeat center center;
1011
}

0 commit comments

Comments
 (0)