Spaces:
Sleeping
Sleeping
Yuyuqt commited on
Commit ·
cf9e5bb
1
Parent(s): 46cf1b2
add: fix user insights active ranking, rewards theme changes
Browse files
BlazorFrontend/Components/Layout/MainLayout.razor
CHANGED
|
@@ -71,6 +71,10 @@
|
|
| 71 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="flex-shrink-0 mr-3"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
|
| 72 |
Manage Rewards
|
| 73 |
</NavLink>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
</Authorized>
|
| 75 |
</AuthorizeView>
|
| 76 |
</nav>
|
|
|
|
| 71 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="flex-shrink-0 mr-3"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
|
| 72 |
Manage Rewards
|
| 73 |
</NavLink>
|
| 74 |
+
<NavLink href="Insights" class="nav-link" ActiveClass="active">
|
| 75 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="flex-shrink-0 mr-3"><path d="M21 12V7H5a2 2 0 010-4h14v4"/><path d="M3 5v14a2 2 0 002 2h16v-5"/><path d="M18 12a2 2 0 000 4h4v-4Z"/></svg>
|
| 76 |
+
User Insights
|
| 77 |
+
</NavLink>
|
| 78 |
</Authorized>
|
| 79 |
</AuthorizeView>
|
| 80 |
</nav>
|
BlazorFrontend/Components/Pages/Home.razor
CHANGED
|
@@ -27,27 +27,32 @@ else
|
|
| 27 |
@if (_loyaltyAccount != null)
|
| 28 |
{
|
| 29 |
<a href="Rewards" class="block group mb-10 animate-in fade-in zoom-in-95 duration-700">
|
| 30 |
-
<div class="bg-gradient-to-
|
| 31 |
-
<div class="relative z-10 flex items-center justify-between">
|
| 32 |
<div>
|
| 33 |
-
<p class="text-
|
| 34 |
<div class="flex items-baseline gap-3">
|
| 35 |
-
<h2 class="text-
|
| 36 |
-
<span class="text-
|
| 37 |
</div>
|
| 38 |
-
<p class="text-[10px] text-
|
| 39 |
</div>
|
| 40 |
-
<div class="
|
| 41 |
-
<div class="
|
| 42 |
-
<
|
| 43 |
-
<
|
|
|
|
|
|
|
|
|
|
| 44 |
</div>
|
| 45 |
-
<div class="
|
| 46 |
-
<svg class="w-
|
| 47 |
</div>
|
| 48 |
</div>
|
| 49 |
</div>
|
| 50 |
-
<
|
|
|
|
|
|
|
| 51 |
</div>
|
| 52 |
</a>
|
| 53 |
}
|
|
|
|
| 27 |
@if (_loyaltyAccount != null)
|
| 28 |
{
|
| 29 |
<a href="Rewards" class="block group mb-10 animate-in fade-in zoom-in-95 duration-700">
|
| 30 |
+
<div class="bg-gradient-to-br from-mystic-900 to-[#5a5669] rounded-3xl p-8 text-white shadow-xl relative overflow-hidden transition-all duration-500 hover:shadow-2xl hover:translate-y-[-4px] border border-white/5">
|
| 31 |
+
<div class="relative z-10 flex flex-col md:flex-row md:items-center justify-between gap-6">
|
| 32 |
<div>
|
| 33 |
+
<p class="text-mystic-200 text-xs font-bold uppercase tracking-[0.2em] mb-2 opacity-80">Your Loyalty Status</p>
|
| 34 |
<div class="flex items-baseline gap-3">
|
| 35 |
+
<h2 class="text-5xl font-black tracking-tighter">@_loyaltyAccount.CurrentBalance.ToString("N0")</h2>
|
| 36 |
+
<span class="text-mystic-300 font-bold tracking-wide text-lg">Points Earned</span>
|
| 37 |
</div>
|
| 38 |
+
<p class="text-[10px] text-white/40 mt-3 uppercase tracking-widest font-bold">Member Account: Verified</p>
|
| 39 |
</div>
|
| 40 |
+
<div class="flex items-center gap-6">
|
| 41 |
+
<div class="flex flex-col items-end">
|
| 42 |
+
<span class="text-[10px] text-mystic-300 font-bold uppercase tracking-widest mb-1 opacity-60">Current Tier</span>
|
| 43 |
+
<div class="inline-flex items-center gap-3 bg-white/10 backdrop-blur-md px-6 py-3 rounded-2xl border border-white/10 shadow-xl">
|
| 44 |
+
<div class="w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></div>
|
| 45 |
+
<span class="font-black text-xl tracking-tight">@_loyaltyAccount.Tier</span>
|
| 46 |
+
</div>
|
| 47 |
</div>
|
| 48 |
+
<div class="w-12 h-12 bg-white/10 rounded-2xl flex items-center justify-center group-hover:bg-white/20 transition-all duration-300">
|
| 49 |
+
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M9 5l7 7-7 7"></path></svg>
|
| 50 |
</div>
|
| 51 |
</div>
|
| 52 |
</div>
|
| 53 |
+
<!-- Decorative Elements -->
|
| 54 |
+
<div class="absolute -right-20 -bottom-20 w-64 h-64 bg-white/5 rounded-full blur-3xl transform group-hover:scale-125 transition-transform duration-1000"></div>
|
| 55 |
+
<div class="absolute -left-20 -top-20 w-48 h-48 bg-mystic-100/5 rounded-full blur-2xl transform group-hover:scale-110 transition-transform duration-1000"></div>
|
| 56 |
</div>
|
| 57 |
</a>
|
| 58 |
}
|
BlazorFrontend/Components/Pages/Rewards.razor
CHANGED
|
@@ -14,10 +14,10 @@
|
|
| 14 |
@if (_account != null)
|
| 15 |
{
|
| 16 |
<div class="flex items-center gap-4">
|
| 17 |
-
<div class="text-center bg-
|
| 18 |
-
<p class="text-[10px] font-bold text-
|
| 19 |
-
<p class="text-2xl font-black
|
| 20 |
-
<p class="text-xs text-
|
| 21 |
</div>
|
| 22 |
<div class="text-center bg-mystic-50 border border-mystic-200 px-6 py-3 rounded-2xl shadow-sm">
|
| 23 |
<p class="text-[10px] font-bold text-mystic-500 uppercase tracking-widest">Tier</p>
|
|
@@ -48,7 +48,7 @@
|
|
| 48 |
</span>
|
| 49 |
@if (_pendingRedemptions.Any())
|
| 50 |
{
|
| 51 |
-
<span class="ml-1 inline-flex items-center justify-center w-5 h-5 text-[10px] font-black rounded-full bg-
|
| 52 |
}
|
| 53 |
</button>
|
| 54 |
<button @onclick='() => _activeTab = "history"'
|
|
@@ -87,10 +87,10 @@ else
|
|
| 87 |
{
|
| 88 |
var canAfford = _account != null && _account.CurrentBalance >= reward.PointCost;
|
| 89 |
<div class="group relative bg-white border border-mystic-200 rounded-2xl shadow-sm hover:shadow-xl hover:-translate-y-1 transition-all duration-300 overflow-hidden">
|
| 90 |
-
<div class="h-1.5 @(canAfford ? "bg-gradient-to-r from-
|
| 91 |
<div class="p-6">
|
| 92 |
<div class="flex justify-between items-start mb-4">
|
| 93 |
-
<div class="p-3 @(canAfford ? "bg-
|
| 94 |
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z"></path></svg>
|
| 95 |
</div>
|
| 96 |
<div class="text-right">
|
|
@@ -105,7 +105,7 @@ else
|
|
| 105 |
@if (canAfford)
|
| 106 |
{
|
| 107 |
<button @onclick="() => RedeemAsync(reward)"
|
| 108 |
-
class="bg-mystic-900 text-white px-4 py-2 rounded-xl text-xs font-bold hover:bg-
|
| 109 |
Redeem
|
| 110 |
</button>
|
| 111 |
}
|
|
@@ -128,7 +128,7 @@ else
|
|
| 128 |
<h2 class="text-lg font-bold mb-1">How to earn more points?</h2>
|
| 129 |
<p class="text-mystic-400 text-sm">Borrow books, subscribe, and return on time to earn points!</p>
|
| 130 |
</div>
|
| 131 |
-
<a href="Books" class="bg-
|
| 132 |
</div>
|
| 133 |
</div>
|
| 134 |
}
|
|
@@ -146,9 +146,9 @@ else
|
|
| 146 |
<div class="space-y-3">
|
| 147 |
@foreach (var r in _pendingRedemptions)
|
| 148 |
{
|
| 149 |
-
<div class="flex items-center justify-between bg-white border border-
|
| 150 |
<div class="flex items-center gap-4">
|
| 151 |
-
<div class="w-10 h-10 rounded-xl bg-
|
| 152 |
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v13m0-13V6a2 2 0 112 2h-2zm0 0V5.5A2.5 2.5 0 109.5 8H12zm-7 4h14M5 12a2 2 0 110-4h14a2 2 0 110 4M5 12v7a2 2 0 002 2h10a2 2 0 002-2v-7"></path></svg>
|
| 153 |
</div>
|
| 154 |
<div>
|
|
@@ -156,8 +156,8 @@ else
|
|
| 156 |
<p class="text-xs text-mystic-400">Claimed @r.RedeemedAt.ToString("MMM dd, yyyy") · @r.PointCost.ToString("N0") pts</p>
|
| 157 |
</div>
|
| 158 |
</div>
|
| 159 |
-
<span class="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold bg-
|
| 160 |
-
<span class="w-1.5 h-1.5 rounded-full bg-
|
| 161 |
Awaiting Fulfillment
|
| 162 |
</span>
|
| 163 |
</div>
|
|
|
|
| 14 |
@if (_account != null)
|
| 15 |
{
|
| 16 |
<div class="flex items-center gap-4">
|
| 17 |
+
<div class="text-center bg-mystic-900 text-white px-6 py-3 rounded-2xl shadow-lg border border-white/5">
|
| 18 |
+
<p class="text-[10px] font-bold text-mystic-200 uppercase tracking-widest">Balance</p>
|
| 19 |
+
<p class="text-2xl font-black">@_account.CurrentBalance.ToString("N0")</p>
|
| 20 |
+
<p class="text-xs text-mystic-300 font-semibold">Points</p>
|
| 21 |
</div>
|
| 22 |
<div class="text-center bg-mystic-50 border border-mystic-200 px-6 py-3 rounded-2xl shadow-sm">
|
| 23 |
<p class="text-[10px] font-bold text-mystic-500 uppercase tracking-widest">Tier</p>
|
|
|
|
| 48 |
</span>
|
| 49 |
@if (_pendingRedemptions.Any())
|
| 50 |
{
|
| 51 |
+
<span class="ml-1 inline-flex items-center justify-center w-5 h-5 text-[10px] font-black rounded-full bg-mystic-900 text-white">@_pendingRedemptions.Count()</span>
|
| 52 |
}
|
| 53 |
</button>
|
| 54 |
<button @onclick='() => _activeTab = "history"'
|
|
|
|
| 87 |
{
|
| 88 |
var canAfford = _account != null && _account.CurrentBalance >= reward.PointCost;
|
| 89 |
<div class="group relative bg-white border border-mystic-200 rounded-2xl shadow-sm hover:shadow-xl hover:-translate-y-1 transition-all duration-300 overflow-hidden">
|
| 90 |
+
<div class="h-1.5 @(canAfford ? "bg-gradient-to-r from-mystic-600 to-mystic-900" : "bg-mystic-200")"></div>
|
| 91 |
<div class="p-6">
|
| 92 |
<div class="flex justify-between items-start mb-4">
|
| 93 |
+
<div class="p-3 @(canAfford ? "bg-mystic-50 text-mystic-600" : "bg-mystic-100 text-mystic-400") rounded-xl">
|
| 94 |
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z"></path></svg>
|
| 95 |
</div>
|
| 96 |
<div class="text-right">
|
|
|
|
| 105 |
@if (canAfford)
|
| 106 |
{
|
| 107 |
<button @onclick="() => RedeemAsync(reward)"
|
| 108 |
+
class="bg-mystic-900 text-white px-4 py-2 rounded-xl text-xs font-bold hover:bg-mystic-700 transition-all active:scale-95 shadow-md">
|
| 109 |
Redeem
|
| 110 |
</button>
|
| 111 |
}
|
|
|
|
| 128 |
<h2 class="text-lg font-bold mb-1">How to earn more points?</h2>
|
| 129 |
<p class="text-mystic-400 text-sm">Borrow books, subscribe, and return on time to earn points!</p>
|
| 130 |
</div>
|
| 131 |
+
<a href="Books" class="bg-white text-mystic-900 px-6 py-3 rounded-2xl font-black hover:bg-mystic-50 transition-all text-sm whitespace-nowrap shadow-sm">Browse Books →</a>
|
| 132 |
</div>
|
| 133 |
</div>
|
| 134 |
}
|
|
|
|
| 146 |
<div class="space-y-3">
|
| 147 |
@foreach (var r in _pendingRedemptions)
|
| 148 |
{
|
| 149 |
+
<div class="flex items-center justify-between bg-white border border-mystic-100 rounded-2xl px-6 py-4 shadow-sm">
|
| 150 |
<div class="flex items-center gap-4">
|
| 151 |
+
<div class="w-10 h-10 rounded-xl bg-mystic-50 flex items-center justify-center text-mystic-600 flex-shrink-0">
|
| 152 |
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v13m0-13V6a2 2 0 112 2h-2zm0 0V5.5A2.5 2.5 0 109.5 8H12zm-7 4h14M5 12a2 2 0 110-4h14a2 2 0 110 4M5 12v7a2 2 0 002 2h10a2 2 0 002-2v-7"></path></svg>
|
| 153 |
</div>
|
| 154 |
<div>
|
|
|
|
| 156 |
<p class="text-xs text-mystic-400">Claimed @r.RedeemedAt.ToString("MMM dd, yyyy") · @r.PointCost.ToString("N0") pts</p>
|
| 157 |
</div>
|
| 158 |
</div>
|
| 159 |
+
<span class="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-bold bg-mystic-50 text-mystic-700 border border-mystic-200">
|
| 160 |
+
<span class="w-1.5 h-1.5 rounded-full bg-mystic-900 animate-pulse"></span>
|
| 161 |
Awaiting Fulfillment
|
| 162 |
</span>
|
| 163 |
</div>
|
BlazorFrontend/Components/Pages/UserInsights.razor
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@page "/Insights"
|
| 2 |
+
@using BlazorFrontend.Services
|
| 3 |
+
@using BlazorFrontend.Models.Dtos
|
| 4 |
+
@using Microsoft.AspNetCore.Authorization
|
| 5 |
+
@attribute [Authorize(Roles = "Librarian")]
|
| 6 |
+
@inject LibraryApiClient ApiClient
|
| 7 |
+
|
| 8 |
+
<PageTitle>User Insights</PageTitle>
|
| 9 |
+
|
| 10 |
+
<div class="mb-10 animate-in fade-in slide-in-from-top-4 duration-500">
|
| 11 |
+
<h1 class="text-4xl font-extrabold tracking-tight text-mystic-900 border-b border-mystic-100 pb-4 mb-2">User Insights</h1>
|
| 12 |
+
<p class="text-mystic-500 font-medium">Discover top-performing library members and engagement trends.</p>
|
| 13 |
+
</div>
|
| 14 |
+
|
| 15 |
+
@if (_isLoading)
|
| 16 |
+
{
|
| 17 |
+
<div class="py-20 flex flex-col items-center justify-center gap-4">
|
| 18 |
+
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-mystic-900"></div>
|
| 19 |
+
<p class="text-mystic-400 font-medium animate-pulse">Calculating insights...</p>
|
| 20 |
+
</div>
|
| 21 |
+
}
|
| 22 |
+
else
|
| 23 |
+
{
|
| 24 |
+
<!-- Tabs -->
|
| 25 |
+
<div class="flex p-1 bg-mystic-100 rounded-2xl mb-12 max-w-2xl mx-auto shadow-inner">
|
| 26 |
+
<button @onclick='() => _activeTab = "Subscribers"'
|
| 27 |
+
class='flex-1 py-3 px-6 rounded-xl text-sm font-bold transition-all @(_activeTab == "Subscribers" ? "bg-white text-mystic-900 shadow-sm" : "text-mystic-500 hover:text-mystic-700")'>
|
| 28 |
+
Top Subscribers
|
| 29 |
+
</button>
|
| 30 |
+
<button @onclick='() => _activeTab = "Loyalty"'
|
| 31 |
+
class='flex-1 py-3 px-6 rounded-xl text-sm font-bold transition-all @(_activeTab == "Loyalty" ? "bg-white text-mystic-900 shadow-sm" : "text-mystic-500 hover:text-mystic-700")'>
|
| 32 |
+
Top Loyalty
|
| 33 |
+
</button>
|
| 34 |
+
<button @onclick='() => _activeTab = "Active"'
|
| 35 |
+
class='flex-1 py-3 px-6 rounded-xl text-sm font-bold transition-all @(_activeTab == "Active" ? "bg-white text-mystic-900 shadow-sm" : "text-mystic-500 hover:text-mystic-700")'>
|
| 36 |
+
Most Active
|
| 37 |
+
</button>
|
| 38 |
+
</div>
|
| 39 |
+
|
| 40 |
+
<!-- Insight Content -->
|
| 41 |
+
<div class="animate-in fade-in zoom-in-95 duration-700">
|
| 42 |
+
@if (CurrentInsightData.Any())
|
| 43 |
+
{
|
| 44 |
+
<!-- Podium -->
|
| 45 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-8 items-end mb-16 max-w-5xl mx-auto px-4">
|
| 46 |
+
@* 2nd Place *@
|
| 47 |
+
@if (CurrentInsightData.Count() > 1)
|
| 48 |
+
{
|
| 49 |
+
var user = CurrentInsightData.ElementAt(1);
|
| 50 |
+
<div class="flex flex-col items-center animate-in slide-in-from-bottom-8 duration-700 delay-100">
|
| 51 |
+
<div class="relative mb-4">
|
| 52 |
+
<div class="w-24 h-24 rounded-2xl bg-mystic-100 border-2 border-mystic-200 flex items-center justify-center text-mystic-400 text-3xl font-black shadow-lg">
|
| 53 |
+
@(user.Name.Substring(0, Math.Min(2, user.Name.Length)).ToUpper())
|
| 54 |
+
</div>
|
| 55 |
+
<div class="absolute -top-3 -right-3 w-10 h-10 rounded-full bg-slate-300 border-4 border-white flex items-center justify-center text-white font-bold shadow-md">2</div>
|
| 56 |
+
</div>
|
| 57 |
+
<h3 class="text-lg font-bold text-mystic-900 text-center truncate w-full">@user.Name</h3>
|
| 58 |
+
<p class="text-mystic-500 font-bold text-sm">@user.ValueLabel</p>
|
| 59 |
+
<div class="mt-4 h-32 w-full bg-gradient-to-t from-mystic-100 to-transparent rounded-t-3xl border-x border-t border-mystic-200/50"></div>
|
| 60 |
+
</div>
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
@* 1st Place *@
|
| 64 |
+
@if (CurrentInsightData.Any())
|
| 65 |
+
{
|
| 66 |
+
var user = CurrentInsightData.ElementAt(0);
|
| 67 |
+
<div class="flex flex-col items-center relative z-10 animate-in slide-in-from-bottom-12 duration-700">
|
| 68 |
+
<div class="relative mb-6">
|
| 69 |
+
<div class="w-32 h-32 rounded-3xl bg-mystic-900 flex items-center justify-center text-white text-4xl font-black shadow-2xl ring-4 ring-mystic-900/10 scale-110">
|
| 70 |
+
@(user.Name.Substring(0, Math.Min(2, user.Name.Length)).ToUpper())
|
| 71 |
+
</div>
|
| 72 |
+
<div class="absolute -top-4 -right-4 w-12 h-12 rounded-full bg-mystic-900 border-4 border-white flex items-center justify-center text-white text-xl font-bold shadow-xl">1</div>
|
| 73 |
+
<div class="absolute -top-12 left-1/2 -translate-x-1/2 text-mystic-900 font-black tracking-tighter">
|
| 74 |
+
<svg class="w-10 h-10" fill="currentColor" viewBox="0 0 24 24"><path d="M5 16L3 5L8.5 10L12 4L15.5 10L21 5L19 16H5Z"></path></svg>
|
| 75 |
+
</div>
|
| 76 |
+
</div>
|
| 77 |
+
<h3 class="text-2xl font-black text-mystic-900 text-center truncate w-full">@user.Name</h3>
|
| 78 |
+
<p class="text-mystic-700 font-black text-lg">@user.ValueLabel</p>
|
| 79 |
+
<div class="mt-6 h-48 w-full bg-gradient-to-t from-mystic-200 to-transparent rounded-t-[2.5rem] border-x border-t border-mystic-300/30 shadow-2xl shadow-mystic-900/5"></div>
|
| 80 |
+
</div>
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
@* 3rd Place *@
|
| 84 |
+
@if (CurrentInsightData.Count() > 2)
|
| 85 |
+
{
|
| 86 |
+
var user = CurrentInsightData.ElementAt(2);
|
| 87 |
+
<div class="flex flex-col items-center animate-in slide-in-from-bottom-6 duration-700 delay-200">
|
| 88 |
+
<div class="relative mb-4">
|
| 89 |
+
<div class="w-20 h-20 rounded-2xl bg-mystic-50 border-2 border-mystic-100 flex items-center justify-center text-mystic-300 text-2xl font-black shadow-md">
|
| 90 |
+
@(user.Name.Substring(0, Math.Min(2, user.Name.Length)).ToUpper())
|
| 91 |
+
</div>
|
| 92 |
+
<div class="absolute -top-2 -right-2 w-8 h-8 rounded-full bg-mystic-500 border-4 border-white flex items-center justify-center text-white font-bold shadow-md">3</div>
|
| 93 |
+
</div>
|
| 94 |
+
<h3 class="text-base font-bold text-mystic-900 text-center truncate w-full">@user.Name</h3>
|
| 95 |
+
<p class="text-mystic-400 font-bold text-xs">@user.ValueLabel</p>
|
| 96 |
+
<div class="mt-4 h-24 w-full bg-gradient-to-t from-mystic-50 to-transparent rounded-t-2xl border-x border-t border-mystic-100/30"></div>
|
| 97 |
+
</div>
|
| 98 |
+
}
|
| 99 |
+
</div>
|
| 100 |
+
|
| 101 |
+
<!-- Full List Table -->
|
| 102 |
+
<div class="card overflow-hidden">
|
| 103 |
+
<div class="p-6 border-b border-mystic-100 bg-mystic-50/50">
|
| 104 |
+
<h3 class="text-lg font-bold text-mystic-900">Rankings Overview</h3>
|
| 105 |
+
</div>
|
| 106 |
+
<div class="overflow-x-auto">
|
| 107 |
+
<table class="w-full text-left border-collapse">
|
| 108 |
+
<thead>
|
| 109 |
+
<tr class="bg-white border-b border-mystic-100">
|
| 110 |
+
<th class="px-6 py-4 text-[10px] font-bold text-mystic-400 uppercase tracking-widest">Rank</th>
|
| 111 |
+
<th class="px-6 py-4 text-[10px] font-bold text-mystic-400 uppercase tracking-widest">Member</th>
|
| 112 |
+
<th class="px-6 py-4 text-[10px] font-bold text-mystic-400 uppercase tracking-widest">Performance</th>
|
| 113 |
+
<th class="px-6 py-4 text-[10px] font-bold text-mystic-400 uppercase tracking-widest text-right">Progress</th>
|
| 114 |
+
</tr>
|
| 115 |
+
</thead>
|
| 116 |
+
<tbody class="divide-y divide-mystic-100">
|
| 117 |
+
@foreach (var (user, index) in CurrentInsightData.Select((u, i) => (u, i)))
|
| 118 |
+
{
|
| 119 |
+
<tr class="hover:bg-mystic-50/50 transition-colors group">
|
| 120 |
+
<td class="px-6 py-5">
|
| 121 |
+
<div class='w-8 h-8 rounded-lg flex items-center justify-center text-sm font-black @(index == 0 ? "bg-mystic-900 text-white shadow-md" : index == 1 ? "bg-mystic-600 text-white" : index == 2 ? "bg-mystic-300 text-mystic-900" : "text-mystic-400")'>
|
| 122 |
+
#@(index + 1)
|
| 123 |
+
</div>
|
| 124 |
+
</td>
|
| 125 |
+
<td class="px-6 py-5">
|
| 126 |
+
<div class="flex items-center gap-3">
|
| 127 |
+
<div class="w-10 h-10 rounded-full bg-mystic-900/5 flex items-center justify-center text-mystic-600 font-bold text-xs border border-mystic-100">
|
| 128 |
+
@(user.Name.Substring(0, Math.Min(2, user.Name.Length)).ToUpper())
|
| 129 |
+
</div>
|
| 130 |
+
<div>
|
| 131 |
+
<p class="text-sm font-bold text-mystic-900 group-hover:text-mystic-600 transition-colors">@user.Name</p>
|
| 132 |
+
<p class="text-[10px] text-mystic-400 font-medium">Member since @user.JoinedDate.ToString("MMM yyyy")</p>
|
| 133 |
+
</div>
|
| 134 |
+
</div>
|
| 135 |
+
</td>
|
| 136 |
+
<td class="px-6 py-5">
|
| 137 |
+
<div class="flex flex-col">
|
| 138 |
+
<span class="text-sm font-extrabold text-mystic-900">@user.ValueLabel</span>
|
| 139 |
+
<span class="text-[10px] text-mystic-500 font-medium">Lifetime Achievement</span>
|
| 140 |
+
</div>
|
| 141 |
+
</td>
|
| 142 |
+
<td class="px-6 py-5">
|
| 143 |
+
<div class="w-full bg-mystic-100 h-1.5 rounded-full overflow-hidden max-w-[120px] ml-auto">
|
| 144 |
+
<div class="bg-mystic-900 h-full transition-all duration-1000"
|
| 145 |
+
style="width: @(CalculatePercentage(user.RawValue))%"></div>
|
| 146 |
+
</div>
|
| 147 |
+
</td>
|
| 148 |
+
</tr>
|
| 149 |
+
}
|
| 150 |
+
</tbody>
|
| 151 |
+
</table>
|
| 152 |
+
</div>
|
| 153 |
+
</div>
|
| 154 |
+
}
|
| 155 |
+
else
|
| 156 |
+
{
|
| 157 |
+
<div class="py-20 text-center bg-mystic-50 rounded-3xl border-2 border-dashed border-mystic-200">
|
| 158 |
+
<p class="text-mystic-400 font-medium italic">No data available for this insight yet.</p>
|
| 159 |
+
</div>
|
| 160 |
+
}
|
| 161 |
+
</div>
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
@code {
|
| 165 |
+
private bool _isLoading = true;
|
| 166 |
+
private string _activeTab = "Subscribers";
|
| 167 |
+
|
| 168 |
+
private List<InsightItem> _subscribers = new();
|
| 169 |
+
private List<InsightItem> _loyalty = new();
|
| 170 |
+
private List<InsightItem> _activeReaders = new();
|
| 171 |
+
|
| 172 |
+
private IEnumerable<InsightItem> CurrentInsightData => _activeTab switch
|
| 173 |
+
{
|
| 174 |
+
"Subscribers" => _subscribers,
|
| 175 |
+
"Loyalty" => _loyalty,
|
| 176 |
+
"Active" => _activeReaders,
|
| 177 |
+
_ => Enumerable.Empty<InsightItem>()
|
| 178 |
+
};
|
| 179 |
+
|
| 180 |
+
protected override async Task OnInitializedAsync()
|
| 181 |
+
{
|
| 182 |
+
await LoadInsightsAsync();
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
private async Task LoadInsightsAsync()
|
| 186 |
+
{
|
| 187 |
+
_isLoading = true;
|
| 188 |
+
try
|
| 189 |
+
{
|
| 190 |
+
var users = await ApiClient.GetUsersAsync();
|
| 191 |
+
var borrowings = await ApiClient.GetAllBorrowingsAsync();
|
| 192 |
+
var subscriptions = await ApiClient.GetAllSubscriptionsAsync();
|
| 193 |
+
var memberships = await ApiClient.GetMembershipsAsync();
|
| 194 |
+
var loyaltyHistory = await ApiClient.GetAllMembersPointsHistoryAsync();
|
| 195 |
+
|
| 196 |
+
// 1. Top Subscribers (Total Spent)
|
| 197 |
+
var membershipPriceMap = memberships.ToDictionary(m => m.Id, m => m.Price);
|
| 198 |
+
_subscribers = subscriptions
|
| 199 |
+
.GroupBy(s => s.UserId)
|
| 200 |
+
.Select(g => {
|
| 201 |
+
var user = users.FirstOrDefault(u => u.Id == g.Key);
|
| 202 |
+
var totalSpent = g.Sum(s => membershipPriceMap.TryGetValue(s.MembershipId, out var price) ? price : 0);
|
| 203 |
+
return new InsightItem {
|
| 204 |
+
UserId = g.Key,
|
| 205 |
+
Name = user?.FullName ?? "Unknown User",
|
| 206 |
+
JoinedDate = user?.CreatedAt ?? DateTime.MinValue,
|
| 207 |
+
RawValue = (double)totalSpent,
|
| 208 |
+
ValueLabel = $"MMK {totalSpent:N0}"
|
| 209 |
+
};
|
| 210 |
+
})
|
| 211 |
+
.OrderByDescending(i => i.RawValue)
|
| 212 |
+
.ToList();
|
| 213 |
+
|
| 214 |
+
// 2. Top Loyalty (Earned Points only)
|
| 215 |
+
_loyalty = loyaltyHistory
|
| 216 |
+
.Select(lh => {
|
| 217 |
+
var user = users.FirstOrDefault(u => u.Id == lh.UserId);
|
| 218 |
+
var totalEarned = lh.History.Where(h => h.PointDelta > 0).Sum(h => h.PointDelta);
|
| 219 |
+
return new InsightItem {
|
| 220 |
+
UserId = lh.UserId,
|
| 221 |
+
Name = user?.FullName ?? lh.UserName,
|
| 222 |
+
JoinedDate = user?.CreatedAt ?? DateTime.MinValue,
|
| 223 |
+
RawValue = totalEarned,
|
| 224 |
+
ValueLabel = $"{totalEarned:N0} Points"
|
| 225 |
+
};
|
| 226 |
+
})
|
| 227 |
+
.OrderByDescending(i => i.RawValue)
|
| 228 |
+
.ToList();
|
| 229 |
+
|
| 230 |
+
// 3. Most Active (Approved Returns only)
|
| 231 |
+
_activeReaders = borrowings
|
| 232 |
+
.Where(b => b.Status == "Returned")
|
| 233 |
+
.GroupBy(b => b.UserId)
|
| 234 |
+
.Select(g => {
|
| 235 |
+
var user = users.FirstOrDefault(u => u.Id == g.Key);
|
| 236 |
+
var count = g.Count();
|
| 237 |
+
return new InsightItem {
|
| 238 |
+
UserId = g.Key,
|
| 239 |
+
Name = user?.FullName ?? "Unknown User",
|
| 240 |
+
JoinedDate = user?.CreatedAt ?? DateTime.MinValue,
|
| 241 |
+
RawValue = count,
|
| 242 |
+
ValueLabel = $"{count} Completed"
|
| 243 |
+
};
|
| 244 |
+
})
|
| 245 |
+
.OrderByDescending(i => i.RawValue)
|
| 246 |
+
.ToList();
|
| 247 |
+
}
|
| 248 |
+
catch (Exception ex)
|
| 249 |
+
{
|
| 250 |
+
Console.WriteLine($"Error loading insights: {ex.Message}");
|
| 251 |
+
}
|
| 252 |
+
finally
|
| 253 |
+
{
|
| 254 |
+
_isLoading = false;
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
private double CalculatePercentage(double value)
|
| 259 |
+
{
|
| 260 |
+
var max = CurrentInsightData.Any() ? CurrentInsightData.Max(i => i.RawValue) : 1;
|
| 261 |
+
if (max == 0) return 0;
|
| 262 |
+
return (value / max) * 100;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
private class InsightItem
|
| 266 |
+
{
|
| 267 |
+
public Guid UserId { get; set; }
|
| 268 |
+
public string Name { get; set; } = "";
|
| 269 |
+
public DateTime JoinedDate { get; set; }
|
| 270 |
+
public double RawValue { get; set; }
|
| 271 |
+
public string ValueLabel { get; set; } = "";
|
| 272 |
+
}
|
| 273 |
+
}
|