From b82a0c765796053ce1bf20a840d838a1577d91d0 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 15 Feb 2023 13:03:58 -0500 Subject: [PATCH] fix: update unread indicator on scroll, add unread count --- public/src/client/topic.js | 2 +- public/src/modules/navigator.js | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 67f5de1137..9150414dec 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -359,7 +359,7 @@ define('forum/topic', [ ) ) { if (app.user.uid) { - ajaxify.data.bookmark = index + 1; + ajaxify.data.bookmark = index; socket.emit('topics.bookmark', { tid: ajaxify.data.tid, diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js index f21562813a..ef66590d21 100644 --- a/public/src/modules/navigator.js +++ b/public/src/modules/navigator.js @@ -1,6 +1,6 @@ 'use strict'; -define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts'], function (pagination, components, hooks, alerts) { +define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts', 'translator'], function (pagination, components, hooks, alerts, translator) { const navigator = {}; let index = 0; let count = 0; @@ -86,7 +86,7 @@ define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts'], funct if (ajaxify.data.template.topic) { handleScrollNav(); - updateUnreadIndicator(ajaxify.data.bookmark); + updateUnreadIndicator(ajaxify.data.postIndex); } handleKeys(); @@ -353,10 +353,6 @@ define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts'], funct } index = Math.max(index, ajaxify.data.bookmark); - // const meta = unreadEl.querySelector('.meta'); - // if (isHidden(meta)) { - // return; - // } const unreadEl = paginationBlockUnreadEl.get(0); const trackEl = unreadEl.parentNode; const trackHeight = trackEl.getBoundingClientRect().height; @@ -364,16 +360,16 @@ define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts'], funct const percentage = 1 - (index / ajaxify.data.postcount); unreadEl.style.height = `${trackHeight * percentage}px`; - // const anchorEl = unreadEl.querySelector('.meta a'); - // const remaining = ajaxify.data.postcount - index; - // if (remaining > 0) { - // const text = await translate(`[[topic:navigator.unread, ${remaining}]]`); - // anchorEl.href = `${config.relative_path}/topic/${ajaxify.data.slug}/${Math.min(index + 1, ajaxify.data.postcount)}`; - // anchorEl.innerText = text; - // } else { - // anchorEl.href = ajaxify.data.url; - // anchorEl.innerText = ''; - // } + const anchorEl = unreadEl.querySelector('.meta a'); + const remaining = ajaxify.data.postcount - index; + if (remaining > 0) { + const text = await translator.translate(`[[topic:navigator.unread, ${remaining}]]`); + anchorEl.href = `${config.relative_path}/topic/${ajaxify.data.slug}/${Math.min(index + 1, ajaxify.data.postcount)}`; + anchorEl.innerText = text; + } else { + anchorEl.href = ajaxify.data.url; + anchorEl.innerText = ''; + } } function clearRenderInterval() { @@ -514,6 +510,7 @@ define('navigator', ['forum/pagination', 'components', 'hooks', 'alerts'], funct if (newIndex !== index) { index = newIndex; navigator.updateTextAndProgressBar(); + updateUnreadIndicator(index); setThumbToIndex(index); }