Refactor: Web Consolidation and Identity Stabilization (#40)
## Overview This PR completes the architectural consolidation of the web project and stabilizes the Identity-based authentication flow for the NexusReader application. It also refines the UI aesthetic for the Book Ingestion Modal as requested in #33. ## Key Changes - **Project Consolidation**: Fully merged `NexusReader.Web.New` into `NexusReader.Web`. This includes updating all namespace references, VS Code launch/task configurations, and CI/CD (`Dockerfile`). - **Identity Stabilization**: - Implemented `IIdentityService` on the server using `SignInManager<NexusUser>` and `UserManager<NexusUser>`. - Fixed registration logic to include mandatory fields (`SubscriptionPlanId`, `TenantId`). - Updated `Login.razor` to force a page reload on successful login, ensuring proper synchronization of authentication cookies between SignalR and the browser. - **UI/UX Refinement**: - Updated `BookIngestionModal` styling to follow the **Nexus Neon** design system. - Added premium button styles with hover effects and glows. - Improved modal layout and interaction feedback (shimmer effects, spinner colors). - **Cleanup**: Removed obsolete interfaces and constants that were superseded by newer Application layer implementations. ## Verification - Successfully built the solution: `dotnet build NexusReader.slnx --no-restore` - Verified project structure and file moves. - Validated server-side authentication logic. Fixes #33 --------- Co-authored-by: Marek Jasiński <jasins.marek@gmail.com> Reviewed-on: #40 Co-authored-by: Antigravity <antigravity@google.com> Co-committed-by: Antigravity <antigravity@google.com>
This commit was merged in pull request #40.
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using NexusReader.Application.Abstractions.Services
|
||||
@using NexusReader.Application.Queries.Reader
|
||||
@inject IEpubMetadataExtractor MetadataExtractor
|
||||
@inject ILogger<BookIngestionModal> Logger
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@if (IsOpen)
|
||||
{
|
||||
<div class="modal-backdrop" @onclick="CloseModal">
|
||||
<div class="modal-content glass-panel" @onclick:stopPropagation>
|
||||
<div class="modal-header">
|
||||
<h2>Add New Book</h2>
|
||||
<button class="close-btn" @onclick="CloseModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="parsing-state shimmer" style="@(IsParsing ? "display:flex;" : "display:none;")">
|
||||
<div class="shimmer-content">
|
||||
<div class="spinner"></div>
|
||||
<p>Scanning metadata...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="metadata-state" style="@(Metadata != null && !IsParsing ? "display:flex;" : "display:none;")">
|
||||
@if (Metadata != null)
|
||||
{
|
||||
<div class="metadata-info">
|
||||
<h3>@Metadata.Title</h3>
|
||||
<p class="author">@Metadata.Author</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn btn-primary">Confirm & Upload</button>
|
||||
<button class="btn btn-secondary" @onclick="Reset">Cancel</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="upload-state @(_isDragging ? "drag-over" : "")"
|
||||
style="@(!IsParsing && Metadata == null ? "display:flex;" : "display:none;")"
|
||||
@ondragenter="OnDragEnter"
|
||||
@ondragleave="OnDragLeave">
|
||||
<div class="drop-zone">
|
||||
<InputFile id="epub-upload" OnChange="HandleFileSelected" accept=".epub" class="file-input-cover" />
|
||||
<div class="drop-zone-content">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg>
|
||||
<p>Drag and drop your .epub file here</p>
|
||||
<span>or click to browse</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@if (!string.IsNullOrEmpty(ErrorMessage))
|
||||
{
|
||||
<div class="error-message">
|
||||
@ErrorMessage
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the modal is open.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool IsOpen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Event triggered when the IsOpen state changes.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<bool> IsOpenChanged { get; set; }
|
||||
|
||||
private bool _isDragging;
|
||||
private bool IsParsing { get; set; }
|
||||
private LocalEpubMetadata? Metadata { get; set; }
|
||||
private string? ErrorMessage { get; set; }
|
||||
|
||||
// Allow up to 50 MB
|
||||
private const long MaxFileSize = 50 * 1024 * 1024;
|
||||
|
||||
private async Task CloseModal()
|
||||
{
|
||||
IsOpen = false;
|
||||
Reset();
|
||||
await IsOpenChanged.InvokeAsync(false);
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
IsParsing = false;
|
||||
Metadata = null;
|
||||
ErrorMessage = null;
|
||||
_isDragging = false;
|
||||
}
|
||||
|
||||
private void OnDragEnter() => _isDragging = true;
|
||||
private void OnDragLeave() => _isDragging = false;
|
||||
|
||||
private async Task HandleFileSelected(InputFileChangeEventArgs e)
|
||||
{
|
||||
_isDragging = false;
|
||||
var file = e.File;
|
||||
|
||||
if (file == null) return;
|
||||
|
||||
if (!file.Name.EndsWith(".epub", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ErrorMessage = "Only .epub files are supported.";
|
||||
return;
|
||||
}
|
||||
|
||||
ErrorMessage = null;
|
||||
IsParsing = true;
|
||||
StateHasChanged();
|
||||
|
||||
try
|
||||
{
|
||||
using var stream = file.OpenReadStream(MaxFileSize);
|
||||
|
||||
// In Blazor WASM, we might need to copy to memory stream first for synchronous parsing if the parser doesn't stream well over interop
|
||||
using var memoryStream = new MemoryStream();
|
||||
await stream.CopyToAsync(memoryStream);
|
||||
memoryStream.Position = 0;
|
||||
|
||||
var result = await MetadataExtractor.ExtractMetadataAsync(memoryStream);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
Metadata = result.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = result.Errors.FirstOrDefault()?.Message ?? "Failed to parse EPUB.";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Error uploading EPUB");
|
||||
ErrorMessage = $"An unexpected error occurred: {ex.Message} \n {ex.StackTrace}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsParsing = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
// Cleanup if necessary
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user