From f42aaba9c095dc43785f2c5d8f06dd8b7c566282 Mon Sep 17 00:00:00 2001 From: maja Date: Fri, 30 Oct 2026 14:53:42 +0100 Subject: [PATCH] dokonceni zobrazeni produktu --- .../Components/Pages/Katalog.razor | 68 ++++- .../Components/Pages/Shared/ProductCard.razor | 81 ++++-- Web-Jarmark/Web-Jarmark/wwwroot/app.css | 267 ++++++++++++++++++ 3 files changed, 376 insertions(+), 40 deletions(-) diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Katalog.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Katalog.razor index d4601e0..c6d2531 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/Katalog.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Katalog.razor @@ -1,32 +1,70 @@ @page "/" @using Microsoft.EntityFrameworkCore @using Web_Jarmark.Data -@using Web_Jarmark.Components.Pages.Shared - @using Web_Jarmark.Data.Models +@using Web_Jarmark.Components.Pages.Shared @inject ApplicationDbContext DbContext -

Katalog Produktů

+Školní jarmark | Katalog +
-
-
- @foreach (var product in products) +
+
+ ŠKOLNÍ JARMARK +

Objevte naše produkty

+

Vyberte si z nabídky výrobků našich žáků.

+
+ +
+ @products.Count produktů +
+
+ + @if (isLoading) { - +
+ Načítám produkty... +
+ } + else if (products.Count == 0) + { +
+ 📦 +

Zatím tu nejsou žádné produkty

+

Produkty se zobrazí, jakmile budou přidány do katalogu.

+
+ } + else + { +
+ @foreach (var product in products) + { + + } +
} -
-
+ @code { - private List products; + private List products = new(); + private bool isLoading = true; protected override async Task OnInitializedAsync() { - products = await DbContext.Products - .Include(p => p.Category) - .ToListAsync(); + try + { + products = await DbContext.Products + .AsNoTracking() + .Include(product => product.Category) + .Where(product => product.IsVisible) + .OrderByDescending(product => product.UpdatedAt) + .ToListAsync(); + } + finally + { + isLoading = false; + } } private void HandleAddToCart(Product product) { diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Shared/ProductCard.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Shared/ProductCard.razor index dcc0f3a..3d9c630 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/Shared/ProductCard.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Shared/ProductCard.razor @@ -1,25 +1,39 @@ @using Web_Jarmark.Data.Models
-
- @ProductIcon + @if (!string.IsNullOrWhiteSpace(Product.ImageUrl) && !imageFailed) + { + @Product.Name + } + else + { + @ProductIcon + } - - @Product.Category.Name - + @if (Product.Category is not null) + { + + @Product.Category.Name + + }
-

@Product.Name

-

- @Product.Category.Name -

+ @if (!string.IsNullOrWhiteSpace(Product.Description)) + { +

+ @Product.Description +

+ }
- + @if (Product.StockQuantity > 0) { @@ -32,17 +46,19 @@
- @Product.Price.ToString("C") + @Product.Price.ToString("N0") Kč
- - + @if (OnAddToCart.HasDelegate) + { + + }
-
@code { @@ -52,17 +68,32 @@ [Parameter] public EventCallback OnAddToCart { get; set; } + private bool imageFailed; + + protected override void OnParametersSet() + { + imageFailed = false; + } + + private void HandleImageError() + { + imageFailed = true; + } + private string ProductIcon => - Product.Category.Name.Contains("med", - StringComparison.OrdinalIgnoreCase) ? "🍯" : - Product.Category.Name.Contains("cuk", - StringComparison.OrdinalIgnoreCase) ? "🍪" : - Product.Category.Name.Contains("dřev", - StringComparison.OrdinalIgnoreCase) ? "🪵" : "🎁"; + Product.Category?.Name.Contains( + "med", + StringComparison.OrdinalIgnoreCase) == true ? "🍯" : + Product.Category?.Name.Contains( + "cuk", + StringComparison.OrdinalIgnoreCase) == true ? "🍪" : + Product.Category?.Name.Contains( + "dřev", + StringComparison.OrdinalIgnoreCase) == true ? "🪵" : + "🎁"; private async Task AddToCart() { await OnAddToCart.InvokeAsync(Product); } } - diff --git a/Web-Jarmark/Web-Jarmark/wwwroot/app.css b/Web-Jarmark/Web-Jarmark/wwwroot/app.css index 9c9e75e..3874325 100644 --- a/Web-Jarmark/Web-Jarmark/wwwroot/app.css +++ b/Web-Jarmark/Web-Jarmark/wwwroot/app.css @@ -2109,3 +2109,270 @@ textarea.wj-input { scroll-behavior: auto !important; } } + +/* ===== KATALOG ===== */ + +.market-shell { + width: min(1250px, calc(100% - 40px)); + margin: 42px auto 70px; +} + +.market-heading { + display: flex; + justify-content: space-between; + align-items: end; + gap: 20px; + margin-bottom: 30px; +} + +.market-eyebrow { + color: #1769d2; + font-size: 11px; + font-weight: 800; + letter-spacing: 1.5px; +} + +.market-heading h1 { + margin: 8px 0; + color: #142b4a; + font-size: clamp(26px, 3vw, 36px); + font-weight: 800; + letter-spacing: -1px; +} + +.market-heading p { + margin: 0; + color: #718096; +} + +.market-product-count { + padding: 9px 14px; + border: 1px solid #e5eaf1; + border-radius: 10px; + background: #fff; + color: #52647b; + font-size: 13px; + white-space: nowrap; +} + +/* ===== PRODUKTOVÁ MØ͎KA ===== */ + +.market-grid { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 22px; +} + +/* ===== PRODUKTOVÁ KARTA ===== */ + +.market-card { + display: flex; + min-width: 0; + flex-direction: column; + overflow: hidden; + border: 1px solid #e5eaf1; + border-radius: 16px; + background: #fff; + box-shadow: 0 5px 20px rgba(20, 43, 74, .05); + transition: transform .2s ease, box-shadow .2s ease; +} + + .market-card:hover { + transform: translateY(-4px); + box-shadow: 0 12px 30px rgba(20, 43, 74, .12); + } + +/* ===== OBRÁZEK PRODUKTU ===== */ + +.market-product-picture { + position: relative; + display: flex; + align-items: center; + justify-content: center; + height: 220px; + margin: 12px 12px 0; + overflow: hidden; + border-radius: 11px; + background: #f3f6fb; +} + + .market-product-picture img { + display: block; + width: 100%; + height: 100%; + padding: 12px; + object-fit: contain; + transition: transform .25s ease; + } + +.market-card:hover .market-product-picture img { + transform: scale(1.05); +} + +.product-icon { + font-size: 65px; +} + +.market-product-tag { + position: absolute; + top: 10px; + left: 10px; + max-width: calc(100% - 20px); + overflow: hidden; + padding: 6px 10px; + border-radius: 7px; + background: #fff; + color: #142b4a; + font-size: 11px; + font-weight: 700; + text-overflow: ellipsis; + white-space: nowrap; +} + +/* ===== INFORMACE O PRODUKTU ===== */ + +.market-card-content { + display: flex; + flex: 1; + flex-direction: column; + padding: 17px; +} + +.market-card h3 { + margin: 0 0 8px; + color: #142b4a; + font-size: 17px; + font-weight: 750; + line-height: 1.4; +} + +.market-description { + display: -webkit-box; + min-height: 38px; + margin: 0 0 15px; + overflow: hidden; + color: #718096; + font-size: 13px; + line-height: 1.5; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; +} + +.market-stock { + display: flex; + align-items: center; + gap: 8px; + margin-top: auto; + color: #16834b; + font-size: 12px; + font-weight: 650; +} + +.market-stock-dot { + width: 8px; + height: 8px; + flex: 0 0 8px; + border-radius: 50%; + background: #20a464; +} + + .market-stock-dot.out-of-stock { + background: #d94b4b; + } + +.market-card-bottom { + margin: 17px 0 12px; +} + + .market-card-bottom strong { + color: #142b4a; + font-size: 23px; + font-weight: 850; + } + +/* ===== TLAÈÍTKO ===== */ + +.product-cart-button { + width: 100%; + min-height: 43px; + border: 0; + border-radius: 9px; + background: #1769d2; + color: #fff; + font-size: 14px; + font-weight: 750; + cursor: pointer; + transition: background .2s ease; +} + + .product-cart-button:hover:not(:disabled) { + background: #1055b0; + } + + .product-cart-button:disabled { + background: #aeb8c6; + cursor: not-allowed; + } + +/* ===== PRÁZDNÝ KATALOG ===== */ + +.market-empty { + padding: 65px 20px; + border: 1px dashed #ccd6e4; + border-radius: 16px; + background: #fff; + text-align: center; + color: #718096; +} + + .market-empty > span { + font-size: 42px; + } + + .market-empty h3 { + margin: 12px 0 6px; + color: #142b4a; + } + +/* ===== RESPONZIVITA ===== */ + +@media (max-width: 1050px) { + .market-grid { + grid-template-columns: repeat(3, minmax(0, 1fr)); + } +} + +@media (max-width: 750px) { + .market-shell { + width: calc(100% - 28px); + margin-top: 25px; + } + + .market-grid { + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 13px; + } + + .market-product-picture { + height: 165px; + } + + .market-card-content { + padding: 12px; + } + + .market-heading { + align-items: start; + flex-direction: column; + } +} + +@media (max-width: 420px) { + .market-grid { + grid-template-columns: 1fr; + } + + .market-product-picture { + height: 210px; + } +}