fix: #13962, infinite scroll and pagination not working on world

This commit is contained in:
Julian Lam
2026-02-09 13:45:31 -05:00
parent c61326dfa8
commit 9f1369a272
3 changed files with 21 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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({