Skip to content

Node.js based forum software built for the modern web

fix: #10068, baseIndex should be read before sort update fix off by one error

Barış Soner Uşaklı9af233513419
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);