Skip to content

Node.js based forum software built for the modern web

fix(post-queue): correct category update logic and template regression

Julian Lam6b203c0f84fd
diff --git a/public/src/client/post-queue.js b/public/src/client/post-queue.js
index 0d67ac9964..d8920d2dfb 100644
--- a/public/src/client/post-queue.js
+++ b/public/src/client/post-queue.js
@@ -168,64 +168,47 @@ define('forum/post-queue', [
});
}
- function handleCrosspostCidChange(postEl) {
+ function handleCategoryChange(categoryEl, { apiParam = 'cid', isCrosspost } = {}) {
+ const postEl = categoryEl.closest('[data-id]');
const id = postEl.getAttribute('data-id');
- const crosspostSection = postEl.querySelector('[data-crosspost]');
+ const crosspostSection = isCrosspost ? postEl.querySelector('[data-crosspost]') : null;
categorySelector.modal({
localOnly: true,
+ openOnLoad: true,
onSubmit: function (selectedCategory) {
Promise.all([
api.get(`/categories/${selectedCategory.cid}`, {}),
api.put(`/posts/queue/${id}`, {
- crosspostCid: selectedCategory.cid,
+ [apiParam]: selectedCategory.cid,
}),
]).then(function (result) {
const category = result[0];
+ const postData = {};
+ if (isCrosspost) {
+ postData.crosspostCategory = category;
+ postData.type = 'crosspost';
+ } else {
+ postData.category = category;
+ }
app.parseAndTranslate('post-queue', 'posts', {
- posts: [{
- type: 'crosspost',
- crosspostCategory: category,
- crosspostCid: category.cid,
- }],
+ posts: [postData],
}, function (html) {
if (crosspostSection) {
- crosspostSection.innerHTML = html.find('[data-crosspost]').html();
- }
- });
- }).catch(alerts.error);
- },
- });
- }
-
- function handleCategoryChange(categoryEl) {
- const $this = $(categoryEl);
- const id = $this.parents('[data-id]').attr('data-id');
- categorySelector.modal({
- onSubmit: function (selectedCategory) {
- Promise.all([
- api.get(`/categories/${selectedCategory.cid}`, {}),
- api.put(`/posts/queue/${id}`, {
- cid: selectedCategory.cid,
- }),
- ]).then(function (result) {
- const category = result[0];
- app.parseAndTranslate('post-queue', 'posts', {
- posts: [{
- category: category,
- }],
- }, function (html) {
- if ($this.find('.category-text').length) {
- $this.find('.category-text').text(html.find('.topic-category .category-text').text());
+ const newCrosspost = html.find('[data-crosspost]')[0];
+ if (newCrosspost) {
+ crosspostSection.outerHTML = newCrosspost.outerHTML;
+ }
} else {
- // for backwards compatibility, remove in 1.16.0
- $this.replaceWith(html.find('.topic-category'));
+ const newCategory = html.find('.topic-category')[0];
+ if (newCategory) {
+ categoryEl.replaceWith(newCategory);
+ }
}
});
}).catch(alerts.error);
},
});
- return false;
}
function handleTagChange(postEl) {
@@ -287,12 +270,12 @@ define('forum/post-queue', [
break;
case 'editCategory': {
const postEl = e.target.closest('[data-id]');
- if (e.target.closest('[data-crosspost]')) {
- handleCrosspostCidChange(postEl);
- } else {
- const categoryEl = postEl.querySelector('.topic-category');
- handleCategoryChange(categoryEl);
- }
+ const isCrosspost = e.target.closest('[data-crosspost]');
+ const categoryEl = isCrosspost ?
+ postEl.querySelector('[data-crosspost] .topic-category') :
+ postEl.querySelector('.topic-category');
+ const apiParam = isCrosspost ? 'crosspostCid' : 'cid';
+ handleCategoryChange(categoryEl, { apiParam, isCrosspost: !!isCrosspost });
break;
}
diff --git a/src/views/post-queue.tpl b/src/views/post-queue.tpl
index cec043368d..502a70117a 100644
--- a/src/views/post-queue.tpl
+++ b/src/views/post-queue.tpl
@@ -173,11 +173,11 @@
{{{ end }}}
</div>
- <div class="topic-category">
+ <div class="topic-category" data-cid="{posts.category.cid}">
<a href="{config.relative_path}/category/{posts.category.slug}">
<div class="category-item d-inline-block">
{{buildCategoryIcon(./category, "24px", "rounded-circle")}}
- <span class="text-sm">{posts.category.name}</span>
+ <span class="text-sm category-text">{posts.category.name}</span>
</div>
</a>
</div>
@@ -192,11 +192,11 @@
<button data-action="editCategory" class="btn btn-ghost btn-sm ff-secondary border text-xs">{{tx("post-queue:edit")}}</button>
</div>
- <div class="topic-category">
+ <div class="topic-category" data-cid="{posts.crosspostCategory.cid}">
<a href="{config.relative_path}/category/{posts.crosspostCategory.slug}">
<div class="category-item d-inline-block">
{{buildCategoryIcon(./crosspostCategory, "24px", "rounded-circle")}}
- <span class="text-sm">{posts.crosspostCategory.name}</span>
+ <span class="text-sm category-text">{posts.crosspostCategory.name}</span>
</div>
</a>
</div>