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 f88b69a..6eff439 100644
Binary files a/Web-Jarmark/Web-Jarmark/jarmark.db-shm and b/Web-Jarmark/Web-Jarmark/jarmark.db-shm differ
diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-wal b/Web-Jarmark/Web-Jarmark/jarmark.db-wal
index 319a5bb..edee014 100644
Binary files a/Web-Jarmark/Web-Jarmark/jarmark.db-wal and b/Web-Jarmark/Web-Jarmark/jarmark.db-wal differ