Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 4f32a83

Browse files
committed
Added more data load handlers
1 parent 1ca493c commit 4f32a83

File tree

1 file changed

+57
-44
lines changed

1 file changed

+57
-44
lines changed

app/js/listwindow.js

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var winType = 0,
1212
max_count = 0,
1313
total_count = 0,
1414
current_page = 1,
15+
threads = 0,
1516
scroll_busy = false,
1617
filters = { countryCode: '', seen: true, active: false },
1718
MAX_PAGE_SIZE = 10;
@@ -72,34 +73,18 @@ $(function(){
7273
$('header h1').html(user.user_info.uname + (winType == 0 ? ' Fans' : ' Followings'));
7374
});
7475

75-
setTimeout(function(){ startLoad(); }, 100);
76-
setTimeout(function(){ $('main').show(); }, 250);
76+
setTimeout(function(){ startLoad(); }, 200);
77+
78+
setImmediate(function(){ $('main').show(); });
7779

7880
filters.countryCode = '';
7981
filters.seen = true;
8082

81-
setTimeout(function(){
83+
setImmediate(function(){
8284
$('#countryCode').empty();
8385
for (i = 0; i < cclist.length; i++) {
8486
$('#countryCode').append(`<option value="${cclist[i][1]}">${cclist[i][0]}</option>`)
8587
}
86-
}, 5);
87-
88-
$('main').scroll(function() {
89-
if (($(this).scrollTop() + $(this).height()) > ($('table').height() - 128)) {
90-
91-
if (has_more == false) return;
92-
if (scroll_busy == true) return;
93-
94-
scroll_busy = true;
95-
current_page++;
96-
97-
if (winType == 1) {
98-
doFollowings();
99-
} else {
100-
doFans();
101-
}
102-
}
10388
});
10489

10590
});
@@ -108,8 +93,35 @@ function startLoad() {
10893

10994
$('table.fflist tbody').html('');
11095

96+
scroll_busy = true;
11197
current_page = 1;
11298
total_count = 0;
99+
threads = 0;
100+
101+
switch (winType) {
102+
case 1: // Followers/Fans
103+
doFollowings();
104+
break;
105+
106+
case 0: // Followings
107+
doFans();
108+
break;
109+
110+
}
111+
}
112+
113+
function loadMore() {
114+
115+
if (threads > 0) {
116+
setTimeout(function(){
117+
loadMore();
118+
}, 100);
119+
return;
120+
}
121+
122+
scroll_busy = true;
123+
threads = 0;
124+
current_page++;
113125

114126
switch (winType) {
115127
case 1: // Followers/Fans
@@ -155,38 +167,37 @@ function doFollowings() {
155167

156168
for(var i = 0; i < results.length; i++) {
157169
if ((filters.seen == true) && (filters.countryCode.length < 2)) {
170+
threads++;
158171
addEntry(results[i]);
159172
} if ((filters.countryCode.length > 1) && (results[i].countryCode == filters.countryCode)) {
160173
if (filters.seen == true) {
174+
threads++;
161175
addEntry(results[i]);
162176
} else if ((filters.seen == false) && (DataManager.wasProfileViewed(results[i].uid) != false)) {
177+
threads++;
163178
addEntry(results[i]);
164179
}
165180
} else if (filters.countryCode.length < 2) {
166181
if ((filters.seen == false) && (DataManager.wasProfileViewed(results[i].uid) == false)) {
182+
threads++;
167183
addEntry(results[i]);
168184
}
169185
}
170186
}
171187

172-
setTimeout(function(){ scroll_busy = false; }, 250);
173-
174188
has_more = results.length >= MAX_PAGE_SIZE;
175189

176190
var c = $('table.fflist tbody tr').length;
177191
if (filters.seen == false || filters.countryCode.length > 1) {
178-
$('footer h1').html(`Showing ${c} filtered from ${total_count} of ${max_count} accounts, scroll to load more.`);
192+
$('footer h1').html(`Showing ${c} filtered from ${total_count} of ${max_count} accounts.`);
179193
} else {
180-
$('footer h1').html(`Showing ${total_count} of ${max_count} accounts, scroll to load more.`);
194+
$('footer h1').html(`Showing ${total_count} of ${max_count} accounts.`);
181195
}
182196

183-
// $('footer h1').html($('table.fflist tbody tr').length + ' of ' + max_count + ' accounts loaded' + (filters.seen == false || filters.countryCode.length > 1 ? ' and filtered' : '') + '.');
184-
185-
if (has_more && ($('table.fflist tbody tr').length < (MAX_PAGE_SIZE * 3))) {
186-
setTimeout(function(){
187-
current_page++;
188-
doFollowings();
189-
}, filters.active ? 150 : 250)
197+
if (has_more && ($('table.fflist tbody tr').length < max_count)) {
198+
setTimeout(function(){
199+
loadMore();
200+
}, 100);
190201
}
191202
});
192203

@@ -204,52 +215,53 @@ function doFans() {
204215

205216
for(var i = 0; i < results.length; i++) {
206217
if ((filters.seen == true) && (filters.countryCode.length < 2)) {
218+
threads++;
207219
addEntry(results[i]);
208220
} if ((filters.countryCode.length > 1) && (results[i].countryCode == filters.countryCode)) {
209221
if (filters.seen == true) {
222+
threads++;
210223
addEntry(results[i]);
211224
} else if ((filters.seen == false) && (DataManager.wasProfileViewed(results[i].uid) != false)) {
225+
threads++;
212226
addEntry(results[i]);
213227
}
214228
} else if (filters.countryCode.length < 2) {
215229
if ((filters.seen == false) && (DataManager.wasProfileViewed(results[i].uid) == false)) {
230+
threads++;
216231
addEntry(results[i]);
217232
}
218233
}
219234
}
220235

221-
setTimeout(function(){ scroll_busy = false; }, 250);
222-
223236
has_more = results.length >= MAX_PAGE_SIZE;
237+
224238
var c = $('table.fflist tbody tr').length;
225239
if (filters.seen == false || filters.countryCode.length > 1) {
226-
$('footer h1').html(`Showing ${c} filtered from ${total_count} of ${max_count} accounts, scroll to load more.`);
240+
$('footer h1').html(`Showing ${c} filtered from ${total_count} of ${max_count} accounts.`);
227241
} else {
228-
$('footer h1').html(`Showing ${total_count} of ${max_count} accounts, scroll to load more.`);
242+
$('footer h1').html(`Showing ${total_count} of ${max_count} accounts.`);
229243
}
230244

231-
232-
if (has_more && ($('table.fflist tbody tr').length < (MAX_PAGE_SIZE * 3))) {
233-
setTimeout(function(){
234-
current_page++;
235-
doFans();
236-
}, filters.active ? 150 : 250)
245+
if (has_more && ($('table.fflist tbody tr').length < max_count)) {
246+
setTimeout(function(){
247+
loadMore();
248+
}, 100);
237249
}
238250
});
239251
}
240252

241253
function addEntry(entry) {
242254
var prettydate = require('pretty-date');
243-
var sex = entry.sex < 0 ? '' : (entry.sex == 0 ? 'female' : 'male'),
255+
var sex = entry.sex < 0 ? '' : (entry.sex == 0 ? 'is-female' : 'is-male'),
244256
seenRaw = DataManager.wasProfileViewed(entry.uid),
245257
seenDate = seenRaw != false ? prettydate.format(seenRaw) : '',
246258
seen = seenRaw != false ? 'bright blue' : 'dim',
247259
bookmarked = DataManager.isBookmarked(entry) ? 'star-full bright yellow' : 'star-empty dim';
248260

249261
$("table.fflist tbody").append(`
250-
<tr id="entry-${entry.uid}" class="entry-${entry.uid}">
262+
<tr id="entry-${entry.uid}" class="entry-${entry.uid} ${sex}">
251263
<td width="64">
252-
<img src="${entry.face}" style="height: 64px; width: 64px;" onError="$(this).hide()" align="bottom">
264+
<img src="${entry.face}" style="height: 64px; width: 64px;" onError="$(this).hide()" align="bottom" class="avatar">
253265
</td>
254266
<td width="90%">
255267
<div class="seen" title="Last seen ${seenDate}"><i class="icon icon-eye ${seen}"></i></div>
@@ -290,6 +302,7 @@ function addEntry(entry) {
290302
$('#user-' + user.user_info.uid + '-buttons a.fans').html(user.count_info.follower_count + ' Fans');
291303
$('#user-' + user.user_info.uid + '-buttons a.following').html('Following ' + user.count_info.following_count);
292304
}
305+
threads--;
293306
});
294307

295308
/*

0 commit comments

Comments
 (0)