-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement shopping cart functionality and update layout
- Loading branch information
Showing
14 changed files
with
95 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,11 @@ | ||
namespace MicroCommerce.Web; | ||
|
||
public class CartService | ||
{ | ||
public List<GetProductsResponse.Product> CartItems { get; private set; } = new(); | ||
|
||
public void AddToCart(GetProductsResponse.Product product) | ||
{ | ||
CartItems.Add(product); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 3 additions & 15 deletions
18
code/src/MicroCommerce.Web/Components/Layout/MainLayout.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 0 additions & 78 deletions
78
code/src/MicroCommerce.Web/Components/Layout/MainLayout.razor.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
code/src/MicroCommerce.Web/Components/Layout/NavMenu.razor
This file was deleted.
Oops, something went wrong.
102 changes: 0 additions & 102 deletions
102
code/src/MicroCommerce.Web/Components/Layout/NavMenu.razor.css
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,22 @@ | ||
@page "/cart" | ||
@inject CartService CartService | ||
|
||
<h1 class="text-center my-4">Shopping Cart</h1> | ||
<div class="container"> | ||
<ul class="list-group"> | ||
@if (CartService.CartItems.Count > 0) | ||
{ | ||
@foreach (var item in CartService.CartItems) | ||
{ | ||
<li class="list-group-item d-flex justify-content-between align-items-center"> | ||
@item.Name | ||
<span class="badge bg-primary rounded-pill">$@item.Price</span> | ||
</li> | ||
} | ||
} | ||
else | ||
{ | ||
<p>Your cart is empty.</p> | ||
} | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,29 @@ | ||
@inject NavigationManager Navigation | ||
|
||
<div class="justify-content-end"> | ||
@if (true) | ||
{ | ||
<EditForm Model="this" FormName="checkout" OnSubmit="HandleCheckout" data-enhance> | ||
<button type="submit" class="align-content-end cart-button"> | ||
<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"> | ||
10 | ||
</i> | ||
</span> | ||
</button> | ||
</EditForm> | ||
} | ||
</div> | ||
|
||
@code { | ||
protected override async Task OnInitializedAsync() | ||
Check warning on line 20 in code/src/MicroCommerce.Web/Components/Shared/Cart.razor GitHub Actions / unit-tests
Check warning on line 20 in code/src/MicroCommerce.Web/Components/Shared/Cart.razor GitHub Actions / unit-tests
|
||
{ | ||
} | ||
|
||
private async Task HandleCheckout() | ||
Check warning on line 24 in code/src/MicroCommerce.Web/Components/Shared/Cart.razor GitHub Actions / unit-tests
Check warning on line 24 in code/src/MicroCommerce.Web/Components/Shared/Cart.razor GitHub Actions / unit-tests
|
||
{ | ||
// Preserve query string | ||
Navigation.NavigateTo($"/{new Uri(Navigation.Uri).Query}"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
code/src/MicroCommerce.Web/Components/Shared/ProductCard.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,17 @@ | ||
@using System.Globalization | ||
|
||
<div class="card mb-4 h-100"> | ||
<img src="images/@Product.ImageUrl" class="card-img-top" alt="@Product.Name"> | ||
<div class="card-body"> | ||
<h5 class="card-title">@Product.Name</h5> | ||
<p class="card-text">$@Product.Price.ToString("C", new CultureInfo("en-US"))</p> | ||
<button class="btn btn-primary" @onclick="() => AddToCart(Product)"> | ||
<i class="fas fa-cart-plus"></i> Add to Cart | ||
</button> | ||
</div> | ||
</div> | ||
|
||
@code { | ||
[Parameter] public required GetProductsResponse.Product Product { get; set; } | ||
[Parameter] public required Action<GetProductsResponse.Product> AddToCart { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 23,3 @@ public record Product | |
public string ImageUrl { get; set; } = ""; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.