feat(ui): Hub Navigation, Profile Dashboard and Auth Stability Fixes (#31)

This PR implements the Hub Navigation system and the Profile Dashboard, while resolving critical session synchronization issues.

### Key Changes
- **Hub Navigation**: Introduced `MainHubLayout` with a premium glassmorphism sidebar, providing access to Dashboard, Library, Concepts Map, and Profile.
- **Profile Dashboard**: Implemented a high-fidelity Profile page (#27) with learning metrics, AI token usage tracking, and system rank visualization.
- **Stability Fixes**:
    - Resolved an infinite network loop on the `/profile` page by implementing request deduplication and in-memory caching in `IdentityService`.
    - Added environment-aware guards to prevent illegal JavaScript interop calls during server-side prerendering.
    - Implemented automatic session invalidation on `401 Unauthorized` responses to handle stale authentication states gracefully.
- **Reader Integration**: Added a "Return to Dashboard" option in the reader toolbar (#26).

Closes #26
Closes #27

Reviewed-on: #31
Co-authored-by: Marek Jasiński <jasins.marek@gmail.com>
Co-committed-by: Marek Jasiński <jasins.marek@gmail.com>
This commit was merged in pull request #31.
This commit is contained in:
2026-05-10 17:36:35 +00:00
committed by Marek Jaisński
parent 34794db209
commit 2e23a032d3
56 changed files with 4292 additions and 481 deletions
@@ -1,4 +1,5 @@
@page "/account/profile"
@page "/profile"
@using Microsoft.AspNetCore.Authorization
@using NexusReader.UI.Shared.Services
@using NexusReader.UI.Shared.Components.Atoms
@@ -6,96 +7,102 @@
@inject IIdentityService IdentityService
@inject NavigationManager NavigationManager
<div class="profile-dashboard">
<div class="profile-page-container">
<div class="background-radial"></div>
<div class="mesh-overlay"></div>
@if (_profile == null)
{
<div class="loading-overlay">
<div class="loading-state">
<div class="nexus-loader"></div>
<p>Ładowanie Twojego profilu...</p>
<p>Ładowanie systemu...</p>
</div>
}
else
{
<div class="dashboard-content">
<header class="dashboard-header">
<div class="user-meta">
<div class="user-avatar">
<div class="profile-content">
<!-- Identity Section -->
<section class="identity-section">
<div class="avatar-container">
<div class="avatar-glow"></div>
<div class="avatar-inner">
@(_profile.Email[0].ToString().ToUpper())
</div>
<div class="user-info">
<h1>@_profile.Email</h1>
<div class="plan-info">
<span class="badge @(_profile.CurrentPlan.ToLower())">@_profile.CurrentPlan Plan</span>
<span class="tenant-id">ID: @_profile.TenantId.ToString()[..8]...</span>
</div>
</div>
</div>
<div class="header-actions">
<button class="btn-logout" @onclick="HandleLogout">
<NexusIcon Name="lock" Size="16" />
Wyloguj się
</button>
<div class="user-titles">
<h1 class="username">@_profile.Email.Split('@')[0]</h1>
<span class="system-rank">[Nexus_Explorer_@(_profile.TenantId.ToString()[..4])]</span>
</div>
</header>
</section>
<div class="stats-grid">
<!-- AI Token Card -->
<div class="stat-card usage-card">
<div class="card-icon">
<NexusIcon Name="robot" Size="24" />
<!-- Metrics Grid -->
<div class="metrics-grid">
<!-- Intelligence Card -->
<div class="metric-card glass-panel">
<div class="card-header">
<NexusIcon Name="robot" Size="24" Color="var(--nexus-neon)" />
<h3>Interfejs AI</h3>
</div>
<div class="card-info">
<h3>Wykorzystanie AI</h3>
<div class="token-numbers">
<span class="tokens-used">@_profile.AITokensUsed</span>
<span class="tokens-limit">/ @_profile.AITokenLimit tokenów</span>
<div class="card-body">
<div class="token-usage">
<div class="usage-values">
<span class="current">@_profile.AITokensUsed</span>
<span class="separator">/</span>
<span class="total">@_profile.AITokenLimit</span>
</div>
<div class="usage-progress">
<div class="progress-bar" style="width: @(CalculateProgress())%"></div>
</div>
</div>
<div class="usage-bar">
<div class="usage-fill" style="width: @(CalculateProgress())%"></div>
</div>
<p class="usage-desc">Limit odnawia się w następnym cyklu rozliczeniowym.</p>
<span class="metric-label">Wykorzystane Jednostki Mocy</span>
</div>
</div>
<!-- Learning Progress Card -->
<div class="stat-card learning-card">
<div class="card-icon">
<NexusIcon Name="mail" Size="24" />
<!-- Sync Card -->
<div class="metric-card glass-panel">
<div class="card-header">
<NexusIcon Name="activity" Size="24" Color="var(--nexus-neon)" />
<h3>Wydajność Nauki</h3>
</div>
<div class="card-info">
<h3>Aktywna Nauka</h3>
<div class="learning-metrics">
<div class="metric">
<span class="label">Średni wynik quizów</span>
<span class="value">@_profile.AverageQuizScore%</span>
</div>
<div class="metric">
<span class="label">Ostatnio czytane</span>
<span class="value truncate">@_profile.LastReadBookTitle</span>
</div>
<div class="card-body">
<div class="score-display">
<span class="score-value">@_profile.AverageQuizScore%</span>
<span class="score-label">Średni Wynik Asymilacji</span>
</div>
<div class="last-book">
<NexusIcon Name="book-open" Size="14" />
<span class="truncate">@_profile.LastReadBookTitle</span>
</div>
</div>
</div>
<!-- Account Status Card -->
<div class="metric-card glass-panel full-width">
<div class="card-header">
<NexusIcon Name="shield" Size="24" Color="var(--nexus-neon)" />
<h3>Status Autoryzacji</h3>
</div>
<div class="card-body status-layout">
<div class="status-info">
<span class="plan-badge @(_profile.CurrentPlan.ToLower())">@_profile.CurrentPlan Protocol</span>
<span class="tenant-tag">Node: @_profile.TenantId.ToString().ToUpper()</span>
</div>
<div class="profile-actions">
<button class="btn-nexus secondary" @onclick="HandleUpgrade">Zarządzaj Subskrypcją</button>
<button class="btn-nexus logout" @onclick="HandleLogout">
<NexusIcon Name="log-out" Size="18" />
Wyloguj
</button>
</div>
</div>
</div>
</div>
<section class="subscription-section">
<div class="section-card">
<div class="section-info">
<h2>Zarządzaj subskrypcją</h2>
<p>Zmień swój plan, aby zwiększyć limit tokenów AI i odblokować funkcje premium.</p>
</div>
<button class="btn-upgrade" @onclick="HandleUpgrade">
Przejdź do panelu płatności
</button>
</div>
</section>
</div>
}
<div class="decoration-star top-left">✦</div>
<div class="decoration-star bottom-right">✦</div>
<div class="decoration decoration-top">NXS-SYS-v10</div>
<div class="decoration decoration-bottom">IDENTITY-CORE-ENCRYPTED</div>
</div>
@code {
@@ -103,7 +110,12 @@
protected override async Task OnInitializedAsync()
{
_profile = await IdentityService.GetProfileAsync();
var result = await IdentityService.GetProfileAsync();
if (result.IsSuccess)
{
_profile = result.Value;
}
StateHasChanged();
}
private int CalculateProgress()