feat: update mobile comment view to use nested comments

This commit is contained in:
Kerby Martino authored and Kerby Martino (aider) committed 2025-05-02 23:52:10 +08:00
1 parent 05a4cf1c64
commit 0d4e9c002a
5 files changed
+25 -201

No files matched your search

+1
View File
@@ -17,6 +17,7 @@ GEM
ffi (1.17.0-x64-mingw-ucrt) ffi (1.17.0-x64-mingw-ucrt)
ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-darwin)
forwardable-extended (2.6.0) forwardable-extended (2.6.0)
google-protobuf (3.25.4)
google-protobuf (3.25.4-arm64-darwin) google-protobuf (3.25.4-arm64-darwin)
google-protobuf (3.25.4-x64-mingw-ucrt) google-protobuf (3.25.4-x64-mingw-ucrt)
google-protobuf (3.25.4-x86_64-darwin) google-protobuf (3.25.4-x86_64-darwin)
+1 -1
View File
@@ -5,6 +5,6 @@ post: 2023-10-02-ask-the-saga-of-the-disappearing-ergonomic-chair-continues
author: commenter1 author: commenter1
date: 2023-10-02 12:00:00 +0000 date: 2023-10-02 12:00:00 +0000
upvotes: 15 upvotes: 15
replies: 8 replies: 24
--- ---
Haha, this totally happened to me last year. We had a phantom chair thief at work and it became an ongoing office joke for months! Haha, this totally happened to me last year. We had a phantom chair thief at work and it became an ongoing office joke for months!
-160
View File
@@ -1,160 +0,0 @@
{% comment %}
Mobile Comment View: Renders a flat list of top-level comments for the current post.
Assumes JavaScript will handle the navigation to nested replies using fragment identifiers.
{% endcomment %}
{% assign post_comments = site.comments | where: "post", page.slug %}
{% assign top_level_comments = post_comments | where_exp: "item", "item.parent == nil or item.parent == ''" | sort: "date" %}
<div id="mobile-comments-list" class="space-y-4">
{% if top_level_comments.size > 0 %}
{% for comment in top_level_comments %}
{% assign direct_replies = site.comments | where: "parent", comment.slug %}
<div class="border-b border-gray-200 pb-3 mb-3" id="mobile-comment-{{ comment.slug }}">
<p class="text-sm mb-2">{{ comment.content | default: "Missing content" }}</p>
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
<div class="flex items-start space-x-2 mb-2 md:mb-0">
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fa-solid fa-arrow-up mr-1"></i> {{ comment.upvotes }}
</span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fas fa-reply mr-1"></i> REPLY
</span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fas fa-comment mr-1"></i> {{ direct_replies.size }}
</span>
</div>
<small class="text-sm font-action">
<a href="#" class="text-sm hover:underline">{{ comment.author }}</a>
<span class="text-text-muted text-sm opacity-75">{{ comment.date | date: "%d %b %Y" }}</span>
</small>
</div>
<div class="flex items-center justify-between">
<div class="flex items-center space-x-2">
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fa-solid fa-arrow-up mr-1"></i> {{ comment.upvotes }}
</span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fas fa-reply mr-1"></i> REPLY
</span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fas fa-comment mr-1"></i> {{ direct_replies.size }}
</span>
</div>
<div class="text-right">
{% if direct_replies.size > 0 %}
<a href="#mobile-comment-thread-{{ comment.slug }}" class="view-replies text-xs text-primary hover:underline" data-comment-slug="{{ comment.slug }}">
View Replies ({{ direct_replies.size }}) <i class="fas fa-chevron-right text-xs"></i>
</a>
{% else %}
<span class="text-xs text-text-muted opacity-75">No Replies</span>
{% endif %}
</div>
</div>
</div>
{% endfor %}
{% else %}
<p class="text-sm text-text-muted">No comments yet.</p>
{% endif %}
</div>
{% comment %}
Placeholder for where JavaScript would load the replies for a selected comment.
This container could be populated by JS when a 'View Replies' link is clicked.
{% endcomment %}
<div id="mobile-comment-thread-view" class="hidden mt-4">
<button class="back-to-list text-primary mb-2 text-sm">
<i class="fas fa-chevron-left text-xs"></i> Back to Comments
</button>
<div id="mobile-comment-thread-content">
<!-- Parent comment and its replies will be loaded here by JavaScript -->
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const commentsList = document.getElementById('mobile-comments-list');
const threadView = document.getElementById('mobile-comment-thread-view');
const threadContent = document.getElementById('mobile-comment-thread-content');
const backToListButton = threadView.querySelector('.back-to-list');
commentsList.addEventListener('click', function(event) {
if (event.target.classList.contains('view-replies')) {
event.preventDefault();
const commentSlug = event.target.getAttribute('data-comment-slug');
loadCommentThread(commentSlug);
}
});
backToListButton.addEventListener('click', function() {
threadView.classList.add('hidden');
commentsList.classList.remove('hidden');
});
function loadCommentThread(commentSlug) {
// Fetch the parent comment and its replies using AJAX or preloaded data
// For demonstration, we'll use a static example
const parentComment = {
slug: commentSlug,
author: 'Author Name',
date: '10 Oct 2023',
content: 'This is the parent comment content.',
upvotes: 5,
replies: [
{
author: 'Reply Author 1',
date: '11 Oct 2023',
content: 'This is a reply to the parent comment.'
},
{
author: 'Reply Author 2',
date: '12 Oct 2023',
content: 'This is another reply to the parent comment.'
}
]
};
// Render the parent comment and its replies
threadContent.innerHTML = `
<div class="border-b border-gray-200 pb-3 mb-3">
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
<div class="flex items-start space-x-2 mb-2 md:mb-0">
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fa-solid fa-arrow-up mr-1"></i> ${parentComment.upvotes}
</span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fas fa-reply mr-1"></i> REPLY
</span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center">
<i class="fas fa-comment mr-1"></i> ${parentComment.replies.length}
</span>
</div>
<small class="text-sm font-action">
<a href="#" class="text-sm hover:underline">${parentComment.author}</a>
<span class="text-text-muted text-sm opacity-75">${parentComment.date}</span>
</small>
</div>
<p class="text-sm mb-2">${parentComment.content}</p>
</div>
<div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
${parentComment.replies.map(reply => `
<div class="mb-3">
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
<small class="text-sm font-action">
<a href="#" class="text-sm hover:underline">${reply.author}</a>
<span class="text-text-muted text-sm opacity-75">${reply.date}</span>
</small>
</div>
<p class="text-sm mb-2">${reply.content}</p>
</div>
`).join('')}
</div>
`;
// Show the thread view and hide the comments list
commentsList.classList.add('hidden');
threadView.classList.remove('hidden');
}
});
</script>
+21 -38
View File
@@ -8,68 +8,51 @@
</div> </div>
<div id="mobile-comment-thread-content"> <div id="mobile-comment-thread-content">
<div class="border-b border-gray-200 pb-3 mb-3"> <div class="border-b border-gray-200 pb-3 mb-3">
<p class="text-sm mb-2">This is the parent comment content.</p> <p class="text-sm mb-2">{{ page.content }}</p>
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2"> <div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
<div class="flex items-start space-x-2 mb-2 md:mb-0"> <div class="flex items-start space-x-2 mb-2 md:mb-0">
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover"> <span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fa-solid fa-arrow-up mr-1"></i> 5 <i class="fa-solid fa-arrow-up mr-1"></i> {{ page.upvotes }}
</span> </span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover"> <span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fas fa-reply mr-1"></i> REPLY <i class="fas fa-reply mr-1"></i> REPLY
</span> </span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover"> <span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fas fa-comment mr-1"></i> 2 <i class="fas fa-comment mr-1"></i> {{ page.replies }}
</span> </span>
</div> </div>
<small class="text-sm font-action"> <small class="text-sm font-action">
<a href="#" class="text-sm hover:underline">Author Name</a> <a href="#" class="text-sm hover:underline">{{ page.author }}</a>
<span class="text-text-muted text-sm opacity-75">10 Oct 2023</span> <span class="text-text-muted text-sm opacity-75">{{ page.date | date: "%d %b %Y" }}</span>
</small> </small>
</div> </div>
</div> </div>
<div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2"> <div class="ml-4 mt-3 border-l-2 border-gray-200 pl-2">
<div class="mb-3 pb-3 border-b border-gray-200"> {% assign nested_comments = site.comments | where: "parent", page.slug | sort: "date" %}
<p class="text-sm mb-2">This is a reply to the parent comment.</p>
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
<div class="flex items-start space-x-2 mb-2 md:mb-0">
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fa-solid fa-arrow-up mr-1"></i> 5
</span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fas fa-reply mr-1"></i> REPLY
</span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fas fa-comment mr-1"></i> 2
</span>
</div>
<small class="text-sm font-action">
<a href="#" class="text-sm hover:underline">Reply Author 1</a>
<span class="text-text-muted text-sm opacity-75">11 Oct 2023</span>
</small>
</div>
</div>
<div class="mb-3"> {% for comment in nested_comments %}
<p class="text-sm mb-2">This is another reply to the parent comment.</p> <div class="mb-3 pb-3 border-b border-gray-200">
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2"> <p class="text-sm mb-2">{{ comment.content }}</p>
<div class="flex items-start space-x-2 mb-2 md:mb-0"> <div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
<div class="flex items-start space-x-2 mb-2 md:mb-0">
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover"> <span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fa-solid fa-arrow-up mr-1"></i> 5 <i class="fa-solid fa-arrow-up mr-1"></i>
</span> </span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover"> <span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fas fa-reply mr-1"></i> REPLY <i class="fas fa-reply mr-1"></i> REPLY
</span> </span>
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover"> <span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
<i class="fas fa-comment mr-1"></i> 2 <i class="fas fa-comment mr-1"></i> {{ comment.replies }}
</span> </span>
</div>
<small class="text-sm font-action">
<a href="#" class="text-sm hover:underline">{{ comment.author }}</a>
<span class="text-text-muted text-sm opacity-75">{{ comment.date | date: "%d %b %Y" }}</span>
</small>
</div> </div>
<small class="text-sm font-action">
<a href="#" class="text-sm hover:underline">Reply Author 2</a>
<span class="text-text-muted text-sm opacity-75">12 Oct 2023</span>
</small>
</div> </div>
</div> {% endfor %}
</div> </div>
</div> </div>
+2 -2
View File
@@ -15,7 +15,7 @@ layout: default
</p> </p>
<div class="post-content mb-2"> <div class="post-content mb-2">
{{ content }} {{ post.content }}
</div> </div>
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2"> <div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
@@ -52,6 +52,6 @@ layout: default
</div> </div>
</form> </form>
<div class="mt-4"> <div class="mt-4">
{% include mobile_comment_nested.liquid %} {% include mobile_comment_nested.liquid comment=page %}
</div> </div>
</div> </div>