feat(search/rag): implement NexusSearchBox, dynamic Qdrant collection auto-provisioning, batch vector ingestion, mobile Serilog logging, and resolve 401 auth handler error (#51)
Resolves #52 This Pull Request introduces the **NexusSearchBox** search feature with premium unified styling, implements a robust **dynamic Qdrant collection auto-provisioning and batch-vector ingestion pipeline**, integrates a unified **Serilog logging infrastructure** for the Blazor Hybrid environment (MAUI), and resolves the **401 Unauthorized API header propagation error** inside mobile builds. ### 🚀 Key Implementations #### 1. Premium `NexusSearchBox` & Semantic Search UI * **NexusSearchBox Component:** Created an elegant search-as-you-type search box with smooth key navigation, quick-clearing, and seamless dynamic styling. * **Unified Aesthetics:** Refactored the search box isolated styling to align perfectly with the dashboard's design system using glassmorphism, `--nexus-neon` token gradients, and smooth pulse/fade animations. * **Semantic Search Integration:** Integrated semantic search query dispatching (`SearchLibrarySemanticallyQuery`) and wired up navigation seamlessly through the updated `ReaderNavigationService`. * **Tests Hardening:** Added/adapted query assertions in `QueryTests.cs` to guarantee safe parameterization and error boundary mapping. #### 2. Qdrant Collection Provisioning & Vector Ingestion * **Dynamic Auto-Provisioning:** Implemented dynamic checking and lazy-creation of the `knowledge_units` collection using 768 dimensions and Cosine distance. * **High-Performance Ingestion:** Optimized `ProcessKnowledgeUnitsAsync` with high-performance batch embedding generation using `_embeddingGenerator` and deterministic MD5 GUIDs for stable, duplicate-free upsertion. * **Database Cache Clear Sync:** Integrated Qdrant collection deletion in `ClearCacheAsync` to ensure absolute consistency between the PostgreSQL database cache and vector database indices. #### 3. Cross-Platform MAUI Logging (Serilog Infrastructure) * **Serilog Integration:** Configured cross-platform Serilog routing in `SerilogConfiguration.cs`, streaming diagnostic logs safely across native platforms and the Blazor Webview container. * **Interop Bridge:** Built `BlazorLoggingBridge.cs` to capture web console messages and pipe them directly to the native host logger. * **Demo Interface:** Added an interactive `SerilogDemo.razor` sandbox under Pages. #### 4. Resolving 401 Load Errors (Authentication Handler Flow) * **Authentication Header Handler:** Implemented the `MobileAuthenticationHeaderHandler` to correctly extract, validate, and inject bearer JWT tokens into outbound API requests. * **Configuration-based API Host:** Structured standard API URI routing to use clean configuration bindings in `appsettings.json`. --- ### 🧪 Verification & Build Status * Run `dotnet build` from the solution root: Successfully compiled the full multi-targeted solution (`Liczba błędów: 0`). * All unit and integration tests successfully executed and verified (`dotnet test`). --------- Co-authored-by: Marek Jasiński <jasins.marek@gmail.com> Co-authored-by: Marek Jaisński <jasins.marek@gmail.com> Reviewed-on: #51 Co-authored-by: Antigravity <antigravity@google.com> Co-committed-by: Antigravity <antigravity@google.com>
This commit was merged in pull request #51.
This commit is contained in:
@@ -2,9 +2,14 @@
|
||||
@using NexusReader.Application.Queries.Quiz
|
||||
@using NexusReader.Application.Commands.Quiz
|
||||
@using NexusReader.Application.Abstractions.Services
|
||||
@using NexusReader.UI.Shared.Components.Atoms
|
||||
@using NexusReader.UI.Shared.Services
|
||||
@inject IMediator Mediator
|
||||
@inject IPlatformService PlatformService
|
||||
@inject IQuizStateService QuizService
|
||||
@inject IIdentityService IdentityService
|
||||
@inject IKnowledgeGraphService GraphService
|
||||
@inject KnowledgeCoordinator Coordinator
|
||||
|
||||
<div class="knowledge-check">
|
||||
<div class="quiz-header">
|
||||
@@ -12,10 +17,33 @@
|
||||
<button class="expand-btn">⌵</button>
|
||||
</div>
|
||||
|
||||
@if (QuizService.IsHydrating)
|
||||
@if (QuizService.IsHydrating || _isGenerating)
|
||||
{
|
||||
<div class="loading-state shimmer">Skanowanie wiedzy przez AI...</div>
|
||||
}
|
||||
else if (_isSubmitted)
|
||||
{
|
||||
<div class="submitted-container">
|
||||
<div class="success-icon-wrapper">
|
||||
<NexusIcon Name="check" Size="48" Class="success-glow" />
|
||||
</div>
|
||||
<h3 class="submitted-title">Gratulacje!</h3>
|
||||
<p class="submitted-text">Sprawdzian zakończony pomyślnie. Twój wynik został zapisany w bazie danych.</p>
|
||||
|
||||
<div class="score-card">
|
||||
<div class="score-main">
|
||||
<span class="score-num">@_score</span>
|
||||
<span class="score-divider">/</span>
|
||||
<span class="score-total">@_totalQuestions</span>
|
||||
</div>
|
||||
<div class="score-percent">@((int)_percentage)% poprawnych odpowiedzi</div>
|
||||
</div>
|
||||
|
||||
<button class="reset-quiz-btn" @onclick="CloseQuiz">
|
||||
<span>ZAKOŃCZ</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
else if (QuizService.CurrentQuiz != null)
|
||||
{
|
||||
<div class="quiz-body">
|
||||
@@ -41,17 +69,45 @@
|
||||
}
|
||||
|
||||
<div class="quiz-footer">
|
||||
<button class="submit-btn" disabled="@(!AllQuestionsAnswered())">Wyślij</button>
|
||||
<button class="submit-btn" disabled="@(!AllQuestionsAnswered() || _isSubmitting)" @onclick="SubmitQuizAsync">
|
||||
@if (_isSubmitting)
|
||||
{
|
||||
<span>Zapisywanie...</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Wyślij</span>
|
||||
}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="empty-quiz-state">
|
||||
<div class="empty-icon-wrapper">
|
||||
<NexusIcon Name="robot" Size="48" Class="neon-glow" />
|
||||
</div>
|
||||
<h3 class="empty-title">Brak Aktywnego Quizu</h3>
|
||||
<p class="empty-text">Generuj spersonalizowany sprawdzian wiedzy na podstawie bieżącego rozdziału książki.</p>
|
||||
|
||||
<button class="generate-quiz-btn" @onclick="GenerateChapterQuizAsync" disabled="@(string.IsNullOrWhiteSpace(Coordinator.CurrentFullPageContent))">
|
||||
<span>GENERUJ QUIZ DLA ROZDZIAŁU</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter] public string ContextBlockId { get; set; } = string.Empty;
|
||||
|
||||
private Dictionary<QuizQuestionDto, (int SelectedIndex, bool IsCorrect)> _states = new();
|
||||
private bool _isSubmitting = false;
|
||||
private bool _isSubmitted = false;
|
||||
private bool _isGenerating = false;
|
||||
private int _score = 0;
|
||||
private int _totalQuestions = 0;
|
||||
private double _percentage = 0.0;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@@ -65,6 +121,24 @@
|
||||
QuizService.OnQuizUpdated -= HandleUpdate;
|
||||
}
|
||||
|
||||
private async Task GenerateChapterQuizAsync()
|
||||
{
|
||||
if (_isGenerating || string.IsNullOrWhiteSpace(Coordinator.CurrentFullPageContent)) return;
|
||||
|
||||
_isGenerating = true;
|
||||
StateHasChanged();
|
||||
|
||||
try
|
||||
{
|
||||
await Coordinator.RequestSummaryAndQuizAsync(Coordinator.CurrentFullPageContent);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isGenerating = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SelectOptionAsync(QuizQuestionDto question, int index)
|
||||
{
|
||||
if (_states.ContainsKey(question)) return;
|
||||
@@ -90,6 +164,67 @@
|
||||
return QuizService.CurrentQuiz != null && _states.Count == QuizService.CurrentQuiz.Questions.Count;
|
||||
}
|
||||
|
||||
private async Task SubmitQuizAsync()
|
||||
{
|
||||
if (QuizService.CurrentQuiz == null || !AllQuestionsAnswered() || _isSubmitting) return;
|
||||
|
||||
_isSubmitting = true;
|
||||
StateHasChanged();
|
||||
|
||||
try
|
||||
{
|
||||
_score = _states.Values.Count(s => s.IsCorrect);
|
||||
_totalQuestions = QuizService.CurrentQuiz.Questions.Count;
|
||||
_percentage = _totalQuestions > 0 ? ((double)_score / _totalQuestions) * 100 : 0.0;
|
||||
|
||||
string topic = "Quiz wiedzy";
|
||||
var graph = GraphService.CurrentGraphData;
|
||||
if (graph != null && !string.IsNullOrEmpty(QuizService.CurrentQuizBlockId))
|
||||
{
|
||||
var node = graph.Nodes.FirstOrDefault(n => n.Id == QuizService.CurrentQuizBlockId);
|
||||
if (node != null && !string.IsNullOrEmpty(node.Label))
|
||||
{
|
||||
topic = $"Test: {node.Label}";
|
||||
}
|
||||
}
|
||||
|
||||
var profileResult = await IdentityService.GetProfileAsync();
|
||||
if (profileResult.IsSuccess && profileResult.Value != null)
|
||||
{
|
||||
var userId = profileResult.Value.UserId;
|
||||
|
||||
var cmd = new SubmitQuizResultCommand(userId, topic, _score, _totalQuestions);
|
||||
var result = await Mediator.Send(cmd);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
IdentityService.ClearCache();
|
||||
_isSubmitted = true;
|
||||
await PlatformService.VibrateSuccessAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await PlatformService.VibrateErrorAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
await PlatformService.VibrateErrorAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSubmitting = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseQuiz()
|
||||
{
|
||||
_isSubmitted = false;
|
||||
_states.Clear();
|
||||
QuizService.SetQuiz(null, null);
|
||||
}
|
||||
|
||||
private string GetBlockClass(QuizQuestionDto question)
|
||||
{
|
||||
|
||||
@@ -121,3 +121,217 @@
|
||||
0% { background-position: -200% 0; }
|
||||
100% { background-position: 200% 0; }
|
||||
}
|
||||
|
||||
.option-revealed-correct {
|
||||
border-color: #00ff99 !important;
|
||||
background: rgba(0, 255, 153, 0.08) !important;
|
||||
box-shadow: 0 0 8px rgba(0, 255, 153, 0.15);
|
||||
}
|
||||
|
||||
.option-faded {
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
.submitted-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
padding: 2rem 1rem;
|
||||
animation: fadeIn 0.4s ease-out;
|
||||
}
|
||||
|
||||
.success-icon-wrapper {
|
||||
background: rgba(0, 255, 153, 0.1);
|
||||
border: 1px solid rgba(0, 255, 153, 0.3);
|
||||
border-radius: 50%;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 1.5rem;
|
||||
box-shadow: 0 0 20px rgba(0, 255, 153, 0.15);
|
||||
}
|
||||
|
||||
.success-glow {
|
||||
color: var(--nexus-neon, #00ff99);
|
||||
filter: drop-shadow(0 0 8px var(--nexus-neon, #00ff99));
|
||||
}
|
||||
|
||||
.submitted-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
margin-bottom: 0.5rem;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.submitted-text {
|
||||
font-size: 0.9rem;
|
||||
color: #888;
|
||||
margin-bottom: 2rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.score-card {
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||
border-radius: 16px;
|
||||
padding: 1.5rem 2.5rem;
|
||||
margin-bottom: 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.score-main {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.2rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.score-num {
|
||||
font-size: 3rem;
|
||||
font-weight: 800;
|
||||
color: var(--nexus-neon, #00ff99);
|
||||
line-height: 1;
|
||||
text-shadow: 0 0 15px rgba(0, 255, 153, 0.3);
|
||||
}
|
||||
|
||||
.score-divider {
|
||||
font-size: 1.8rem;
|
||||
color: #444;
|
||||
}
|
||||
|
||||
.score-total {
|
||||
font-size: 1.8rem;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.score-percent {
|
||||
font-size: 0.85rem;
|
||||
color: #666;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.reset-quiz-btn {
|
||||
padding: 0.8rem 3rem;
|
||||
background: transparent;
|
||||
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||
border-radius: 30px;
|
||||
color: #fff;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.reset-quiz-btn:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-color: #fff;
|
||||
box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.empty-quiz-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
padding: 2.5rem 1rem;
|
||||
animation: fadeIn 0.4s ease-out;
|
||||
}
|
||||
|
||||
.empty-icon-wrapper {
|
||||
background: rgba(0, 255, 153, 0.03);
|
||||
border: 1px solid rgba(0, 255, 153, 0.15);
|
||||
border-radius: 50%;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 1.5rem;
|
||||
box-shadow: 0 0 30px rgba(0, 255, 153, 0.05);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.empty-quiz-state:hover .empty-icon-wrapper {
|
||||
background: rgba(0, 255, 153, 0.08);
|
||||
border-color: rgba(0, 255, 153, 0.4);
|
||||
box-shadow: 0 0 35px rgba(0, 255, 153, 0.15);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.neon-glow {
|
||||
color: var(--nexus-neon, #00ff99);
|
||||
filter: drop-shadow(0 0 6px var(--nexus-neon, #00ff99));
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
margin-bottom: 0.5rem;
|
||||
letter-spacing: -0.3px;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 0.9rem;
|
||||
color: #888;
|
||||
margin-bottom: 2rem;
|
||||
line-height: 1.5;
|
||||
max-width: 280px;
|
||||
}
|
||||
|
||||
.generate-quiz-btn {
|
||||
padding: 0.85rem 2rem;
|
||||
background: rgba(0, 255, 153, 0.08);
|
||||
border: 1px solid var(--nexus-neon, #00ff99);
|
||||
border-radius: 30px;
|
||||
color: var(--nexus-neon, #00ff99);
|
||||
font-size: 0.85rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
letter-spacing: 0.8px;
|
||||
text-shadow: 0 0 10px rgba(0, 255, 153, 0.3);
|
||||
box-shadow: 0 0 15px rgba(0, 255, 153, 0.1);
|
||||
}
|
||||
|
||||
.generate-quiz-btn:not(:disabled):hover {
|
||||
background: var(--nexus-neon, #00ff99);
|
||||
color: #000;
|
||||
box-shadow: 0 0 25px rgba(0, 255, 153, 0.4);
|
||||
transform: translateY(-2px);
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
.generate-quiz-btn:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
border-color: rgba(255, 255, 255, 0.15);
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
color: #666;
|
||||
text-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user