From b9632039f9ada9006b4b125c56bdb4adf57222d2 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 2 Oct 2021 11:24:07 -0700 Subject: [PATCH] Link notification block to its main path --- bookwyrm/static/js/block_href.js | 22 +++++++++++++++++++ .../templates/notifications/items/add.html | 8 +++++++ .../templates/notifications/items/boost.html | 4 ++++ .../templates/notifications/items/fav.html | 4 ++++ .../templates/notifications/items/follow.html | 4 ++++ .../templates/notifications/items/import.html | 5 ++++- .../notifications/items/item_layout.html | 2 +- .../notifications/items/mention.html | 3 +++ .../templates/notifications/items/reply.html | 3 +++ .../templates/notifications/items/report.html | 4 ++++ .../notifications/notifications_page.html | 5 +++++ 11 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 bookwyrm/static/js/block_href.js diff --git a/bookwyrm/static/js/block_href.js b/bookwyrm/static/js/block_href.js new file mode 100644 index 00000000..1de6ca66 --- /dev/null +++ b/bookwyrm/static/js/block_href.js @@ -0,0 +1,22 @@ +/* exported BlockHref */ +/* globals BookWyrm */ + +let BlockHref = new class { + constructor() { + document.querySelectorAll('[data-href]') + .forEach(t => t.addEventListener('click', this.followLink.bind(this))); + } + + /** + * Follow a fake link + * + * @param {Event} event + * @return {undefined} + */ + followLink(event) { + const url = event.currentTarget.dataset.href; + + window.location.href = url; + } +}(); + diff --git a/bookwyrm/templates/notifications/items/add.html b/bookwyrm/templates/notifications/items/add.html index 8e1c46a3..0e653aeb 100644 --- a/bookwyrm/templates/notifications/items/add.html +++ b/bookwyrm/templates/notifications/items/add.html @@ -3,6 +3,14 @@ {% load i18n %} {% load utilities %} +{% block primary_link %}{% spaceless %} +{% if notification.related_list_item.approved %} + {{ notification.related_list_item.book_list.local_path }} +{% else %} + {% url 'list-curate' notification.related_list_item.book_list.id %} +{% endif %} +{% endspaceless %}{% endblock %} + {% block icon %} {% endblock %} diff --git a/bookwyrm/templates/notifications/items/boost.html b/bookwyrm/templates/notifications/items/boost.html index 8ba868f5..5f8962b3 100644 --- a/bookwyrm/templates/notifications/items/boost.html +++ b/bookwyrm/templates/notifications/items/boost.html @@ -3,6 +3,10 @@ {% load i18n %} {% load utilities %} +{% block primary_link %}{% spaceless %} + {{ notification.related_status.local_path }} +{% endspaceless %}{% endblock %} + {% block icon %} {% endblock %} diff --git a/bookwyrm/templates/notifications/items/fav.html b/bookwyrm/templates/notifications/items/fav.html index fb61e59e..d430598e 100644 --- a/bookwyrm/templates/notifications/items/fav.html +++ b/bookwyrm/templates/notifications/items/fav.html @@ -3,6 +3,10 @@ {% load i18n %} {% load utilities %} +{% block primary_link %}{% spaceless %} + {{ notification.related_status.local_path }} +{% endspaceless %}{% endblock %} + {% block icon %} {% endblock %} diff --git a/bookwyrm/templates/notifications/items/follow.html b/bookwyrm/templates/notifications/items/follow.html index d85d2af3..7220d5d1 100644 --- a/bookwyrm/templates/notifications/items/follow.html +++ b/bookwyrm/templates/notifications/items/follow.html @@ -3,6 +3,10 @@ {% load i18n %} {% load utilities %} +{% block primary_link %}{% spaceless %} + {{ notification.related_user.local_path }} +{% endspaceless %}{% endblock %} + {% block icon %} {% endblock %} diff --git a/bookwyrm/templates/notifications/items/import.html b/bookwyrm/templates/notifications/items/import.html index 87dd0998..f3c8b5c0 100644 --- a/bookwyrm/templates/notifications/items/import.html +++ b/bookwyrm/templates/notifications/items/import.html @@ -1,7 +1,10 @@ {% extends 'notifications/items/item_layout.html' %} - {% load i18n %} +{% block primary_link %}{% spaceless %} +{% url 'import-status' notification.related_import.id %} +{% endspaceless %}{% endblock %} + {% block icon %} {% endblock %} diff --git a/bookwyrm/templates/notifications/items/item_layout.html b/bookwyrm/templates/notifications/items/item_layout.html index 19b6d13d..382978d4 100644 --- a/bookwyrm/templates/notifications/items/item_layout.html +++ b/bookwyrm/templates/notifications/items/item_layout.html @@ -1,7 +1,7 @@ {% load humanize %} {% load bookwyrm_tags %} {% related_status notification as related_status %} -
+
{% block icon %}{% endblock %} diff --git a/bookwyrm/templates/notifications/items/mention.html b/bookwyrm/templates/notifications/items/mention.html index 003f4e29..cda77163 100644 --- a/bookwyrm/templates/notifications/items/mention.html +++ b/bookwyrm/templates/notifications/items/mention.html @@ -3,6 +3,9 @@ {% load i18n %} {% load utilities %} +{% block primary_link %}{% spaceless %} + {{ notification.related_status.local_path }} +{% endspaceless %}{% endblock %} {% block icon %} diff --git a/bookwyrm/templates/notifications/items/reply.html b/bookwyrm/templates/notifications/items/reply.html index 125e4dec..883bbbb5 100644 --- a/bookwyrm/templates/notifications/items/reply.html +++ b/bookwyrm/templates/notifications/items/reply.html @@ -3,6 +3,9 @@ {% load i18n %} {% load utilities %} +{% block primary_link %}{% spaceless %} + {{ notification.related_status.local_path }} +{% endspaceless %}{% endblock %} {% block icon %} diff --git a/bookwyrm/templates/notifications/items/report.html b/bookwyrm/templates/notifications/items/report.html index 9e56d352..f537b525 100644 --- a/bookwyrm/templates/notifications/items/report.html +++ b/bookwyrm/templates/notifications/items/report.html @@ -2,6 +2,10 @@ {% load i18n %} +{% block primary_link %}{% spaceless %} + {% url 'settings-report' notification.related_report.id %} +{% endspaceless %}{% endblock %} + {% block icon %} {% endblock %} diff --git a/bookwyrm/templates/notifications/notifications_page.html b/bookwyrm/templates/notifications/notifications_page.html index 8d1cf6ad..dc6acbdb 100644 --- a/bookwyrm/templates/notifications/notifications_page.html +++ b/bookwyrm/templates/notifications/notifications_page.html @@ -1,5 +1,6 @@ {% extends 'layout.html' %} {% load i18n %} +{% load static %} {% block title %}{% trans "Notifications" %}{% endblock %} @@ -45,3 +46,7 @@ {% endif %}
{% endblock %} + +{% block scripts %} + +{% endblock %}