Node.js based forum software built for the modern web
fix: #13962, infinite scroll and pagination not working on world
Julian Lam9f1369a272f2
diff --git a/public/src/client/world.js b/public/src/client/world.jsindex f428b4c97e..adf6925e57 100644--- a/public/src/client/world.js+++ b/public/src/client/world.js@@ -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) {diff --git a/src/categories/topics.js b/src/categories/topics.jsindex 633779ef89..83cc41ee45 100644--- a/src/categories/topics.js+++ b/src/categories/topics.js@@ -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;diff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.jsindex 2052c708a3..59eed289c1 100644--- a/src/controllers/activitypub/topics.js+++ b/src/controllers/activitypub/topics.js@@ -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({