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 %} <div class="max-w-screen-lg mx-auto px-4 py-8">
{% assign demo_users = "" | split: "," %} <h1 class="text-3xl font-bold text-text-title mb-6 pb-4 border-b border-gray-200">Leaderboard</h1>
{% 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 %}
{% 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 %} <!-- Sub-Tabs Navigation -->
{% assign top_merits_users = demo_users | sort: "merits" | reverse %} <div class="mb-4 border-b border-gray-200">
{% assign top_posters = demo_users | sort: "posts" | reverse %} <nav class="-mb-px flex space-x-8" aria-label="Sub-Tabs">
{% assign top_commenters = demo_users | sort: "comments" | reverse %} <a href="#sub-tab-week" class="group whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm
{% assign new_users = demo_users | sort: "joined" | reverse %} 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>
<!-- Tab Content Panes -->
{% comment %} --- Leaderboard Display --- {% endcomment %} <div class="space-y-6">
<div class="leaderboard space-y-10"> <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">
<!-- Top Merits --> <!-- Users Grid for Merits - Week -->
<section> <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<h2 class="text-2xl font-bold text-primary mb-4 font-action flex items-center"> <!-- Example User Card -->
<i class="fas fa-trophy text-yellow-500 mr-3 fa-fw"></i> Top Merits (All-Time) <div class="bg-white p-4 rounded-md shadow-md">
</h2> <div class="flex items-center space-x-4">
<ol class="list-none space-y-3"> <img src="/assets/images/default-avatar.png" alt="User Avatar" class="w-12 h-12 rounded-full">
{% for user in top_merits_users limit:10 %} <div>
<li class="flex items-center justify-between p-3 bg-bg-footer rounded-md shadow-sm border border-gray-200"> <h3 class="text-lg font-bold text-text-title">User1</h3>
<div class="flex items-center"> <p class="text-sm text-text-muted">Merits: 150</p>
<span class="text-lg font-bold text-text-muted w-8 text-right mr-4">{{ forloop.index }}</span> </div>
<a href="/user/{{ user.username }}/" class="text-primary font-action hover:underline font-medium">{{ user.username }}</a> </div>
</div>
<!-- Add more user cards as needed -->
</div> </div>
<span class="text-primary font-bold font-action">{{ user.merits }} Merits</span> </div>
</li> <div id="sub-tab-month" class="hidden [&:target]:block space-y-6">
{% endfor %} <!-- Users Grid for Merits - Month -->
</ol> <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
</section> <!-- Example User Card -->
<div class="bg-white p-4 rounded-md shadow-md">
<!-- Most Posts --> <div class="flex items-center space-x-4">
<section> <img src="/assets/images/default-avatar.png" alt="User Avatar" class="w-12 h-12 rounded-full">
<h2 class="text-2xl font-bold text-primary mb-4 font-action flex items-center"> <div>
<i class="fas fa-file-alt text-purple-500 mr-3 fa-fw"></i> Most Posts Submitted <h3 class="text-lg font-bold text-text-title">User2</h3>
</h2> <p class="text-sm text-text-muted">Merits: 300</p>
<ol class="list-none space-y-3"> </div>
{% for user in top_posters limit:10 %} </div>
<li class="flex items-center justify-between p-3 bg-bg-footer rounded-md shadow-sm border border-gray-200"> </div>
<div class="flex items-center"> <!-- Add more user cards as needed -->
<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>
<span class="text-primary font-bold font-action">{{ user.posts }} Posts</span> </div>
</li> <!-- Add more sub-tabs for Merits as needed -->
{% endfor %} </div>
</ol>
</section>
<!-- Most Comments --> <div id="tab-new-users" class="hidden [&:target]:block space-y-6">
<section> <div id="sub-tab-week" class="block [&:not(:target)]:hidden [&:not(:target):not(:has(~:target))]:block space-y-6">
<h2 class="text-2xl font-bold text-primary mb-4 font-action flex items-center"> <!-- Users Grid for New Users - Week -->
<i class="fas fa-comments text-blue-500 mr-3 fa-fw"></i> Most Comments Submitted <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
</h2> <!-- Example User Card -->
<ol class="list-none space-y-3"> <div class="bg-white p-4 rounded-md shadow-md">
{% for user in top_commenters limit:10 %} <div class="flex items-center space-x-4">
<li class="flex items-center justify-between p-3 bg-bg-footer rounded-md shadow-sm border border-gray-200"> <img src="/assets/images/default-avatar.png" alt="User Avatar" class="w-12 h-12 rounded-full">
<div class="flex items-center"> <div>
<span class="text-lg font-bold text-text-muted w-8 text-right mr-4">{{ forloop.index }}</span> <h3 class="text-lg font-bold text-text-title">NewUser1</h3>
<a href="/user/{{ user.username }}/" class="text-primary font-action hover:underline font-medium">{{ user.username }}</a> <p class="text-sm text-text-muted">Joined: 2 days ago</p>
</div>
</div>
</div>
<!-- Add more user cards as needed -->
</div> </div>
<span class="text-primary font-bold font-action">{{ user.comments }} Comments</span> </div>
</li> <div id="sub-tab-month" class="hidden [&:target]:block space-y-6">
{% endfor %} <!-- Users Grid for New Users - Month -->
</ol> <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
</section> <!-- Example User Card -->
<div class="bg-white p-4 rounded-md shadow-md">
<!-- New Users --> <div class="flex items-center space-x-4">
<section> <img src="/assets/images/default-avatar.png" alt="User Avatar" class="w-12 h-12 rounded-full">
<h2 class="text-2xl font-bold text-primary mb-4 font-action flex items-center"> <div>
<i class="fas fa-user-plus text-green-500 mr-3 fa-fw"></i> Newest Members <h3 class="text-lg font-bold text-text-title">NewUser2</h3>
</h2> <p class="text-sm text-text-muted">Joined: 1 month ago</p>
<ol class="list-none space-y-3"> </div>
{% for user in new_users limit:10 %} </div>
<li class="flex items-center justify-between p-3 bg-bg-footer rounded-md shadow-sm border border-gray-200"> </div>
<div class="flex items-center"> <!-- Add more user cards as needed -->
<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>
<span class="text-sm text-text-muted font-action">Joined {{ user.joined | date: "%b %d, %Y" }}</span> </div>
</li> <!-- Add more sub-tabs for New Users as needed -->
{% endfor %} </div>
</ol>
</section>
<!-- Add more tabs for Most Posts, Most Comments, Most Votes as needed -->
</div>
</div> </div>