71 lines
3.4 KiB
HTML
71 lines
3.4 KiB
HTML
{%- import "macros.html" as macros -%}
|
|
<div class="border-t-2 border-gray-300 border-dashed pt-8">
|
|
<h2 class="text-2xl font-bold text-gray-900 mb-6">Comments ({{ comments_count }})</h2>
|
|
<div class="bg-gray-50 rounded-lg p-6 mb-8 border border-gray-200">
|
|
<h3 class="text-lg font-semibold text-gray-900 mb-4">Leave a comment</h3>
|
|
<form hx-post="/posts/{{ post.post_id }}/comments"
|
|
hx-target="#form-messages"
|
|
hx-swap="innerHTML"
|
|
class="space-y-4">
|
|
<input type="hidden" name="idempotency_key" value="{{ idempotency_key }}"/>
|
|
<div>
|
|
<input type="text"
|
|
name="author"
|
|
placeholder="Your name (optional)"
|
|
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
|
|
</div>
|
|
<div>
|
|
<textarea name="content"
|
|
rows="4"
|
|
required
|
|
placeholder="Write your comment..."
|
|
class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"></textarea>
|
|
</div>
|
|
<button type="submit"
|
|
class="bg-blue-600 text-white hover:bg-blue-700 font-medium py-2 px-6 rounded-md transition-colors">
|
|
Submit
|
|
</button>
|
|
<div id="form-messages"></div>
|
|
</form>
|
|
</div>
|
|
{% block comments %}
|
|
{% if comments.is_empty() %}
|
|
<div id="comments-list" class="text-center py-8 text-gray-500">
|
|
<svg class="w-12 h-12 mx-auto mb-3 text-gray-400"
|
|
fill="none"
|
|
viewBox="0 0 24 24"
|
|
stroke="currentColor">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/>
|
|
</svg>
|
|
<p>No comments yet. Be the first to comment!</p>
|
|
</div>
|
|
{% else %}
|
|
{% let post_id = comments[0].post_id %}
|
|
<div id="comments-list" class="space-y-4">
|
|
{% for comment in comments %}
|
|
{% include "posts/comments/card.html" %}
|
|
{% endfor %}
|
|
<div id="load-more-comments" class="text-center mt-6">
|
|
{% if current_page < max_page %}
|
|
<div class="flex flex-col items-center space-y-6">
|
|
<button hx-get="/posts/{{ post_id }}/comments?page={{ current_page + 1 }}"
|
|
hx-target="#load-more-comments"
|
|
hx-swap="outerHTML"
|
|
hx-indicator="#comment-indicator"
|
|
class="text-center bg-gray-200 text-gray-700 hover:bg-gray-300 font-medium py-2 px-6 rounded-md transition-colors">
|
|
Load more comments
|
|
</button>
|
|
<span id="comment-indicator" class="htmx-indicator">
|
|
{% call macros::spinner(class="text-gray-300 w-6 h-6", highlight_class="text-gray-700", size=24) %}
|
|
</span>
|
|
</div>
|
|
{% else %}
|
|
<p class="text-gray-600">No more comments. Check back later for more!</p>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
{% endblock %}
|