From 9af2335134190cba2c888eb07a0fafbad93e807a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 8 Dec 2021 09:41:48 -0500 Subject: [PATCH] fix: #10068, baseIndex should be read before sort update fix off by one error --- public/src/client/category/tools.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/src/client/category/tools.js b/public/src/client/category/tools.js index 2b45b72377..eba385206f 100644 --- a/public/src/client/category/tools.js +++ b/public/src/client/category/tools.js @@ -284,14 +284,17 @@ define('forum/category/tools', [ const topicListEl = $('[component="category"]').filter(function (i, e) { return !$(e).parents('[widget-area],[data-widget-area]').length; }); + let baseIndex = 0; topicListEl.sortable({ handle: '[component="topic/pinned"]', items: '[component="category/topic"].pinned', + start: function () { + baseIndex = parseInt(topicListEl.find('[component="category/topic"].pinned').first().attr('data-index'), 10); + }, update: function (ev, ui) { - const baseIndex = parseInt(topicListEl.find('[component="category/topic"].pinned').first().attr('data-index'), 10); socket.emit('topics.orderPinnedTopics', { tid: ui.item.attr('data-tid'), - order: baseIndex + ui.item.index() - 1, + order: baseIndex + ui.item.index(), }, function (err) { if (err) { return alerts.error(err);