Add likes/comment counts + like button to individual post viewer

- Only render in jQuery and likes script when a user is logged in
- Possibly we should show the like button but redirect to login page?
This commit is contained in:
Xevion
2022-03-30 16:49:59 -05:00
parent 531c60d163
commit f8e8d0fbaf
2 changed files with 18 additions and 6 deletions

View File

@@ -1,7 +1,9 @@
{% extends 'layouts/index.html' %}
{% from 'macros.html' import render_field %}
{% set use_jquery = true %}
{% set use_likes = true %}
{% if current_user.is_authenticated %}
{% set use_jquery = true %}
{% set use_likes = true %}
{% endif %}
{% block content %}
{% if current_user.is_authenticated %}

View File

@@ -1,18 +1,28 @@
{% extends 'layouts/index.html' %}
{% set use_jquery = true %}
{% set use_likes = true %}
{% block content %}
<div class="post-box">
<div id="post-{{ post.id }}" class="post-box">
{% if current_user.is_authenticated %}
<i class="fas fa-heart {% if current_user.has_liked_post(post.id) %}liked{% endif %}" onclick="like({{ post.id }})"></i>
{% endif %}
{{ post.text }}
<br>
<div class="post-author">
<em>Posted by <a href="{{ url_for('main.view_user', username=post.author.username) }}">{{ post.author.name }}</a></em> <span
title="{{ post.date_posted }}">{{ post.get_time_ago() }} ago</span>.
{% with comment_count = post.comments|length %}
<em>Posted by <a href="{{ url_for('main.view_user', username=post.author.username) }}">{{ post.author.name }}</a></em>
<span title="{{ post.date_posted }}">{{ post.get_time_ago() }} ago</span>. |
<a href="{{ url_for('main.view_post', post_id=post.id) }}"><span> {{ comment_count }} comment{{ comment_count|pluralize }}</span></a>
| <span class="post-like-status">{{ post.get_like_text()|safe }}</span>
{% endwith %}
</div>
<div class="post-comments">
{% if current_user.is_authenticated %}
<div class="post-comment add-comment">
<form method="POST" action="{{ url_for('forms.add_comment', post_id=post.id) }}">
{{ form.csrf_token }}
{{ form.text }}<input type=submit value="Add Comment">
{{ form.text()|safe }}<input type=submit value="Add Comment">
</form>
</div>
{% endif %}