From 66489a918fcfdb86a827dea44036f186ef391361 Mon Sep 17 00:00:00 2001 From: Marek Jarolimek Date: Fri, 6 Nov 2026 20:45:16 +0100 Subject: [PATCH] uprvaveni onfa kosik i v deteil vyrovku --- .../Components/Pages/DatailVyrobku.razor | 127 ++++++++++++++++++ Web-Jarmark/Web-Jarmark/jarmark.db-shm | Bin 32768 -> 32768 bytes Web-Jarmark/Web-Jarmark/jarmark.db-wal | Bin 313152 -> 321392 bytes 3 files changed, 127 insertions(+) diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/DatailVyrobku.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/DatailVyrobku.razor index 91574f6..7939a55 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/DatailVyrobku.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/DatailVyrobku.razor @@ -8,8 +8,18 @@ @inject IHttpContextAccessor HttpContextAccessor @inject PersistentComponentState ApplicationState +@implements IDisposable + Detail produktu +@if (showNotification) +{ +
+ ✓ + @notificationMessage +
+} + @if (loading) {

Načítám produkt...

@@ -65,6 +75,74 @@ else } + + @code { [Parameter] public int Id { get; set; } @@ -73,6 +151,11 @@ else private bool loading = true; private string? cartToken; + private bool showNotification; + private string notificationMessage = ""; + + private CancellationTokenSource? notificationCts; + protected override async Task OnInitializedAsync() { if (!ApplicationState.TryTakeFromJson( @@ -142,5 +225,49 @@ else cart.UpdatedAt = DateTime.UtcNow; await DbContext.SaveChangesAsync(); + + await ShowCartNotification(product.Name); + } + + private async Task ShowCartNotification(string productName) + { + notificationCts?.Cancel(); + + var currentCts = new CancellationTokenSource(); + notificationCts = currentCts; + + notificationMessage = $"{productName} byl přidán do košíku."; + showNotification = true; + + await InvokeAsync(StateHasChanged); + + try + { + await Task.Delay(3500, currentCts.Token); + + if (!currentCts.Token.IsCancellationRequested) + { + showNotification = false; + await InvokeAsync(StateHasChanged); + } + } + catch (OperationCanceledException) + { + // Nové přidání produktu restartovalo čas notifikace. + } + finally + { + if (ReferenceEquals(notificationCts, currentCts)) + { + notificationCts = null; + currentCts.Dispose(); + } + } + } + + public void Dispose() + { + notificationCts?.Cancel(); + notificationCts?.Dispose(); } } diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-shm b/Web-Jarmark/Web-Jarmark/jarmark.db-shm index f88b69aebaeaf8eaa2d0e5147182e58888535029..6eff4399771ff1d94a1033c8adff5079b4fb8196 100644 GIT binary patch delta 174 zcmZo@U}|V!s+V}A%K!q55G>#aq_u$9CAd>>;faQb;|5>(`=X}rv|PEs`~4c$2c)V8 z8U+SEK=MBlfC@7)_-t%6XWYDjkt=%hp%@(@M&Hc`8ILke-co4A=m%sTWZk@>Jb(iL DJ;ON+ delta 174 zcmZo@U}|V!s+V}A%K!pwK+MR%Am9U}wSYLcwc<{b?YDsA24DI6qNeX$-1KFBtM0yA zq^buR1qNO~@;?%Q3Nta7Z)`MY+