dokonceni zobrazeni produktu
This commit is contained in:
@@ -1,33 +1,71 @@
|
|||||||
@page "/"
|
@page "/"
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using Web_Jarmark.Data
|
@using Web_Jarmark.Data
|
||||||
@using Web_Jarmark.Components.Pages.Shared
|
|
||||||
|
|
||||||
@using Web_Jarmark.Data.Models
|
@using Web_Jarmark.Data.Models
|
||||||
|
@using Web_Jarmark.Components.Pages.Shared
|
||||||
@inject ApplicationDbContext DbContext
|
@inject ApplicationDbContext DbContext
|
||||||
|
|
||||||
<h3>Katalog Produktů</h3>
|
<PageTitle>Školní jarmark | Katalog</PageTitle>
|
||||||
|
|
||||||
<main class="market-shell">
|
<main class="market-shell">
|
||||||
<div class="row">
|
<section class="market-heading">
|
||||||
<div class="market-grid">
|
<div>
|
||||||
|
<span class="market-eyebrow">ŠKOLNÍ JARMARK</span>
|
||||||
|
<h1>Objevte naše produkty</h1>
|
||||||
|
<p>Vyberte si z nabídky výrobků našich žáků.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="market-product-count">
|
||||||
|
@products.Count produktů
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
@if (isLoading)
|
||||||
|
{
|
||||||
|
<div class="market-empty">
|
||||||
|
Načítám produkty...
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else if (products.Count == 0)
|
||||||
|
{
|
||||||
|
<div class="market-empty">
|
||||||
|
<span>📦</span>
|
||||||
|
<h3>Zatím tu nejsou žádné produkty</h3>
|
||||||
|
<p>Produkty se zobrazí, jakmile budou přidány do katalogu.</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<section class="market-grid">
|
||||||
@foreach (var product in products)
|
@foreach (var product in products)
|
||||||
{
|
{
|
||||||
<ProductCard
|
<ProductCard @key="product.Id"
|
||||||
Product="product"
|
Product="product" OnAddToCart="HandleAddToCart" />
|
||||||
OnAddToCart="HandleAddToCart" />
|
}
|
||||||
|
</section>
|
||||||
}
|
}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private List<Product> products;
|
private List<Product> products = new();
|
||||||
|
private bool isLoading = true;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
products = await DbContext.Products
|
products = await DbContext.Products
|
||||||
.Include(p => p.Category)
|
.AsNoTracking()
|
||||||
|
.Include(product => product.Category)
|
||||||
|
.Where(product => product.IsVisible)
|
||||||
|
.OrderByDescending(product => product.UpdatedAt)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
private void HandleAddToCart(Product product)
|
private void HandleAddToCart(Product product)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Přidán produkt: {product.Name}");
|
Console.WriteLine($"Přidán produkt: {product.Name}");
|
||||||
|
|||||||
@@ -1,25 +1,39 @@
|
|||||||
@using Web_Jarmark.Data.Models
|
@using Web_Jarmark.Data.Models
|
||||||
|
|
||||||
<article class="market-card">
|
<article class="market-card">
|
||||||
|
|
||||||
<div class="market-product-picture">
|
<div class="market-product-picture">
|
||||||
|
@if (!string.IsNullOrWhiteSpace(Product.ImageUrl) && !imageFailed)
|
||||||
|
{
|
||||||
|
<img src="@Product.ImageUrl.Trim()"
|
||||||
|
alt="@Product.Name"
|
||||||
|
loading="lazy"
|
||||||
|
@onerror="HandleImageError" />
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
<span class="product-icon">@ProductIcon</span>
|
<span class="product-icon">@ProductIcon</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Product.Category is not null)
|
||||||
|
{
|
||||||
<span class="market-product-tag">
|
<span class="market-product-tag">
|
||||||
@Product.Category.Name
|
@Product.Category.Name
|
||||||
</span>
|
</span>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="market-card-content">
|
<div class="market-card-content">
|
||||||
|
|
||||||
<h3>@Product.Name</h3>
|
<h3>@Product.Name</h3>
|
||||||
|
|
||||||
|
@if (!string.IsNullOrWhiteSpace(Product.Description))
|
||||||
|
{
|
||||||
<p class="market-description">
|
<p class="market-description">
|
||||||
@Product.Category.Name
|
@Product.Description
|
||||||
</p>
|
</p>
|
||||||
|
}
|
||||||
|
|
||||||
<div class="market-stock">
|
<div class="market-stock">
|
||||||
<span class="market-stock-dot"></span>
|
<span class="market-stock-dot @(Product.StockQuantity <= 0 ? "out-of-stock" : "")"></span>
|
||||||
|
|
||||||
@if (Product.StockQuantity > 0)
|
@if (Product.StockQuantity > 0)
|
||||||
{
|
{
|
||||||
@@ -32,17 +46,19 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="market-card-bottom">
|
<div class="market-card-bottom">
|
||||||
<strong>@Product.Price.ToString("C")</strong>
|
<strong>@Product.Price.ToString("N0") Kč</strong>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="product-cart-button"
|
@if (OnAddToCart.HasDelegate)
|
||||||
|
{
|
||||||
|
<button type="button"
|
||||||
|
class="product-cart-button"
|
||||||
disabled="@(Product.StockQuantity <= 0)"
|
disabled="@(Product.StockQuantity <= 0)"
|
||||||
@onclick="AddToCart">
|
@onclick="AddToCart">
|
||||||
🛒 Do košíku
|
🛒 Do košíku
|
||||||
</button>
|
</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@@ -52,17 +68,32 @@
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<Product> OnAddToCart { get; set; }
|
public EventCallback<Product> OnAddToCart { get; set; }
|
||||||
|
|
||||||
|
private bool imageFailed;
|
||||||
|
|
||||||
|
protected override void OnParametersSet()
|
||||||
|
{
|
||||||
|
imageFailed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleImageError()
|
||||||
|
{
|
||||||
|
imageFailed = true;
|
||||||
|
}
|
||||||
|
|
||||||
private string ProductIcon =>
|
private string ProductIcon =>
|
||||||
Product.Category.Name.Contains("med",
|
Product.Category?.Name.Contains(
|
||||||
StringComparison.OrdinalIgnoreCase) ? "🍯" :
|
"med",
|
||||||
Product.Category.Name.Contains("cuk",
|
StringComparison.OrdinalIgnoreCase) == true ? "🍯" :
|
||||||
StringComparison.OrdinalIgnoreCase) ? "🍪" :
|
Product.Category?.Name.Contains(
|
||||||
Product.Category.Name.Contains("dřev",
|
"cuk",
|
||||||
StringComparison.OrdinalIgnoreCase) ? "🪵" : "🎁";
|
StringComparison.OrdinalIgnoreCase) == true ? "🍪" :
|
||||||
|
Product.Category?.Name.Contains(
|
||||||
|
"dřev",
|
||||||
|
StringComparison.OrdinalIgnoreCase) == true ? "🪵" :
|
||||||
|
"🎁";
|
||||||
|
|
||||||
private async Task AddToCart()
|
private async Task AddToCart()
|
||||||
{
|
{
|
||||||
await OnAddToCart.InvokeAsync(Product);
|
await OnAddToCart.InvokeAsync(Product);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2109,3 +2109,270 @@ textarea.wj-input {
|
|||||||
scroll-behavior: auto !important;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user