feat: closes #11139, move sort settings to user settings page

don't change user settings when user changes sort inside topic/category
isekai-main
Barış Soner Uşaklı 2 years ago
parent 44c2d402a9
commit 77ddfc642e

@ -100,10 +100,10 @@
"nodebb-plugin-ntfy": "1.0.15", "nodebb-plugin-ntfy": "1.0.15",
"nodebb-plugin-spam-be-gone": "2.0.6", "nodebb-plugin-spam-be-gone": "2.0.6",
"nodebb-rewards-essentials": "0.2.2", "nodebb-rewards-essentials": "0.2.2",
"nodebb-theme-harmony": "1.0.0-beta.78", "nodebb-theme-harmony": "1.0.0-beta.79",
"nodebb-theme-lavender": "7.0.9", "nodebb-theme-lavender": "7.0.9",
"nodebb-theme-peace": "2.0.19", "nodebb-theme-peace": "2.0.19",
"nodebb-theme-persona": "13.0.50", "nodebb-theme-persona": "13.0.51",
"nodebb-widget-essentials": "7.0.6", "nodebb-widget-essentials": "7.0.6",
"nodemailer": "6.9.1", "nodemailer": "6.9.1",
"nprogress": "0.2.0", "nprogress": "0.2.0",

@ -126,6 +126,8 @@
"paginate_description" : "Paginate topics and posts instead of using infinite scroll", "paginate_description" : "Paginate topics and posts instead of using infinite scroll",
"topics_per_page": "Topics per Page", "topics_per_page": "Topics per Page",
"posts_per_page": "Posts per Page", "posts_per_page": "Posts per Page",
"category-topic-sort": "Category topic sort",
"topic-post-sort": "Topic post sort",
"max_items_per_page": "Maximum %1", "max_items_per_page": "Maximum %1",
"acp_language": "Admin Page Language", "acp_language": "Admin Page Language",
"notifications": "Notifications", "notifications": "Notifications",

@ -1,36 +1,24 @@
'use strict'; 'use strict';
define('sort', ['components', 'api'], function (components, api) { define('sort', ['components'], function (components) {
const module = {}; const module = {};
module.handleSort = function (field, gotoOnSave) { module.handleSort = function (field, gotoOnSave) {
const threadSort = components.get('thread/sort'); const threadSort = components.get('thread/sort');
threadSort.find('i').removeClass('fa-check'); threadSort.find('i').removeClass('fa-check');
const currentSetting = threadSort.find('a[data-sort="' + config[field] + '"]'); const currentSort = utils.params().sort || config[field];
const currentSetting = threadSort.find('a[data-sort="' + currentSort + '"]');
currentSetting.find('i').addClass('fa-check'); currentSetting.find('i').addClass('fa-check');
$('body') $('body')
.off('click', '[component="thread/sort"] a') .off('click', '[component="thread/sort"] a')
.on('click', '[component="thread/sort"] a', function () { .on('click', '[component="thread/sort"] a', function () {
function refresh(newSetting, params) {
config[field] = newSetting;
const qs = decodeURIComponent($.param(params));
ajaxify.go(gotoOnSave + (qs ? '?' + qs : ''));
}
const newSetting = $(this).attr('data-sort'); const newSetting = $(this).attr('data-sort');
if (app.user.uid) { const urlParams = utils.params();
const payload = { settings: {} }; urlParams.sort = newSetting;
payload.settings[field] = newSetting; const qs = decodeURIComponent($.param(urlParams));
api.put(`/users/${app.user.uid}/settings`, payload).then(() => { ajaxify.go(gotoOnSave + (qs ? '?' + qs : ''));
// Yes, this is normal. If you are logged in, sort is not added to qs since it's saved to user settings
refresh(newSetting, utils.params());
});
} else {
const urlParams = utils.params();
urlParams.sort = newSetting;
refresh(newSetting, urlParams);
}
}); });
}; };

Loading…
Cancel
Save