Checkout page clean up
continuous-integration/drone/pr Build is passing

This commit is contained in:
Khwezi Mngoma
2026-06-16 21:12:12 +02:00
parent 554741c2e5
commit 5d614d2a94
5 changed files with 630 additions and 79 deletions
@@ -204,7 +204,7 @@
</li>
<li><hr class="dropdown-divider m-0" /></li>
<li>
<a class="dropdown-item p-2.5 font-monospace text-uppercase text-danger d-flex align-items-center gap-2" href="/logout">
<a class="dropdown-item p-2.5 font-monospace text-uppercase text-danger d-flex align-items-center gap-2" href="javascript:void(0)" @onclick:preventDefault @onclick="HandleLogout">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path>
<polyline points="16 17 21 12 16 7"></polyline>
@@ -216,15 +216,15 @@
</Authorized>
<NotAuthorized>
<li>
<a class="dropdown-item p-2.5 font-monospace text-uppercase text-dark d-flex align-items-center gap-2" href="/login">
<a class="dropdown-item p-2.5 font-monospace text-uppercase text-dark d-flex align-items-center gap-2" href="javascript:void(0)" @onclick:preventDefault @onclick="HandleLogin">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h4"></path><polyline points="10 17 15 12 10 7"></polyline><line x1="15" y1="12" x2="3" y2="12"></line></svg>
Sign In
</a>
</li>
<li>
<a class="dropdown-item p-2.5 font-monospace text-uppercase text-muted d-flex align-items-center gap-2" href="/account">
<a class="dropdown-item p-2.5 font-monospace text-uppercase text-muted d-flex align-items-center gap-2" href="javascript:void(0)" @onclick:preventDefault @onclick="RedirectToAccount">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
Order Status
Order History
</a>
</li>
</NotAuthorized>
@@ -5,15 +5,10 @@ namespace MidrandBookshop.Components.Layout;
public partial class MainLayout(CartService cartService) : IDisposable
{
[Inject] private AuthenticationStateProvider AuthStateProvider { get; set; } = default!;
[Inject] public IToastService ToastService { get; set; } = default!;
private Cart ShoppingCart => cartService.ShoppingCart;
private AuthenticationState? AuthState { get; set; }
private ClaimsPrincipal? User { get; set; }
private bool IsAuthenticated => User?.Identity?.IsAuthenticated ?? false;
private string SearchInputBuffer { get; set; } = string.Empty;
private string GlobalSearchQuery { get; set; } = string.Empty;
private bool IsSearchActive { get; set; } = false;
@@ -21,13 +16,11 @@ public partial class MainLayout(CartService cartService) : IDisposable
protected override async Task OnInitializedAsync()
{
AuthState = await AuthStateProvider.GetAuthenticationStateAsync();
User = AuthState!.User;
Navigation.LocationChanged += OnLocationChanged;
cartService.OnCartChanged += CartService_OnCartChanged;
await cartService.LoadCartFromStorageAsync();
if (cartService.ShoppingCart.Items.Count == 0)
await cartService.LoadCartFromStorageAsync();
SyncSearchQueryFromUrl();
}
@@ -122,16 +115,49 @@ public partial class MainLayout(CartService cartService) : IDisposable
private decimal GetCartTotal() => ShoppingCart?.TotalAmount ?? 0.00m;
private void RedirectToCart()
private async Task RedirectToCart()
{
IsCartOpen = false;
await cartService.SaveCartToStorageAsync();
Navigation.NavigateTo("/cart");
}
private void RedirectToCheckout()
private async Task RedirectToCheckout()
{
IsCartOpen = false;
Navigation.NavigateTo("/checkout");
await cartService.SaveCartToStorageAsync();
Navigation.NavigateTo("/checkout", forceLoad: true);
}
private async Task RedirectToAccount()
{
IsCartOpen = false;
await cartService.SaveCartToStorageAsync();
Navigation.NavigateTo("/account", forceLoad: true);
}
private async Task HandleLogin()
{
IsCartOpen = false;
await cartService.SaveCartToStorageAsync();
Navigation.NavigateTo("/login", forceLoad: true);
}
private async Task HandleLogout()
{
IsCartOpen = false;
await cartService.SaveCartToStorageAsync();
Navigation.NavigateTo("/logout", forceLoad: true);
}
public void Dispose()