From f53bb62b2b73382efa9b201ce6caad26ca89cac0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 23 Aug 2024 16:52:38 -0700 Subject: [PATCH 1/4] Allow users to hide ratings in the UI --- bookwyrm/models/user.py | 2 +- bookwyrm/static/js/bookwyrm.js | 17 +++++++++++++++++ bookwyrm/templates/snippets/stars.html | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 80f1c2d9a..93465720e 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -141,7 +141,6 @@ class User(OrderedCollectionPageMixin, AbstractUser): hide_follows = fields.BooleanField(default=False) # migration fields - moved_to = fields.RemoteIdField( null=True, unique=False, activitypub_field="movedTo", deduplication_field=False ) @@ -158,6 +157,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): show_suggested_users = models.BooleanField(default=True) discoverable = fields.BooleanField(default=False) show_guided_tour = models.BooleanField(default=True) + show_ratings = models.BooleanField(default=True) # feed options feed_status_types = DjangoArrayField( diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index a2351a98c..48f84e5e9 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -14,6 +14,10 @@ let BookWyrm = new (class { .querySelectorAll("[data-controls]") .forEach((button) => button.addEventListener("click", this.toggleAction.bind(this))); + document + .querySelectorAll("[data-disappear]") + .forEach((button) => button.addEventListener("click", this.hideSelf.bind(this))); + document .querySelectorAll(".interaction") .forEach((button) => button.addEventListener("submit", this.interact.bind(this))); @@ -181,6 +185,19 @@ let BookWyrm = new (class { this.addRemoveClass(visible, "is-hidden", true); } + /** + * Hide the element you just clicked + * + * @param {Event} event + * @return {undefined} + */ + hideSelf(event) { + let trigger = event.currentTarget; + this.addRemoveClass(trigger, "is-hidden", true) + } + + + /** * Execute actions on targets based on triggers. * diff --git a/bookwyrm/templates/snippets/stars.html b/bookwyrm/templates/snippets/stars.html index 991110151..fe347e8b3 100644 --- a/bookwyrm/templates/snippets/stars.html +++ b/bookwyrm/templates/snippets/stars.html @@ -1,8 +1,19 @@ {% spaceless %} +{% load utilities %} {% load i18n %} - +{% with 0|uuid as uuid %} + + {% if not request.user.show_ratings %} + + + + {% endif %} + {% if rating %} + {% blocktranslate trimmed with rating=rating|floatformat:0 count counter=rating|floatformat:0|add:0 %} {{ rating }} star @@ -19,8 +30,11 @@ aria-hidden="true" > {% endfor %} + {% else %} {% trans "No rating" %} {% endif %} + +{% endwith %} {% endspaceless %} From 612098475a688cb49451b0bc8d4b6487171a5abd Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 23 Aug 2024 17:34:52 -0700 Subject: [PATCH 2/4] Adds option to show ratings to the user settings panel --- bookwyrm/forms/edit_user.py | 1 + bookwyrm/templates/preferences/edit_user.html | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/bookwyrm/forms/edit_user.py b/bookwyrm/forms/edit_user.py index 9024972c3..13ac285d8 100644 --- a/bookwyrm/forms/edit_user.py +++ b/bookwyrm/forms/edit_user.py @@ -18,6 +18,7 @@ class EditUserForm(CustomForm): "email", "summary", "show_goal", + "show_ratings", "show_suggested_users", "manually_approves_followers", "default_post_privacy", diff --git a/bookwyrm/templates/preferences/edit_user.html b/bookwyrm/templates/preferences/edit_user.html index f2b14babf..c10bc1ee4 100644 --- a/bookwyrm/templates/preferences/edit_user.html +++ b/bookwyrm/templates/preferences/edit_user.html @@ -69,6 +69,12 @@ {% trans "Show reading goal prompt in feed" %} +
+ +