Support for comments
Some checks failed
Rust / Test (push) Failing after 4m13s
Rust / Rustfmt (push) Successful in 22s
Rust / Clippy (push) Failing after 31s
Rust / Code coverage (push) Successful in 6m21s

This commit is contained in:
Alphonse Paix
2025-10-02 00:26:18 +02:00
parent 2c7282475f
commit cb3f216591
14 changed files with 380 additions and 2751 deletions

View File

@@ -0,0 +1,30 @@
<div class="bg-white rounded-lg p-4 border border-gray-200">
<div class="flex items-start space-x-3">
<div class="flex-shrink-0">
<div class="w-10 h-10 bg-gray-200 rounded-full flex items-center justify-center">
<svg class="w-5 h-5 text-gray-500"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
</svg>
</div>
</div>
<div class="flex-1 min-w-0">
<div class="flex items-center space-x-2 mb-1">
<span class="font-medium text-gray-900">
{% if let Some(name) = comment.author %}
{{ name }}
{% else %}
Anonymous
{% endif %}
</span>
<span class="text-gray-400"></span>
<time class="text-sm text-gray-500" datetime="{{ comment.published_at }}">
{{ comment.formatted_date() }}
</time>
</div>
<p class="text-gray-700 whitespace-pre-line">{{ comment.content }}</p>
</div>
</div>
</div>

View File

@@ -0,0 +1,68 @@
{%- 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">
<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 %}

View File

@@ -35,6 +35,7 @@
</header>
<div class="prose-compact">{{ post.content | safe }}</div>
</article>
<div class="mt-12">{% include "posts/comments/list.html" %}</div>
<div class="mt-8 bg-gradient-to-r from-blue-600 to-indigo-700 rounded-lg shadow-lg text-white p-8 text-center">
<h3 class="text-2xl font-bold mb-2">Enjoyed this post?</h3>
<p class="text-blue-100 mb-4">Subscribe to my newsletter for more insights on Rust backend development.</p>