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