fix: closes #11731, set postIndex on pagination

isekai-main
Barış Soner Uşaklı 2 years ago
parent 777c7d0975
commit cbd98c1b28

@ -303,11 +303,11 @@ ajaxify.widgets = { render: render };
window.scrollTo(0, 0);
// if on topic page, scroll to the correct post,
// this is here to avoid a flash of the wrong posts at the top of the page
if (ajaxify.data.template.topic && ajaxify.data.postIndex > 1) {
require(['navigator'], function (navigator) {
require(['navigator'], function (navigator) {
if (navigator.shouldScrollToPost(ajaxify.data.postIndex)) {
navigator.scrollToPostIndex(ajaxify.data.postIndex - 1, true, 0);
});
}
}
});
}
ajaxify.loadScript(tpl_url, function done() {
hooks.fire('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });

@ -151,10 +151,8 @@ define('forum/topic', [
const bookmark = ajaxify.data.bookmark || storage.getItem('topic:' + tid + ':bookmark');
const postIndex = ajaxify.data.postIndex;
updateUserBookmark(postIndex);
if (postIndex > 1) {
if (components.get('post/anchor', postIndex - 1).length) {
return navigator.scrollToPostIndex(postIndex - 1, true, 0);
}
if (navigator.shouldScrollToPost(postIndex)) {
return navigator.scrollToPostIndex(postIndex - 1, true, 0);
} else if (bookmark && (
!config.usePagination ||
(config.usePagination && ajaxify.data.pagination.currentPage === 1)

@ -642,6 +642,14 @@ define('navigator', [
}
};
navigator.shouldScrollToPost = function (postIndex) {
if (!ajaxify.data.template.topic || postIndex <= 1) {
return false;
}
const firstPostEl = $('[component="topic"] [component="post"]').first();
return parseInt(firstPostEl.attr('data-index'), 10) !== postIndex - 1;
};
navigator.scrollToPostIndex = function (postIndex, highlight, duration) {
const scrollTo = components.get('post', 'index', postIndex);
navigator.scrollToElement(scrollTo, highlight, duration, postIndex);

@ -72,8 +72,12 @@ topicsController.get = async function getTopic(req, res, next) {
const sort = req.query.sort || settings.topicPostSort;
const set = sort === 'most_votes' ? `tid:${tid}:posts:votes` : `tid:${tid}:posts`;
const reverse = sort === 'newest_to_oldest' || sort === 'most_votes';
if (settings.usePagination && !req.query.page) {
currentPage = calculatePageFromIndex(postIndex, settings);
if (settings.usePagination) {
if (!req.query.page) {
currentPage = calculatePageFromIndex(postIndex, settings);
} else {
postIndex = ((currentPage - 1) * settings.postsPerPage) + 1;
}
}
const { start, stop } = calculateStartStop(currentPage, postIndex, settings);

Loading…
Cancel
Save