Fix #4930: "Show scores" setting should be preserved

Make "show scores" setting persistent.

The setting is stored in a `post_preview_show_votes` cookie. This means
it's remembered on a per-device basis, but not on a per-account basis.
This is so users without an account can use the setting, and so you can
use different settings on desktop and mobile.

The `view=score` URL param has been replaced by `show_votes=true`. The
`show_votes` URL param overrides the `post_preview_show_votes` cookie.
This commit is contained in:
evazion
2021-12-09 15:40:22 -06:00
parent 3de93f556e
commit 7976d12cd0
6 changed files with 47 additions and 33 deletions

View File

@@ -26,6 +26,7 @@ Post.initialize_all = function() {
this.initialize_excerpt();
this.initialize_gestures();
this.initialize_post_preview_size_menu();
this.initialize_post_preview_options_menu();
}
if ($("#c-posts").length && $("#a-show").length) {
@@ -255,6 +256,20 @@ Post.initialize_post_preview_size_menu = function() {
});
}
Post.initialize_post_preview_options_menu = function() {
$(document).on("click.danbooru", "a.post-preview-show-votes", (e) => {
Cookie.put("post_preview_show_votes", "true");
location.reload();
e.preventDefault();
});
$(document).on("click.danbooru", "a.post-preview-hide-votes", (e) => {
Cookie.put("post_preview_show_votes", "false");
location.reload();
e.preventDefault();
});
}
Post.view_original = function(e = null) {
if (Utility.test_max_width(660)) {
// Do the default behavior (navigate to image)
@@ -424,10 +439,10 @@ Post.update = async function(post_id, mode, params) {
Post.show_pending_update_notice()
let urlParams = new URLSearchParams(window.location.search);
let view = urlParams.get("view");
let show_votes = urlParams.get("show_votes");
let size = urlParams.get("size");
await $.ajax({ type: "PUT", url: `/posts/${post_id}.js`, data: { mode, view, size, ...params }});
await $.ajax({ type: "PUT", url: `/posts/${post_id}.js`, data: { mode, show_votes, size, ...params }});
Post.pending_update_count -= 1;
Post.show_pending_update_notice();