feat: Add leaderboard with grid display and tab navigation

This commit is contained in:
Kerby Martino (aider) committed 2025-05-05 18:04:08 +08:00
1 parent 475aa1caf2
commit 330a79e6e3
1 file changed
+134 -88
+134 -88
View File
@@ -1,98 +1,144 @@
{% comment %} --- Static Demo Data --- {% endcomment %}
{% assign demo_users = "" | split: "," %}
{% assign user1 = '{"username": "chair_enthusiast2025", "merits": 152, "posts": 15, "comments": 45, "joined": "2024-11-01"}' | parse_json %}
{% assign user2 = '{"username": "desk_ninja", "merits": 121, "posts": 8, "comments": 72, "joined": "2025-01-15"}' | parse_json %}
{% assign user3 = '{"username": "cable_conqueror", "merits": 98, "posts": 25, "comments": 30, "joined": "2024-12-20"}' | parse_json %}
{% assign user4 = '{"username": "ergonomic_explorer", "merits": 85, "posts": 12, "comments": 55, "joined": "2025-03-10"}' | parse_json %}
{% assign user5 = '{"username": "monitor_maven", "merits": 77, "posts": 5, "comments": 60, "joined": "2025-04-22"}' | parse_json %}
{% assign user6 = '{"username": "keyboard_king", "merits": 65, "posts": 18, "comments": 28, "joined": "2025-02-05"}' | parse_json %}
{% assign user7 = '{"username": "plant_parent_pro", "merits": 50, "posts": 3, "comments": 40, "joined": "2025-05-01"}' | parse_json %}
{% assign user8 = '{"username": "snack_strategist", "merits": 42, "posts": 22, "comments": 15, "joined": "2025-04-18"}' | parse_json %}
{% assign user9 = '{"username": "focus_finder", "merits": 30, "posts": 10, "comments": 20, "joined": "2025-03-28"}' | parse_json %}
{% assign user10 = '{"username": "newbie_navigator", "merits": 15, "posts": 2, "comments": 8, "joined": "2025-05-04"}' | parse_json %}
<div class="max-w-screen-lg mx-auto px-4 py-8">
<h1 class="text-3xl font-bold text-text-title mb-6 pb-4 border-b border-gray-200">Leaderboard</h1>
{% assign demo_users = demo_users | push: user1 | push: user2 | push: user3 | push: user4 | push: user5 | push: user6 | push: user7 | push: user8 | push: user9 | push: user10 %}
<!-- Tabs Navigation -->
<div class="mb-4 border-b border-gray-200">
<nav class="-mb-px flex space-x-8" aria-label="Tabs">
<a href="#tab-merits" class="group whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
border-primary text-primary [&:not(:target):not(:has(~:target))]:border-primary [&:not(:target):not(:has(~:target))]:text-primary
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
Merits
</a>
<a href="#tab-new-users" class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
New Users
</a>
<a href="#tab-most-posts" class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
Most Posts
</a>
<a href="#tab-most-comments" class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
Most Comments
</a>
<a href="#tab-most-votes" class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
Most Votes
</a>
</nav>
</div>
{% comment %} Sort Users for Leaderboards {% endcomment %}
{% assign top_merits_users = demo_users | sort: "merits" | reverse %}
{% assign top_posters = demo_users | sort: "posts" | reverse %}
{% assign top_commenters = demo_users | sort: "comments" | reverse %}
{% assign new_users = demo_users | sort: "joined" | reverse %}
<!-- Sub-Tabs Navigation -->
<div class="mb-4 border-b border-gray-200">
<nav class="-mb-px flex space-x-8" aria-label="Sub-Tabs">
<a href="#sub-tab-week" class="group whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
border-primary text-primary [&:not(:target):not(:has(~:target))]:border-primary [&:not(:target):not(:has(~:target))]:text-primary
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
Week
</a>
<a href="#sub-tab-month" class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
Month
</a>
<a href="#sub-tab-quarter" class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
Quarter
</a>
<a href="#sub-tab-year" class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
Year
</a>
<a href="#sub-tab-all-time" class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
[&:target]:border-primary [&:target]:text-primary
[&:not(:target)]:border-transparent [&:not(:target)]:text-gray-500 [&:not(:target)]:hover:text-gray-700 [&:not(:target)]:hover:border-gray-300">
All-time
</a>
</nav>
</div>
{% comment %} --- Leaderboard Display --- {% endcomment %}
<div class="leaderboard space-y-10">
<!-- Top Merits -->
<section>
<h2 class="text-2xl font-bold text-primary mb-4 font-action flex items-center">
<i class="fas fa-trophy text-yellow-500 mr-3 fa-fw"></i> Top Merits (All-Time)
</h2>
<ol class="list-none space-y-3">
{% for user in top_merits_users limit:10 %}
<li class="flex items-center justify-between p-3 bg-bg-footer rounded-md shadow-sm border border-gray-200">
<div class="flex items-center">
<span class="text-lg font-bold text-text-muted w-8 text-right mr-4">{{ forloop.index }}</span>
<a href="/user/{{ user.username }}/" class="text-primary font-action hover:underline font-medium">{{ user.username }}</a>
<!-- Tab Content Panes -->
<div class="space-y-6">
<div id="tab-merits" class="block [&:not(:target)]:hidden [&:not(:target):not(:has(~:target))]:block space-y-6">
<div id="sub-tab-week" class="block [&:not(:target)]:hidden [&:not(:target):not(:has(~:target))]:block space-y-6">
<!-- Users Grid for Merits - Week -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Example User Card -->
<div class="bg-white p-4 rounded-md shadow-md">
<div class="flex items-center space-x-4">
<img src="/assets/images/default-avatar.png" alt="User Avatar" class="w-12 h-12 rounded-full">
<div>
<h3 class="text-lg font-bold text-text-title">User1</h3>
<p class="text-sm text-text-muted">Merits: 150</p>
</div>
</div>
</div>
<!-- Add more user cards as needed -->
</div>
<span class="text-primary font-bold font-action">{{ user.merits }} Merits</span>
</li>
{% endfor %}
</ol>
</section>
<!-- Most Posts -->
<section>
<h2 class="text-2xl font-bold text-primary mb-4 font-action flex items-center">
<i class="fas fa-file-alt text-purple-500 mr-3 fa-fw"></i> Most Posts Submitted
</h2>
<ol class="list-none space-y-3">
{% for user in top_posters limit:10 %}
<li class="flex items-center justify-between p-3 bg-bg-footer rounded-md shadow-sm border border-gray-200">
<div class="flex items-center">
<span class="text-lg font-bold text-text-muted w-8 text-right mr-4">{{ forloop.index }}</span>
<a href="/user/{{ user.username }}/" class="text-primary font-action hover:underline font-medium">{{ user.username }}</a>
</div>
<div id="sub-tab-month" class="hidden [&:target]:block space-y-6">
<!-- Users Grid for Merits - Month -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Example User Card -->
<div class="bg-white p-4 rounded-md shadow-md">
<div class="flex items-center space-x-4">
<img src="/assets/images/default-avatar.png" alt="User Avatar" class="w-12 h-12 rounded-full">
<div>
<h3 class="text-lg font-bold text-text-title">User2</h3>
<p class="text-sm text-text-muted">Merits: 300</p>
</div>
</div>
</div>
<!-- Add more user cards as needed -->
</div>
<span class="text-primary font-bold font-action">{{ user.posts }} Posts</span>
</li>
{% endfor %}
</ol>
</section>
</div>
<!-- Add more sub-tabs for Merits as needed -->
</div>
<!-- Most Comments -->
<section>
<h2 class="text-2xl font-bold text-primary mb-4 font-action flex items-center">
<i class="fas fa-comments text-blue-500 mr-3 fa-fw"></i> Most Comments Submitted
</h2>
<ol class="list-none space-y-3">
{% for user in top_commenters limit:10 %}
<li class="flex items-center justify-between p-3 bg-bg-footer rounded-md shadow-sm border border-gray-200">
<div class="flex items-center">
<span class="text-lg font-bold text-text-muted w-8 text-right mr-4">{{ forloop.index }}</span>
<a href="/user/{{ user.username }}/" class="text-primary font-action hover:underline font-medium">{{ user.username }}</a>
<div id="tab-new-users" class="hidden [&:target]:block space-y-6">
<div id="sub-tab-week" class="block [&:not(:target)]:hidden [&:not(:target):not(:has(~:target))]:block space-y-6">
<!-- Users Grid for New Users - Week -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Example User Card -->
<div class="bg-white p-4 rounded-md shadow-md">
<div class="flex items-center space-x-4">
<img src="/assets/images/default-avatar.png" alt="User Avatar" class="w-12 h-12 rounded-full">
<div>
<h3 class="text-lg font-bold text-text-title">NewUser1</h3>
<p class="text-sm text-text-muted">Joined: 2 days ago</p>
</div>
</div>
</div>
<!-- Add more user cards as needed -->
</div>
<span class="text-primary font-bold font-action">{{ user.comments }} Comments</span>
</li>
{% endfor %}
</ol>
</section>
<!-- New Users -->
<section>
<h2 class="text-2xl font-bold text-primary mb-4 font-action flex items-center">
<i class="fas fa-user-plus text-green-500 mr-3 fa-fw"></i> Newest Members
</h2>
<ol class="list-none space-y-3">
{% for user in new_users limit:10 %}
<li class="flex items-center justify-between p-3 bg-bg-footer rounded-md shadow-sm border border-gray-200">
<div class="flex items-center">
<span class="text-lg font-bold text-text-muted w-8 text-right mr-4">{{ forloop.index }}</span>
<a href="/user/{{ user.username }}/" class="text-primary font-action hover:underline font-medium">{{ user.username }}</a>
</div>
<div id="sub-tab-month" class="hidden [&:target]:block space-y-6">
<!-- Users Grid for New Users - Month -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Example User Card -->
<div class="bg-white p-4 rounded-md shadow-md">
<div class="flex items-center space-x-4">
<img src="/assets/images/default-avatar.png" alt="User Avatar" class="w-12 h-12 rounded-full">
<div>
<h3 class="text-lg font-bold text-text-title">NewUser2</h3>
<p class="text-sm text-text-muted">Joined: 1 month ago</p>
</div>
</div>
</div>
<!-- Add more user cards as needed -->
</div>
<span class="text-sm text-text-muted font-action">Joined {{ user.joined | date: "%b %d, %Y" }}</span>
</li>
{% endfor %}
</ol>
</section>
</div>
<!-- Add more sub-tabs for New Users as needed -->
</div>
<!-- Add more tabs for Most Posts, Most Comments, Most Votes as needed -->
</div>
</div>