Skip to content

Commit

Permalink
Adds home/local/federated feeds to home
Browse files Browse the repository at this point in the history
Fixes #38
  • Loading branch information
mouse-reeve committed Feb 20, 2020
1 parent 16a39e1 commit 248fe64
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 52 deletions.
10 changes: 9 additions & 1 deletion fedireads/static/format.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

html {
background-color:#EFEFEF;
background-color: #FFF;
color: black;
}

Expand Down Expand Up @@ -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;
Expand Down
54 changes: 8 additions & 46 deletions fedireads/templates/feed.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,54 +49,16 @@ <h2>Recently Added Books</h2>
</div>

<div id="feed">
<div id="feed-tabs">
{% for tab in feed_tabs %}
<div class="{% if tab == active_tab %}active{% endif %}">
<a href="/{{ tab }}">{{ tab }}</a>
</div>
{% endfor %}
</div>

{% for activity in activities %}
<div class="update">
<h2>
{% 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 }}
</h2>
<div class="book-preview review">
{% include 'snippets/book.html' with book=activity.book size=large %}

<h3>{{ activity.name }}</h3>
<p>{{ activity.rating | stars }}</p>
<p>{{ activity.content | safe }}</p>
</div>
<div class="interaction">
{% if activity.favorites.all %}
<span>
{{ activity.favorites.count }} like(s)
</span>
{% endif %}
<form name="favorite" action="/favorite/{{ activity.id }}" method="post">
{% csrf_token %}
<button>⭐️ Like</button>
</form>
<form name="comment" action="/comment" method="post">
{% csrf_token %}
<input type="hidden" name="review" value="{{ activity.id }}"></input>
{{ comment_form.content }}
<button type="submit">Comment</button>
</form>
</div>
{% elif activity.status_type == 'Note' %}
posted</h2>
{{ activity.content | safe }}
{% for book in activity.mention_books.all %}
<div class="book-preview review">
{% include 'snippets/book.html' with book=book size=large description=True %}
</div>
{% endfor %}
{% else %}
{# generic handling for a misc activity, which perhaps should not be displayed at all #}
did {{ activity.activity_type }}
</h2>
{% endif %}
</div>
{% include 'snippets/status.html' with activity=activity %}
{% endfor %}
</div>
{% endblock %}
3 changes: 2 additions & 1 deletion fedireads/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'^(?P<tab>home|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),
Expand Down
28 changes: 24 additions & 4 deletions fedireads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 = {
Expand All @@ -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)
Expand Down

0 comments on commit 248fe64

Please sign in to comment.