mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 02:27:49 +01:00
fix: #13962, infinite scroll and pagination not working on world
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
define('forum/world', [
|
||||
'forum/infinitescroll', 'search', 'sort', 'hooks',
|
||||
'alerts', 'api', 'bootbox', 'helpers', 'forum/category/tools',
|
||||
], function (infinitescroll, search, sort, hooks, alerts, api, bootbox, helpers, categoryTools) {
|
||||
'translator',
|
||||
], function (infinitescroll, search, sort, hooks, alerts, api, bootbox, helpers, categoryTools, translator) {
|
||||
const World = {};
|
||||
|
||||
$(window).on('action:ajaxify.start', function () {
|
||||
@@ -23,8 +24,16 @@ define('forum/world', [
|
||||
const sortLabelEl = document.getElementById('sort-label');
|
||||
const sortOptionsEl = document.getElementById('sort-options');
|
||||
if (sortLabelEl && sortOptionsEl) {
|
||||
const match = sortOptionsEl.querySelector(`a[href="${window.location.pathname}${window.location.search}`);
|
||||
sortLabelEl.innerText = match.innerText;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.get('sort') === 'popular') {
|
||||
translator.translate(`[[world:popular-${params.get('term')}]]`, function (translated) {
|
||||
sortLabelEl.innerText = translated;
|
||||
});
|
||||
} else {
|
||||
translator.translate('[[world:latest]]', function (translated) {
|
||||
sortLabelEl.innerText = translated;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
search.enableQuickSearch({
|
||||
@@ -44,7 +53,7 @@ define('forum/world', [
|
||||
|
||||
if (!config.usePagination) {
|
||||
infinitescroll.init((direction) => {
|
||||
const posts = Array.from(document.querySelectorAll('[component="post"]'));
|
||||
const posts = Array.from(document.querySelectorAll('[component="category/topic"]'));
|
||||
const afterEl = direction > 0 ? posts.pop() : posts.shift();
|
||||
const after = (parseInt(afterEl.getAttribute('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);
|
||||
if (after < config.topicsPerPage) {
|
||||
|
||||
@@ -81,9 +81,10 @@ module.exports = function (Categories) {
|
||||
return result && result.topicCount;
|
||||
}
|
||||
const set = await Categories.buildTopicsSortedSet(data);
|
||||
console.log(set);
|
||||
if (Array.isArray(set)) {
|
||||
return await db.sortedSetIntersectCard(set);
|
||||
} else if (data.targetUid && set) {
|
||||
} else if (parseInt(data.cid, 10) === -1 || data.targetUid && set) {
|
||||
return await db.sortedSetCard(set);
|
||||
}
|
||||
return data.category.topic_count;
|
||||
|
||||
@@ -42,6 +42,7 @@ controller.list = async function (req, res) {
|
||||
data.sort = req.query.sort;
|
||||
|
||||
let tids;
|
||||
let topicCount;
|
||||
if (req.query.sort === 'popular') {
|
||||
cidQuery = {
|
||||
...cidQuery,
|
||||
@@ -50,11 +51,14 @@ controller.list = async function (req, res) {
|
||||
term: req.query.term || 'day',
|
||||
};
|
||||
delete cidQuery.cid;
|
||||
({ tids } = await topics.getSortedTopics(cidQuery));
|
||||
({ tids, topicCount } = await topics.getSortedTopics(cidQuery));
|
||||
tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined);
|
||||
} else {
|
||||
tids = await categories.getTopicIds(cidQuery);
|
||||
topicCount = await categories.getTopicCount(cidQuery);
|
||||
}
|
||||
data.topicCount = topicCount;
|
||||
|
||||
const mainPids = await topics.getMainPids(tids);
|
||||
const postData = await posts.getPostSummaryByPids(mainPids, req.uid, {
|
||||
stripTags: false,
|
||||
@@ -118,6 +122,7 @@ controller.list = async function (req, res) {
|
||||
data.title = translator.escape(data.name);
|
||||
data.breadcrumbs = helpers.buildBreadcrumbs([]);
|
||||
|
||||
console.log(data.topicCount, topicsPerPage);
|
||||
const pageCount = Math.max(1, Math.ceil(data.topicCount / topicsPerPage));
|
||||
data.pagination = pagination.create(page, pageCount, req.query);
|
||||
helpers.addLinkTags({
|
||||
|
||||
Reference in New Issue
Block a user