diff --git a/public/s/js/sidebar-activity.js b/public/s/js/sidebar-activity.js index 96f2377..93a985c 100644 --- a/public/s/js/sidebar-activity.js +++ b/public/s/js/sidebar-activity.js @@ -390,7 +390,7 @@ let mediaHtml = ''; let thumbUrl = `/t/${c.item_id}.webp`; if (window.applyThumbCacheBust) thumbUrl = window.applyThumbCacheBust(thumbUrl); - mediaHtml = ``; + mediaHtml = ``; itemPreview = `
@@ -525,7 +525,8 @@ return true; }; - const SIDEBAR_PAGE_LIMIT = 5; + const SIDEBAR_PAGE_LIMIT = 50; + const SIDEBAR_INITIAL_LIMIT = 15; const loadActivity = async (silent = false) => { const container = document.getElementById('sidebar-activity-container'); @@ -545,7 +546,7 @@ hasMore = true; try { const mode = typeof window.activeMode !== 'undefined' ? window.activeMode : ''; - const res = await fetch(`/activity?json=true&page=1&mode=${mode}`, { + const res = await fetch(`/activity?json=true&page=1&limit=${SIDEBAR_INITIAL_LIMIT}&mode=${mode}`, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }); const data = await res.json(); @@ -555,7 +556,7 @@ ...c, body: c.content || c.body })); - hasMore = data.hasMore === true; + hasMore = data.hasMore === true || data.comments.length === SIDEBAR_INITIAL_LIMIT; renderFromCache(); // Also check after a delay to account for image/emoji loading shifts setTimeout(checkOverflow, 500); @@ -580,7 +581,9 @@ if (!container || loading || loadingMore || !hasMore) return; loadingMore = true; - const nextPage = currentPage + 1; + // Use the current cache length as the exact offset so there's never a gap, + // regardless of the initial fetch limit. + const nextOffset = window._sidebarActivityCache.length; // Show a subtle loading row at the bottom const sentinel = document.createElement('div'); @@ -591,7 +594,7 @@ try { const mode = typeof window.activeMode !== 'undefined' ? window.activeMode : ''; - const res = await fetch(`/activity?json=true&page=${nextPage}&mode=${mode}`, { + const res = await fetch(`/activity?json=true&offset=${nextOffset}&limit=${SIDEBAR_PAGE_LIMIT}&mode=${mode}`, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }); const data = await res.json(); @@ -601,7 +604,7 @@ if (s) s.remove(); if (data.success && data.comments && data.comments.length > 0) { - currentPage = nextPage; + currentPage++; hasMore = data.hasMore === true; // Append only comments not already in the cache diff --git a/src/inc/routes/comments.mjs b/src/inc/routes/comments.mjs index acf31da..feccaec 100644 --- a/src/inc/routes/comments.mjs +++ b/src/inc/routes/comments.mjs @@ -783,8 +783,11 @@ export default (router, tpl) => { router.get(/\/activity\/?/, async (req, res) => { try { const page = +(req.url.qs?.page || 1); - const limit = 50; - const offset = (page - 1) * limit; + const limit = Math.min(+(req.url.qs?.limit || 50), 50); + // Support explicit offset (used by sidebar infinite-scroll after a non-standard initial limit) + const offset = req.url.qs?.offset !== undefined + ? Math.max(0, +(req.url.qs.offset)) + : (page - 1) * limit; /* */ // prioritize query mode (from AJAX) over session default