Merge pull request 'Add setting for preferred default comment sorting' (#319) from redmt/teddit:default_comment_sorting into main
Reviewed-on: https://codeberg.org/teddit/teddit/pulls/319
This commit is contained in:
commit
4663b3a78d
|
@ -18,12 +18,14 @@ function resetPreferences(res) {
|
||||||
res.clearCookie('videos_muted');
|
res.clearCookie('videos_muted');
|
||||||
res.clearCookie('prefer_frontpage');
|
res.clearCookie('prefer_frontpage');
|
||||||
res.clearCookie('show_large_gallery_images');
|
res.clearCookie('show_large_gallery_images');
|
||||||
|
res.clearCookie('default_comment_sort');
|
||||||
}
|
}
|
||||||
|
|
||||||
preferenceRoutes.get('/preferences', (req, res, next) => {
|
preferenceRoutes.get('/preferences', (req, res, next) => {
|
||||||
return res.render('preferences', {
|
return res.render('preferences', {
|
||||||
user_preferences: req.cookies,
|
user_preferences: req.cookies,
|
||||||
instance_config: config,
|
instance_config: config,
|
||||||
|
comment_sort_values: ['best', 'top', 'new', 'controversial', 'old', 'qa'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -93,6 +95,7 @@ preferenceRoutes.post('/saveprefs', (req, res, next) => {
|
||||||
let videos_muted = req.body.videos_muted;
|
let videos_muted = req.body.videos_muted;
|
||||||
let prefer_frontpage = req.body.prefer_frontpage;
|
let prefer_frontpage = req.body.prefer_frontpage;
|
||||||
let show_large_gallery_images = req.body.show_large_gallery_images;
|
let show_large_gallery_images = req.body.show_large_gallery_images;
|
||||||
|
let default_comment_sort = req.body.default_comment_sort;
|
||||||
|
|
||||||
res.cookie('theme', theme, {
|
res.cookie('theme', theme, {
|
||||||
maxAge: 365 * 24 * 60 * 60 * 1000,
|
maxAge: 365 * 24 * 60 * 60 * 1000,
|
||||||
|
@ -182,6 +185,11 @@ preferenceRoutes.post('/saveprefs', (req, res, next) => {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
res.cookie('default_comment_sort', default_comment_sort, {
|
||||||
|
maxAge: 365 * 24 * 60 * 60 * 1000,
|
||||||
|
httpOnly: true,
|
||||||
|
});
|
||||||
|
|
||||||
return res.redirect('/preferences');
|
return res.redirect('/preferences');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -600,7 +600,7 @@ subredditRoutes.get(
|
||||||
let subreddit = req.params.subreddit;
|
let subreddit = req.params.subreddit;
|
||||||
let id = req.params.id;
|
let id = req.params.id;
|
||||||
let snippet = encodeURIComponent(req.params.snippet);
|
let snippet = encodeURIComponent(req.params.snippet);
|
||||||
let sortby = req.query.sort;
|
let sortby = req.query.sort || req.cookies.default_comment_sort;
|
||||||
let comment_id = '';
|
let comment_id = '';
|
||||||
let viewing_comment = false;
|
let viewing_comment = false;
|
||||||
let comment_ids = req.query.comment_ids;
|
let comment_ids = req.query.comment_ids;
|
||||||
|
|
|
@ -111,6 +111,17 @@ html
|
||||||
input(type="checkbox", name="prefer_frontpage", id="prefer_frontpage", checked="checked")
|
input(type="checkbox", name="prefer_frontpage", id="prefer_frontpage", checked="checked")
|
||||||
else
|
else
|
||||||
input(type="checkbox", name="prefer_frontpage", id="prefer_frontpage")
|
input(type="checkbox", name="prefer_frontpage", id="prefer_frontpage")
|
||||||
|
.setting
|
||||||
|
label(for="default_comment_sort") Default comment sorting:
|
||||||
|
select(id="default_comment_sort", name="default_comment_sort")
|
||||||
|
-
|
||||||
|
let default_comment_sort_html = ''
|
||||||
|
let user_default_sort = user_preferences.default_comment_sort || 'best'
|
||||||
|
|
||||||
|
for(let key of comment_sort_values) {
|
||||||
|
default_comment_sort_html += `<option value="${key}" ${(user_default_sort == key ? "selected" : "")}>${key == 'qa' ? 'Q&A' : key}</option>`
|
||||||
|
}
|
||||||
|
!= default_comment_sort_html
|
||||||
legend Media
|
legend Media
|
||||||
.setting
|
.setting
|
||||||
label(for="videos_muted") Mute videos by default:
|
label(for="videos_muted") Mute videos by default:
|
||||||
|
|
Loading…
Reference in New Issue