refactor: more cid parseInt changes

This commit is contained in:
Barış Soner Uşaklı
2026-03-01 12:55:00 -05:00
parent a1b77fa033
commit 1b518f0eb2
7 changed files with 30 additions and 23 deletions

View File

@@ -97,7 +97,7 @@
"multer": "2.0.2",
"nconf": "0.13.0",
"nodebb-plugin-2factor": "7.6.1",
"nodebb-plugin-composer-default": "10.3.22",
"nodebb-plugin-composer-default": "10.3.23",
"nodebb-plugin-dbsearch": "6.4.0",
"nodebb-plugin-emoji": "6.0.5",
"nodebb-plugin-emoji-android": "4.1.1",

View File

@@ -11,7 +11,7 @@ define('admin/manage/categories', [
], function (translator, Benchpress, categorySelector, api, Sortable, bootbox, alerts) {
Sortable = Sortable.default;
const Categories = {};
let newCategoryId = -1;
let newCategoryId = '-1';
let sortables;
Categories.init = function () {
@@ -261,15 +261,15 @@ define('admin/manage/categories', [
};
function itemDidAdd(e) {
newCategoryId = e.to.dataset.cid;
newCategoryId = String(e.to.dataset.cid);
}
function itemDragDidEnd(e) {
const isCategoryUpdate = parseInt(newCategoryId, 10) !== -1;
const isCategoryUpdate = String(newCategoryId) !== '-1';
// Update needed?
if ((e.newIndex != null && parseInt(e.oldIndex, 10) !== parseInt(e.newIndex, 10)) || isCategoryUpdate) {
const cid = e.item.dataset.cid;
const cid = String(e.item.dataset.cid);
const modified = {};
// on page 1 baseIndex is 0, on page n baseIndex is (n - 1) * ajaxify.data.categoriesPerPage
// this makes sure order is correct when drag & drop is used on pages > 1
@@ -282,8 +282,8 @@ define('admin/manage/categories', [
modified[cid].parentCid = newCategoryId;
// Show/hide expand buttons after drag completion
const oldParentCid = parseInt(e.from.getAttribute('data-cid'), 10);
const newParentCid = parseInt(e.to.getAttribute('data-cid'), 10);
const oldParentCid = String(e.from.getAttribute('data-cid') || '');
const newParentCid = String(e.to.getAttribute('data-cid') || '');
if (oldParentCid !== newParentCid) {
const toggle = document.querySelector(`.categories li[data-cid="${newParentCid}"] .toggle`);
if (toggle) {

View File

@@ -160,7 +160,7 @@ define('admin/manage/category', [
label: '[[modules:bootbox.confirm]]',
className: 'btn-primary',
callback: function () {
if (!selectedCid || parseInt(selectedCid, 10) === parseInt(ajaxify.data.category.cid, 10)) {
if (!selectedCid || String(selectedCid) === String(ajaxify.data.category.cid)) {
return;
}

View File

@@ -68,10 +68,14 @@ define('admin/manage/group', [
const cidSelector = categorySelector.init($('.member-post-cids-selector [component="category-selector"]'), {
onSelect: function (selectedCategory) {
let cids = ($('#memberPostCids').val() || '').split(',').map(cid => parseInt(cid, 10));
cids.push(selectedCategory.cid);
cids = cids.filter((cid, index, array) => array.indexOf(cid) === index);
$('#memberPostCids').val(cids.join(','));
const cids = new Set(($('#memberPostCids').val() || '').split(',').filter(Boolean));
if (cids.has(String(selectedCategory.cid))) {
cids.delete(String(selectedCategory.cid));
} else {
cids.add(String(selectedCategory.cid));
}
$('#memberPostCids').val(Array.from(cids).join(','));
cidSelector.selectCategory(0);
return false;
},

View File

@@ -233,11 +233,16 @@ define('forum/groups/details', [
const cidSelector = categorySelector.init($('.member-post-cids-selector [component="category-selector"]'), {
onSelect: function (selectedCategory) {
let cids = ($('#memberPostCids').val() || '').split(',').map(cid => parseInt(cid, 10));
cids.push(selectedCategory.cid);
cids = cids.filter((cid, index, array) => array.indexOf(cid) === index);
$('#memberPostCids').val(cids.join(','));
const cids = new Set(($('#memberPostCids').val() || '').split(',').filter(Boolean));
if (cids.has(String(selectedCategory.cid))) {
cids.delete(String(selectedCategory.cid));
} else {
cids.add(String(selectedCategory.cid));
}
$('#memberPostCids').val(Array.from(cids).join(','));
cidSelector.selectCategory(0);
return false;
},
});
};

View File

@@ -65,9 +65,7 @@ define('forum/unread', [
// Generate list of default categories based on topic list
let defaultCategories = ajaxify.data.topics.reduce((map, topic) => {
const { category } = topic;
let { cid } = category;
cid = utils.isNumber(cid) ? parseInt(cid, 10) : cid;
map.set(cid, category);
map.set(String(category.cid), category);
return map;
}, new Map());
defaultCategories = Array.from(defaultCategories.values());

View File

@@ -95,11 +95,11 @@ define('topicList', [
const categories = d.selectedCids &&
d.selectedCids.length &&
d.selectedCids.indexOf(parseInt(data.cid, 10)) === -1;
!d.selectedCids.includes(parseInt(data.cid, 10));
const filterWatched = d.selectedFilter &&
d.selectedFilter.filter === 'watched';
const category = d.template.category &&
parseInt(d.cid, 10) !== parseInt(data.cid, 10);
String(d.cid) !== String(data.cid);
const preventAlert = !!(categories || filterWatched || category || scheduledTopics.includes(data.tid));
hooks.fire('filter:topicList.onNewTopic', { topic: data, preventAlert }).then((result) => {
@@ -126,14 +126,14 @@ define('topicList', [
const isMain = parseInt(post.topic.mainPid, 10) === parseInt(post.pid, 10);
const categories = d.selectedCids &&
d.selectedCids.length &&
d.selectedCids.indexOf(parseInt(post.topic.cid, 10)) === -1;
!d.selectedCids.includes(parseInt(post.topic.cid, 10));
const filterNew = d.selectedFilter &&
d.selectedFilter.filter === 'new';
const filterWatched = d.selectedFilter &&
d.selectedFilter.filter === 'watched' &&
!post.topic.isFollowing;
const category = d.template.category &&
parseInt(d.cid, 10) !== parseInt(post.topic.cid, 10);
String(d.cid) !== String(post.topic.cid);
const preventAlert = !!(isMain || categories || filterNew || filterWatched || category);
hooks.fire('filter:topicList.onNewPost', { post, preventAlert }).then((result) => {