mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 03:01:08 +01:00
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
This commit is contained in:
committed by
GitHub
parent
cb25faaa2d
commit
4404e81991
@@ -1,22 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
define('forum/tag', ['topicList', 'forum/infinitescroll'], function (topicList, infinitescroll) {
|
||||
define('forum/tag', ['topicList', 'forum/infinitescroll'], function (topicList) {
|
||||
var Tag = {};
|
||||
|
||||
Tag.init = function () {
|
||||
app.enterRoom('tags');
|
||||
|
||||
topicList.init('tag', loadMoreTopics);
|
||||
|
||||
function loadMoreTopics(after, direction, callback) {
|
||||
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
||||
set: 'tag:' + ajaxify.data.tag + ':topics',
|
||||
after: after,
|
||||
direction: direction,
|
||||
count: config.topicsPerPage,
|
||||
}, callback);
|
||||
}
|
||||
topicList.init('tag');
|
||||
};
|
||||
|
||||
return Tag;
|
||||
|
||||
@@ -11,13 +11,6 @@ define('topicList', [
|
||||
var TopicList = {};
|
||||
var templateName = '';
|
||||
|
||||
var tplToSort = {
|
||||
recent: 'recent',
|
||||
unread: 'unread',
|
||||
popular: 'posts',
|
||||
top: 'votes',
|
||||
};
|
||||
|
||||
var newTopicCount = 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) {
|
||||
callback = callback || function () {};
|
||||
var query = utils.params();
|
||||
infinitescroll.loadMore('topics.loadMoreSortedTopics', {
|
||||
after: after,
|
||||
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);
|
||||
query.page = calculateNextPage(after, direction);
|
||||
infinitescroll.loadMoreXhr(query, callback);
|
||||
}
|
||||
|
||||
function filterTopicsOnDom(topics) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const winston = require('winston');
|
||||
|
||||
const topics = require('../../topics');
|
||||
const privileges = require('../../privileges');
|
||||
const meta = require('../../meta');
|
||||
@@ -62,6 +64,7 @@ module.exports = function (SocketTopics) {
|
||||
};
|
||||
|
||||
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) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
@@ -85,6 +88,7 @@ module.exports = function (SocketTopics) {
|
||||
};
|
||||
|
||||
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) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user