uprvaveni onfa kosik i v deteil vyrovku
This commit is contained in:
@@ -8,8 +8,18 @@
|
||||
@inject IHttpContextAccessor HttpContextAccessor
|
||||
@inject PersistentComponentState ApplicationState
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
<PageTitle>Detail produktu</PageTitle>
|
||||
|
||||
@if (showNotification)
|
||||
{
|
||||
<div class="cart-notification" role="status" aria-live="polite">
|
||||
<span class="notification-icon">✓</span>
|
||||
<span>@notificationMessage</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (loading)
|
||||
{
|
||||
<p>Načítám produkt...</p>
|
||||
@@ -65,6 +75,74 @@ else
|
||||
</div>
|
||||
}
|
||||
|
||||
<style>
|
||||
.cart-notification {
|
||||
position: fixed;
|
||||
top: 25px;
|
||||
right: 25px;
|
||||
z-index: 9999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 16px 22px;
|
||||
background: #ffffff;
|
||||
color: #222222;
|
||||
border: 1px solid #d9eadf;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
|
||||
font-size: 14px;
|
||||
font-weight: 650;
|
||||
animation: notification-in 0.25s ease-out, notification-out 1s ease-in 2.5s forwards;
|
||||
}
|
||||
|
||||
.notification-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 27px;
|
||||
height: 27px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 50%;
|
||||
background: #e2f7e9;
|
||||
color: #168344;
|
||||
font-size: 17px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
@@keyframes notification-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@keyframes notification-out {
|
||||
from {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 0;
|
||||
transform: translateY(-12px);
|
||||
}
|
||||
}
|
||||
|
||||
@@media (max-width: 500px) {
|
||||
.cart-notification {
|
||||
top: 15px;
|
||||
right: 12px;
|
||||
left: 12px;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@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<string>(
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user