From 6bc0ec64aca1539f183bca3d2cbf1793cd1b6192 Mon Sep 17 00:00:00 2001 From: newperson1746 Date: Sat, 6 Sep 2025 03:14:06 +0000 Subject: [PATCH 1/6] Deduplicate check for !topics; move to helper --- public/src/modules/topicList.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js index 6396bb9e8e..62a67240d9 100644 --- a/public/src/modules/topicList.js +++ b/public/src/modules/topicList.js @@ -187,17 +187,20 @@ define('topicList', [ }); } - function onTopicsLoaded(templateName, topics, showSelect, direction, callback) { + function noTopics(topics, callback) { if (!topics || !topics.length) { $('#load-more-btn').hide(); - return callback(); + callback(); + return true; } + return false; + } + + function onTopicsLoaded(templateName, topics, showSelect, direction, callback) { + if (noTopics(topics, callback)) return; topics = filterTopicsOnDom(topics); - if (!topics.length) { - $('#load-more-btn').hide(); - return callback(); - } + if (noTopics(topics, callback)) return; let after; let before; From df83b5d9682f26a76d68e3bbaef32d4c7e298658 Mon Sep 17 00:00:00 2001 From: newperson1746 Date: Sat, 6 Sep 2025 03:17:57 +0000 Subject: [PATCH 2/6] Insert print statement into refactored for test --- public/src/modules/topicList.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js index 62a67240d9..0095acbd70 100644 --- a/public/src/modules/topicList.js +++ b/public/src/modules/topicList.js @@ -197,6 +197,8 @@ define('topicList', [ } function onTopicsLoaded(templateName, topics, showSelect, direction, callback) { + console.log('lee test called!'); + if (noTopics(topics, callback)) return; topics = filterTopicsOnDom(topics); From ae451644937c6e96bc1181c8097b9f66ce43fba8 Mon Sep 17 00:00:00 2001 From: newperson1746 Date: Sat, 6 Sep 2025 03:36:12 +0000 Subject: [PATCH 3/6] Move topics direction logic to helper function --- public/src/modules/topicList.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js index 0095acbd70..ef4eeb4c66 100644 --- a/public/src/modules/topicList.js +++ b/public/src/modules/topicList.js @@ -196,6 +196,13 @@ define('topicList', [ return false; } + function getInsertionPoints(direction, topicEls) { + return { + after: direction > 0 ? topicEls.last() : null, + before: direction < 0 ? topicEls.first() : null + }; + } + function onTopicsLoaded(templateName, topics, showSelect, direction, callback) { console.log('lee test called!'); @@ -204,15 +211,7 @@ define('topicList', [ if (noTopics(topics, callback)) return; - let after; - let before; - const topicEls = topicListEl.find('[component="category/topic"]'); - - if (direction > 0 && topics.length) { - after = topicEls.last(); - } else if (direction < 0 && topics.length) { - before = topicEls.first(); - } + const { after, before } = getInsertionPoints(direction, topicListEl.find('[component="category/topic"]')); const tplData = { topics: topics, From 4334c6a514f90a6f8e7bda3129365658ac670e9b Mon Sep 17 00:00:00 2001 From: newperson1746 Date: Sat, 6 Sep 2025 03:36:47 +0000 Subject: [PATCH 4/6] Fix missing comma --- public/src/modules/topicList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js index ef4eeb4c66..bcc30eddda 100644 --- a/public/src/modules/topicList.js +++ b/public/src/modules/topicList.js @@ -199,7 +199,7 @@ define('topicList', [ function getInsertionPoints(direction, topicEls) { return { after: direction > 0 ? topicEls.last() : null, - before: direction < 0 ? topicEls.first() : null + before: direction < 0 ? topicEls.first() : null, }; } From c4f74691d4a82814c9151b9d849c7effe647a446 Mon Sep 17 00:00:00 2001 From: newperson1746 Date: Sat, 6 Sep 2025 03:42:13 +0000 Subject: [PATCH 5/6] Refactor html insertion logic into helper func --- public/src/modules/topicList.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js index bcc30eddda..9b18db45e5 100644 --- a/public/src/modules/topicList.js +++ b/public/src/modules/topicList.js @@ -203,6 +203,21 @@ define('topicList', [ }; } + function insertHtml(html, after, before, topicListEl) { + if (after?.length) { + html.insertAfter(after); + } else if (before?.length) { + const height = $(document).height(); + const scrollTop = $(window).scrollTop(); + + html.insertBefore(before); + + $(window).scrollTop(scrollTop + ($(document).height() - height)); + } else { + topicListEl.append(html); + } + } + function onTopicsLoaded(templateName, topics, showSelect, direction, callback) { console.log('lee test called!'); @@ -228,18 +243,7 @@ define('topicList', [ topicListEl.removeClass('hidden'); $('#category-no-topics').remove(); - if (after && after.length) { - html.insertAfter(after); - } else if (before && before.length) { - const height = $(document).height(); - const scrollTop = $(window).scrollTop(); - - html.insertBefore(before); - - $(window).scrollTop(scrollTop + ($(document).height() - height)); - } else { - topicListEl.append(html); - } + insertHtml(html, after, before, topicListEl); if (!topicSelect.getSelectedTids().length) { infinitescroll.removeExtra(topicListEl.find('[component="category/topic"]'), direction, Math.max(60, config.topicsPerPage * 3)); From f545978e25c26ceb828f1e6498744158386247f9 Mon Sep 17 00:00:00 2001 From: newperson1746 Date: Sat, 6 Sep 2025 03:42:37 +0000 Subject: [PATCH 6/6] Remove debug print --- public/src/modules/topicList.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/public/src/modules/topicList.js b/public/src/modules/topicList.js index 9b18db45e5..19024506ee 100644 --- a/public/src/modules/topicList.js +++ b/public/src/modules/topicList.js @@ -219,8 +219,6 @@ define('topicList', [ } function onTopicsLoaded(templateName, topics, showSelect, direction, callback) { - console.log('lee test called!'); - if (noTopics(topics, callback)) return; topics = filterTopicsOnDom(topics);