Skip to content

Commit

Permalink
eShopLite: Don't checkout if no basket (#51)
Browse files Browse the repository at this point in the history
Fixes #36
  • Loading branch information
DamianEdwards authored Nov 29, 2023
1 parent ee04bd8 commit f304100
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions samples/eShopLite/eShopLite.Frontend/Components/Cart.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<span class="fa-stack fa-lg cart-stack pa-4">
<i class="fa fa-shopping-cart fa-stack-4x"></i>
<i class="fa fa-stack-1x badge">
@itemsInCart
@(customerBasket?.TotalItemCount ?? 0)
</i>
</span>
</button>
Expand All @@ -18,28 +18,25 @@
</div>

@code {
CustomerBasket? customerBasket;
bool basketIsAvailable;
int itemsInCart = 0;

[Parameter]
public EventCallback<bool> BasketAvailabilityChanged { get; set; }

protected override async Task OnInitializedAsync()
{
var (basket, isAvailable) = await BasketClient.GetBasketAsync("user");
(customerBasket, basketIsAvailable) = await BasketClient.GetBasketAsync("user");

if (basket is not null)
{
itemsInCart = basket.TotalItemCount;
}

basketIsAvailable = isAvailable;
await BasketAvailabilityChanged.InvokeAsync(basketIsAvailable);
}

private async Task HandleCheckout()
{
await BasketClient.CheckoutBasketAsync("user");
if (customerBasket is not null)
{
await BasketClient.CheckoutBasketAsync("user");
}

// Preserve query string
Navigation.NavigateTo($"/{new Uri(Navigation.Uri).Query}");
Expand Down

0 comments on commit f304100

Please sign in to comment.