fix: urls used when recent/unread/popular/top is used as the homepage

if recent is used as the homepage then changing the selected category or filters was redirecting the user to forum.com/recent?cid=1 instead of staying at forum.com/?cid=1

also fix unread page mark read button showing the selected category
This commit is contained in:
Barış Soner Uşaklı
2022-01-19 21:48:49 -05:00
parent 1c80adf1ef
commit 2835966518
2 changed files with 29 additions and 20 deletions

View File

@@ -11,6 +11,7 @@ const topics = require('../topics');
const helpers = require('./helpers');
const unreadController = module.exports;
const relative_path = nconf.get('relative_path');
unreadController.get = async function (req, res) {
const { cid } = req.query;
@@ -34,7 +35,16 @@ unreadController.get = async function (req, res) {
query: req.query,
});
data.title = meta.config.homePageTitle || '[[pages:home]]';
const isDisplayedAsHome = !(req.originalUrl.startsWith(`${relative_path}/api/unread`) || req.originalUrl.startsWith(`${relative_path}/unread`));
const baseUrl = isDisplayedAsHome ? '' : 'unread';
if (isDisplayedAsHome) {
data.title = meta.config.homePageTitle || '[[pages:home]]';
} else {
data.title = '[[pages:unread]]';
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);
}
data.pageCount = Math.max(1, Math.ceil(data.topicCount / userSettings.topicsPerPage));
data.pagination = pagination.create(page, data.pageCount, req.query);
helpers.addLinkTags({ url: 'unread', res: req.res, tags: data.pagination.rel });
@@ -45,18 +55,13 @@ unreadController.get = async function (req, res) {
}
data.showSelect = true;
data.showTopicTools = isPrivileged;
data.allCategoriesUrl = `unread${helpers.buildQueryString(req.query, 'cid', '')}`;
data.allCategoriesUrl = `${baseUrl}${helpers.buildQueryString(req.query, 'cid', '')}`;
data.selectedCategory = categoryData.selectedCategory;
data.selectedCids = categoryData.selectedCids;
data.selectCategoryLabel = '[[unread:mark_as_read]]';
data.selectCategoryIcon = 'fa-inbox';
if (req.originalUrl.startsWith(`${nconf.get('relative_path')}/api/unread`) || req.originalUrl.startsWith(`${nconf.get('relative_path')}/unread`)) {
data.title = '[[pages:unread]]';
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[unread:title]]' }]);
}
data.filters = helpers.buildFilters('unread', filter, req.query);
data.showCategorySelectLabel = true;
data.filters = helpers.buildFilters(baseUrl, filter, req.query);
data.selectedFilter = data.filters.find(filter => filter && filter.selected);
res.render('unread', data);