From 248fe64537b7b4d7078f45b95d5d0e02fa9c42ca Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 19 Feb 2020 18:02:11 -0800 Subject: [PATCH] Adds home/local/federated feeds to home Fixes #38 --- fedireads/static/format.css | 10 ++++++- fedireads/templates/feed.html | 54 ++++++----------------------------- fedireads/urls.py | 3 +- fedireads/views.py | 28 +++++++++++++++--- 4 files changed, 43 insertions(+), 52 deletions(-) diff --git a/fedireads/static/format.css b/fedireads/static/format.css index 6c82633c25..31979b8607 100644 --- a/fedireads/static/format.css +++ b/fedireads/static/format.css @@ -7,7 +7,7 @@ } html { - background-color:#EFEFEF; + background-color: #FFF; color: black; } @@ -76,6 +76,14 @@ h2 { margin-right: 0; } +#feed-tabs { + display: flex; + flex-direction: row; +} +.active { + background-color: #FF1654; +} + .user-pic { width: 2rem; height: auto; diff --git a/fedireads/templates/feed.html b/fedireads/templates/feed.html index 3f60890085..d0eb30ebaa 100644 --- a/fedireads/templates/feed.html +++ b/fedireads/templates/feed.html @@ -49,54 +49,16 @@

Recently Added Books

+
+ {% for tab in feed_tabs %} +
+ {{ tab }} +
+ {% endfor %} +
{% for activity in activities %} -
-

- {% include 'snippets/avatar.html' with user=activity.user %} - {% include 'snippets/username.html' with user=activity.user %} - {% if activity.status_type == 'Review' %} - {# display a review #} - reviewed {{ activity.book.data.title }} -

-
- {% include 'snippets/book.html' with book=activity.book size=large %} - -

{{ activity.name }}

-

{{ activity.rating | stars }}

-

{{ activity.content | safe }}

-
-
- {% if activity.favorites.all %} - - {{ activity.favorites.count }} like(s) - - {% endif %} -
- {% csrf_token %} - -
-
- {% csrf_token %} - - {{ comment_form.content }} - -
-
- {% elif activity.status_type == 'Note' %} - posted - {{ activity.content | safe }} - {% for book in activity.mention_books.all %} -
- {% include 'snippets/book.html' with book=book size=large description=True %} -
- {% endfor %} - {% else %} - {# generic handling for a misc activity, which perhaps should not be displayed at all #} - did {{ activity.activity_type }} - - {% endif %} -
+ {% include 'snippets/status.html' with activity=activity %} {% endfor %}
{% endblock %} diff --git a/fedireads/urls.py b/fedireads/urls.py index 349bca0d34..a2bbaf8f29 100644 --- a/fedireads/urls.py +++ b/fedireads/urls.py @@ -38,7 +38,8 @@ # TODO: re_path(r'^.well-known/host-meta/?$', incoming.host_meta), # ui views - path(r'', views.home), + path('', views.home), + re_path(r'^(?Phome|local|federated)/?$', views.home_tab), re_path(r'^register/?$', views.register), re_path(r'^login/?$', views.user_login), re_path(r'^logout/?$', views.user_logout), diff --git a/fedireads/views.py b/fedireads/views.py index 15d59de577..e8af812e5e 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -13,6 +13,12 @@ @login_required def home(request): + ''' this is the same as the feed on the home tab ''' + return home_tab(request, 'home') + + +@login_required +def home_tab(request, tab): ''' user's homepage with activity feed ''' # user's shelves for display reading = models.Shelf.objects.get( @@ -37,11 +43,23 @@ def home(request): Q(followers=request.user) | Q(id=request.user.id) ) - activities = models.Status.objects.filter( - Q(user__in=following, privacy='public') | Q(mention_users=request.user) - ).select_subclasses().order_by( + activities = models.Status.objects.select_subclasses().order_by( '-created_date' - )[:10] + ) + + if tab == 'home': + # people you follow and direct mentions + activities = activities.filter( + Q(user__in=following, privacy='public') | Q(mention_users=request.user) + ) + elif tab == 'local': + # everyone on this instance + activities = activities.filter(user__local=True, privacy='public') + else: + # all activities from everyone you federate with + activities = activities.filter(privacy='public') + + activities = activities[:10] comment_form = forms.CommentForm() data = { @@ -51,6 +69,8 @@ def home(request): 'recent_books': recent_books, 'user_books': user_books, 'activities': activities, + 'feed_tabs': ['home', 'local', 'federated'], + 'active_tab': tab, 'comment_form': comment_form, } return TemplateResponse(request, 'feed.html', data)