This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e978704
commit 0b146db
Showing
8 changed files
with
105 additions
and
22 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
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,24 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
branches: | ||
- main | ||
|
||
jobs: | ||
sonarcloud: | ||
name: SonarCloud | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: SonarCloud Scan | ||
uses: SonarSource/sonarcloud-github-action@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
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
36 changes: 36 additions & 0 deletions
36
ui/storefront/Views/Shared/Components/BasketButton/BasketButtonViewComponent.cs
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,36 @@ | ||
using System.Security.Claims; | ||
using Microsoft.AspNetCore.Mvc; | ||
using RookieShop.Storefront.Areas.Basket.Services; | ||
|
||
namespace RookieShop.Storefront.Views.Shared.Components.BasketButton; | ||
|
||
[ViewComponent] | ||
public sealed class BasketButtonViewComponent( | ||
IBasketService basketService, | ||
IHttpContextAccessor httpContextAccessor) : ViewComponent | ||
{ | ||
public async Task<IViewComponentResult> InvokeAsync() | ||
{ | ||
var context = httpContextAccessor.HttpContext!; | ||
var userId = httpContextAccessor.HttpContext?.User.FindFirstValue(ClaimTypes.NameIdentifier); | ||
|
||
int count; | ||
|
||
if (context.Items.TryGetValue("BasketCount", out var cachedCount)) return View((int)(cachedCount ?? 0)); | ||
|
||
try | ||
{ | ||
var basket = await basketService.GetBasketAsync(Guid.Parse(userId!)); | ||
|
||
count = basket.BasketDetails.Count; | ||
} | ||
catch (HttpRequestException) | ||
{ | ||
count = 0; | ||
} | ||
|
||
context.Items["BasketCount"] = count; | ||
|
||
return View(count); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
ui/storefront/Views/Shared/Components/BasketButton/Default.cshtml
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,15 @@ | ||
@model int | ||
|
||
<li> | ||
<a asp-area="Basket" asp-controller="Basket" asp-action="Index" class="flex items-center space-x-2 justify-center py-4 pr-2"> | ||
<div class="relative"> | ||
@if (Model > 0) | ||
{ | ||
<div class="t-0 absolute left-4"> | ||
<p class="flex h-2 w-2 items-center justify-center rounded-full bg-red-500 p-2 text-xs text-white">@Model</p> | ||
</div> | ||
} | ||
<img loading="lazy" class="mt-2 h-6 w-6" src="~/imgs/home/cart.svg" alt="Cart" asp-append-version="true"/> | ||
</div> | ||
</a> | ||
</li> |
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