fix: switch inf. scroll to xhr (#9854)

this fixes infinitescroll when url has custom query parameters
also fixes infinitescroll for plugins like QnA
fixes infinitescroll on tags page
deprecate topics.loadMoreSortedTopics
deprecate topics.loadMoreFromSet
isekai-main
Barış Soner Uşaklı 3 years ago committed by GitHub
parent cb25faaa2d
commit 4404e81991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,22 +1,12 @@
'use strict'; 'use strict';
define('forum/tag', ['topicList', 'forum/infinitescroll'], function (topicList) {
define('forum/tag', ['topicList', 'forum/infinitescroll'], function (topicList, infinitescroll) {
var Tag = {}; var Tag = {};
Tag.init = function () { Tag.init = function () {
app.enterRoom('tags'); app.enterRoom('tags');
topicList.init('tag', loadMoreTopics); topicList.init('tag');
function loadMoreTopics(after, direction, callback) {
infinitescroll.loadMore('topics.loadMoreFromSet', {
set: 'tag:' + ajaxify.data.tag + ':topics',
after: after,
direction: direction,
count: config.topicsPerPage,
}, callback);
}
}; };
return Tag; return Tag;

@ -11,13 +11,6 @@ define('topicList', [
var TopicList = {}; var TopicList = {};
var templateName = ''; var templateName = '';
var tplToSort = {
recent: 'recent',
unread: 'unread',
popular: 'posts',
top: 'votes',
};
var newTopicCount = 0; var newTopicCount = 0;
var newPostCount = 0; var newPostCount = 0;
@ -197,21 +190,15 @@ define('topicList', [
}); });
}; };
function calculateNextPage(after, direction) {
return Math.floor(after / config.topicsPerPage) + (direction > 0 ? 1 : 0);
}
function loadTopicsAfter(after, direction, callback) { function loadTopicsAfter(after, direction, callback) {
callback = callback || function () {}; callback = callback || function () {};
var query = utils.params(); var query = utils.params();
infinitescroll.loadMore('topics.loadMoreSortedTopics', { query.page = calculateNextPage(after, direction);
after: after, infinitescroll.loadMoreXhr(query, callback);
direction: direction,
sort: tplToSort[templateName],
count: config.topicsPerPage,
cid: query.cid,
tags: query.tags,
query: query,
term: ajaxify.data.selectedTerm && ajaxify.data.selectedTerm.term,
filter: ajaxify.data.selectedFilter.filter,
set: topicListEl.attr('data-set') ? topicListEl.attr('data-set') : 'topics:recent',
}, callback);
} }
function filterTopicsOnDom(topics) { function filterTopicsOnDom(topics) {

@ -1,5 +1,7 @@
'use strict'; 'use strict';
const winston = require('winston');
const topics = require('../../topics'); const topics = require('../../topics');
const privileges = require('../../privileges'); const privileges = require('../../privileges');
const meta = require('../../meta'); const meta = require('../../meta');
@ -62,6 +64,7 @@ module.exports = function (SocketTopics) {
}; };
SocketTopics.loadMoreSortedTopics = async function (socket, data) { SocketTopics.loadMoreSortedTopics = async function (socket, data) {
winston.warn('[deprecated] use infinitescroll.loadMoreXhr'); // TODO: remove in 1.19.0
if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) { if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
throw new Error('[[error:invalid-data]]'); throw new Error('[[error:invalid-data]]');
} }
@ -85,6 +88,7 @@ module.exports = function (SocketTopics) {
}; };
SocketTopics.loadMoreFromSet = async function (socket, data) { SocketTopics.loadMoreFromSet = async function (socket, data) {
winston.warn('[deprecated] use infinitescroll.loadMoreXhr'); // TODO: remove in 1.19.0
if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0 || !data.set) { if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0 || !data.set) {
throw new Error('[[error:invalid-data]]'); throw new Error('[[error:invalid-data]]');
} }

Loading…
Cancel
Save