From 907e19e3983681d282cc67dc31e2eef1a6ec6417 Mon Sep 17 00:00:00 2001 From: Francesco Lorenzo D'Amico Date: Tue, 27 May 2025 13:48:39 +0200 Subject: [PATCH] Make the code more readable and easier with some style --- .../_RecipeInstructionGridPartial.cshtml | 52 ++++++---------- Francesco.Recipes.World/wwwroot/css/site.css | 59 ++++++++++--------- 2 files changed, 48 insertions(+), 63 deletions(-) diff --git a/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml b/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml index ed4f682..c814599 100644 --- a/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml +++ b/Francesco.Recipes.World/Views/Shared/_RecipeInstructionGridPartial.cshtml @@ -4,44 +4,28 @@

Instructions

- @{ - var groupedInstructions = Model.Instructions.OrderBy(i => i.Number).ToList(); - var instructionRows = groupedInstructions - .Select((instruction, index) => new { Instruction = instruction, Index = index }) - .GroupBy(x => x.Index / 3) - .Select(g => g.Select(x => x.Instruction).ToList()) - .ToList(); - - foreach (var row in instructionRows) - { -
- @for (var instruction in row) + @foreach (var instruction in Model.Instructions.OrderBy(i => i.Number)) + { +
+
+ @if (instruction.MediaFiles != null && instruction.MediaFiles.Any()) { - var instruction = groupedInstructions[row * 3 + col]; -
-
- @if (instruction.MediaFiles != null && instruction.MediaFiles.Any()) - { - var mediaFile = instruction.MediaFiles.First(); - @if (mediaFile.Data != null && mediaFile.Data.Length > 0) - { - Step @instruction.Number - } - } - - else - { -
- -
- } - @instruction.Number -
-

@instruction.Description

+ var mediaFile = instruction.MediaFiles.First(); + if (mediaFile.Data != null && mediaFile.Data.Length > 0) + { + Step @instruction.Number + } + } + else + { +
+
} + @instruction.Number
- } +

@instruction.Description

+
}
diff --git a/Francesco.Recipes.World/wwwroot/css/site.css b/Francesco.Recipes.World/wwwroot/css/site.css index b8d4e75..c895bb3 100644 --- a/Francesco.Recipes.World/wwwroot/css/site.css +++ b/Francesco.Recipes.World/wwwroot/css/site.css @@ -89,38 +89,36 @@ textarea.form-control { /* Recipe Instructions Grid Layout */ .instructions-grid { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 1rem; margin-top: 2rem; margin-bottom: 2rem; } -.instruction-row { - display: flex; - justify-content: space-between; - margin-bottom: 2.5rem; - flex-wrap: wrap; -} - -.instruction-card { - width: calc(33.333% - 20px); - margin-bottom: 1.5rem; -} - @media (max-width: 992px) { - .instruction-card { - width: calc(50% - 15px); + .instructions-grid { + grid-template-columns: repeat(2, 1fr); } } @media (max-width: 576px) { - .instruction-card { - width: 100%; + .instructions-grid { + grid-template-columns: 1fr; } } +.instruction-card { + border: 1px solid #ccc; + padding: 1rem; + border-radius: 8px; + background-color: white; +} + .instruction-image { position: relative; width: 100%; - aspect-ratio: 1/1; + aspect-ratio: 1 / 1; border: 1px solid #ddd; border-radius: 4px; overflow: hidden; @@ -129,36 +127,38 @@ textarea.form-control { align-items: center; justify-content: center; background-color: #f8f9fa; + text-align: center; } .instruction-image img { width: 100%; height: 100%; object-fit: cover; + border-radius: 4px; } .placeholder-image { - display: flex; - align-items: center; - justify-content: center; width: 100%; height: 100%; - color: #aaa; + display: flex; + justify-content: center; + align-items: center; + font-size: 2rem; + color: #999; + background-color: #f0f0f0; + border-radius: 4px; } - .placeholder-image i { - font-size: 2rem; - } - .step-number { position: absolute; - bottom: 5px; - right: 10px; - background-color: rgba(0, 0, 0, 0.5); + bottom: 8px; + right: 8px; + background: rgba(0, 0, 0, 0.6); color: white; - font-weight: bold; padding: 3px 8px; border-radius: 50%; + font-size: 0.875rem; + font-weight: bold; } .instruction-text { @@ -183,3 +183,4 @@ textarea.form-control { background-color: #007bff; } +