Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions CulinaryCommandApp/Migrations/AppDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -911,18 +911,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime(6)");

b.Property<string>("ImageData")
.HasColumnType("longtext");

b.Property<bool>("IsSubRecipe")
.HasColumnType("bit(1)");

b.Property<int>("LocationId")
.HasColumnType("int");

b.Property<string>("PortionSize")
.HasMaxLength(128)
.HasColumnType("varchar(128)");

b.Property<string>("RecipeType")
.IsRequired()
Expand Down
6 changes: 0 additions & 6 deletions CulinaryCommandApp/Recipe/Entities/Recipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ public class Recipe

public bool IsSubRecipe { get; set; } = false;

[MaxLength(128)]
public string? PortionSize { get; set; }

// Base64-encoded image (no MaxLength → LONGTEXT in MySQL)
public string? ImageData { get; set; }

public DateTime? CreatedAt { get; set; }

// Optimistic concurrency token — backed by a MySQL timestamp(6) column
Expand Down
89 changes: 0 additions & 89 deletions CulinaryCommandApp/Recipe/Pages/RecipeForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -163,53 +163,6 @@ else {

<hr />

@* ---- Section: Recipe Image ---- *@
<h6 class="text-uppercase text-muted fw-semibold mb-3">Recipe Image</h6>

<div class="mb-4">
<div class="rf-image-card">
@if (!string.IsNullOrWhiteSpace(Model.ImageData))
{
<div class="rf-image-preview">
<img src="@Model.ImageData" alt="Recipe preview" class="rf-preview-img" />
<button type="button" class="rf-remove-img" @onclick="RemoveImage" title="Remove image">
<i class="bi bi-x-lg"></i>
</button>
</div>
}
else
{
<div class="rf-image-placeholder">
<i class="bi bi-image"></i>
<p>No image uploaded</p>
<p class="rf-upload-hint">JPG, PNG or WEBP · max 5 MB</p>
</div>
}
</div>
<InputFile id="recipeImageInput"
class="form-control mt-2"
accept="image/*"
OnChange="HandleImageUpload" />
@if (!string.IsNullOrWhiteSpace(_imageError))
{
<div class="text-danger small mt-1">@_imageError</div>
}
</div>

<hr />

@* ---- Section: Serving Info ---- *@
<h6 class="text-uppercase text-muted fw-semibold mb-3">Serving &amp; Nutrition</h6>

<div class="row mb-3">
<div class="col-md-6">
<label class="form-label fw-semibold">Portion Size</label>
<input class="form-control"
placeholder="e.g. 6 oz serving"
@bind="Model.PortionSize" />
</div>
</div>

<hr />

@* ---- Section 2: Ingredient Lines ----*@
Expand Down Expand Up @@ -451,9 +404,6 @@ else {
private bool _dataLoading;
private readonly SemaphoreSlim _loadSemaphore = new(1, 1);

// Image upload
private string? _imageError;

// Reference data
private List<string> _recipeTypes = new();
private List<string> _recipeCategories = new();
Expand Down Expand Up @@ -819,45 +769,6 @@ else {

private void Cancel() => Nav.NavigateTo("/recipes");

// *** Image upload ***

private async Task HandleImageUpload(InputFileChangeEventArgs e)
{
_imageError = null;
var file = e.File;

const long maxBytes = 5 * 1024 * 1024; // 5 MB
if (file.Size > maxBytes)
{
_imageError = "Image must be under 5 MB.";
return;
}

if (!file.ContentType.StartsWith("image/"))
{
_imageError = "Please select a valid image file.";
return;
}

try
{
using var ms = new System.IO.MemoryStream();
await using var stream = file.OpenReadStream(maxBytes);
await stream.CopyToAsync(ms);
var base64 = Convert.ToBase64String(ms.ToArray());
Model.ImageData = $"data:{file.ContentType};base64,{base64}";
}
catch
{
_imageError = "Failed to read the image. Please try again.";
}
}

private void RemoveImage()
{
Model.ImageData = null;
}

// *** View model for ingredient lines ***

private sealed class IngredientLineViewModel {
Expand Down
23 changes: 4 additions & 19 deletions CulinaryCommandApp/Recipe/Pages/RecipeView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,10 @@

@* Image card *@
<div class="rv-image-card">
@if (!string.IsNullOrWhiteSpace(recipe.ImageData))
{
<img src="@recipe.ImageData" alt="@recipe.Title" class="rv-image" />
}
else
{
<div class="rv-image-placeholder">
<i class="bi bi-image"></i>
<span>@recipe.Title</span>
</div>
}
<div class="rv-image-placeholder">
<i class="bi bi-image"></i>
<span>@recipe.Title</span>
</div>
</div>

@* Title *@
Expand Down Expand Up @@ -103,14 +96,6 @@
</span>
</li>
}
@if (!string.IsNullOrWhiteSpace(recipe.PortionSize))
{
<li>
<i class="bi bi-cup-hot"></i>
<span class="rv-meta-label">Portion</span>
<span class="rv-meta-value">@recipe.PortionSize</span>
</li>
}
</ul>


Expand Down
Loading