From b0e1095fe6a9c201acebcf7089f67b462da0f50e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 26 Mar 2021 10:32:42 -0700 Subject: [PATCH] Adds "suggested follows" panel --- bookwyrm/static/css/format.css | 5 ++++ bookwyrm/templates/feed/feed.html | 27 +++++++++++++++++++ .../templates/snippets/follow_button.html | 10 +++---- bookwyrm/views/feed.py | 18 ++++++++++++- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index 6a1167b2..c640cd27 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -15,6 +15,11 @@ html { overflow: visible; } +.scroll-x { + overflow: hidden; + overflow-x: auto; +} + /* --- SHELVING --- */ .shelf-option:disabled > *::after { font-family: "icomoon"; diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index bc35d3b9..24131051 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -1,6 +1,7 @@ {% extends 'feed/feed_layout.html' %} {% load i18n %} {% load bookwyrm_tags %} +{% load humanize %} {% block panel %}

@@ -48,6 +49,32 @@ {% endif %} {% for activity in activities %} + +{% if not activities.number > 1 and forloop.counter0 == 2 and suggested_users %} +{# suggested users on the first page, two statuses down #} +
+

{% trans "Who to follow" %}

+
+ {% for user in suggested_users %} +
+
+ + {% include 'snippets/avatar.html' with user=user large=True %} + {{ user.display_name|truncatechars:10 }} + @{{ user|username|truncatechars:8 }} + + {% include 'snippets/follow_button.html' with user=user minimal=True %} + {% if user.mutuals %} +

+ {% blocktrans with mutuals=user.mutuals|intcomma count counter=user.mutuals %}{{ mutuals }} follower you follow{% plural %}{{ mutuals }} followers you follow{% endblocktrans %} +

+ {% endif %} +
+
+ {% endfor %} +
+
+{% endif %}
{% include 'snippets/status/status.html' with status=activity %}
diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html index 3df85a1a..962d4d34 100644 --- a/bookwyrm/templates/snippets/follow_button.html +++ b/bookwyrm/templates/snippets/follow_button.html @@ -4,16 +4,12 @@ {% include 'snippets/block_button.html' %} {% else %} -
+
+ {% if not minimal %}
{% include 'snippets/user_options.html' with user=user class="is-small" %}
+ {% endif %}
{% endif %} diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index e0de932d..21a14d8e 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -1,7 +1,7 @@ """ non-interactive pages """ from django.contrib.auth.decorators import login_required from django.core.paginator import Paginator -from django.db.models import Q +from django.db.models import Count, Q from django.http import HttpResponseNotFound from django.template.response import TemplateResponse from django.utils import timezone @@ -34,11 +34,27 @@ class Feed(View): paginated = Paginator(activities, PAGE_LENGTH) + suggested_users = models.User.objects.filter( + ~Q(id__in=request.user.following.all()), + ~Q(id=request.user.id), + discoverable=True, + is_active=True, + bookwyrm_user=True, + ).annotate( + mutuals=Count( + "following", + filter=Q( + following__in=request.user.following.all() + ), + ) + ).order_by("-mutuals", "-last_active_date").all()[:5] + data = { **feed_page_data(request.user), **{ "user": request.user, "activities": paginated.page(page), + "suggested_users": suggested_users, "tab": tab, "goal_form": forms.GoalForm(), "path": "/%s" % tab,