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

fixes #906 infinite scolling for user challenges #962

Merged
merged 4 commits into from
Jan 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
div.paginator
tc-section(state="state")
button.tc-btn.tc-btn-s(ng-show="pageParams.totalCount > pageParams.currentCount", ng-click="loadMore()") Load More
button.tc-btn.tc-btn-s(ng-show="pageParams.totalCount > pageParams.currentCount && firstLoadMore", ng-click="loadMore()") Load More
2 changes: 1 addition & 1 deletion app/directives/tc-section/tc-section.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
section(ng-switch="state")
.section-loading(ng-switch-when="loading")
.section-loading(ng-transclude, ng-switch-when="loading")

.section-error(ng-switch-when="error")
p {{errMsg}}
Expand Down
13 changes: 8 additions & 5 deletions app/my-challenges/my-challenges.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import _ from 'lodash'
vm.loadMore = loadMore
vm.getChallenges = getChallenges
vm.totalCount = 0
vm.firstLoadMore = true
// this will help to keep track of pagination across individual api calls
var counts = {
devDesign: {total: 0, current: 0},
Expand Down Expand Up @@ -99,7 +100,7 @@ import _ from 'lodash'

function getDevDesignChallenges(offset) {
var params = {
limit: 12,
limit: CONSTANTS.CHALLENGES_LOADING_CHUNK,
offset: offset,
orderBy: vm.orderBy + ' desc',
filter: 'status=' + vm.statusFilter
Expand All @@ -125,7 +126,7 @@ import _ from 'lodash'
_filter = 'status=past&isRatedForMM=true'
}
var params = {
limit: 12,
limit: CONSTANTS.CHALLENGES_LOADING_CHUNK,
offset: offset,
orderBy: vm.statusFilter === 'active' ? 'startDate' : 'endDate desc',
filter: _filter
Expand All @@ -142,12 +143,14 @@ import _ from 'lodash'
}

function loadMore() {
currentOffset+=12
vm.getChallenges(currentOffset, false)
if (vm.loading === CONSTANTS.STATE_READY) {
currentOffset += CONSTANTS.CHALLENGES_LOADING_CHUNK
vm.getChallenges(currentOffset, false)
}
}

window.onscroll = function() {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
if ((window.innerHeight + window.scrollY) >= (document.body.offsetHeight - CONSTANTS.INFINITE_SCROLL_OFFSET)) {
if (vm.totalCount > vm.myChallenges.length) {
vm.loadMore()
}
Expand Down
2 changes: 2 additions & 0 deletions app/my-challenges/my-challenges.jade
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
challenge-tile(
ng-repeat="challenge in vm.myChallenges | orderBy:vm.orderBy:true",
challenge="challenge", view="vm.view", ng-class="vm.view + '-view'")

tc-section.load-more-section(state="vm.loading")
20 changes: 17 additions & 3 deletions app/profile/subtrack/subtrack.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import _ from 'lodash'
vm.showNav = showNav
vm.back = back
vm.subTrackStats = []

vm.loadMore = loadMore
vm.pageName = vm.subTrack

vm.tabs = ['statistics']

if (vm.track !== 'COPILOT') {
Expand All @@ -41,7 +40,7 @@ import _ from 'lodash'
// paging params, these are updated by tc-pager
vm.pageParams = {
currentOffset : 0,
limit: 16,
limit: CONSTANTS.CHALLENGES_LOADING_CHUNK,
currentCount: 0,
totalCount: 0,
// counter used to indicate page change
Expand Down Expand Up @@ -156,6 +155,21 @@ import _ from 'lodash'
$window.history.back()
}

function loadMore() {
if (vm.status.challenges === CONSTANTS.STATE_READY) {
vm.pageParams.currentOffset += CONSTANTS.CHALLENGES_LOADING_CHUNK
_getChallenges()
}
}

window.onscroll = function() {
if ((window.innerHeight + window.scrollY) >= (document.body.offsetHeight - CONSTANTS.INFINITE_SCROLL_OFFSET)) {
if (vm.pageParams.totalCount > vm.challenges.length) {
vm.loadMore()
}
}
}

function _getChallenges() {
vm.status.challenges = CONSTANTS.STATE_LOADING
var params = {
Expand Down
4 changes: 3 additions & 1 deletion app/topcoder.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ angular.module('CONSTANTS', []).constant('CONSTANTS', {
'REGISTERED' : 'REGISTERED',
'SUBMISSION_TYPE_CONTEST': 'Contest Submission',
'STATUS_ACTIVE' : 'Active',
'STATUS_COMPLETED_WITHOUT_WIN' : 'Completed Without Win'
'STATUS_COMPLETED_WITHOUT_WIN' : 'Completed Without Win',
'CHALLENGES_LOADING_CHUNK' : 36,
'INFINITE_SCROLL_OFFSET' : '400' // footer is 300px and challenge tile is 400px
})
1 change: 1 addition & 0 deletions assets/css/directives/tc-section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

.section-loading {
width: 100%;
min-width: 50px;
min-height: 100px;
background: url(../../images/ripple.gif) no-repeat center center;
}
Expand Down