feat: add sample data population for new users and improve exercise list layout
This commit is contained in:
@@ -29,6 +29,7 @@ internal static class UserProvisioning
|
|||||||
var created = new User { Id = userId };
|
var created = new User { Id = userId };
|
||||||
db.Users.Add(created);
|
db.Users.Add(created);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
await PopulateSampleDataAsync(db, created);
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,10 +45,63 @@ internal static class UserProvisioning
|
|||||||
var user = new User { Id = newId };
|
var user = new User { Id = newId };
|
||||||
db.Users.Add(user);
|
db.Users.Add(user);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
await PopulateSampleDataAsync(db, user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Populates a new user with sample exercises and routines for debugging.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="db">The application database context.</param>
|
||||||
|
/// <param name="user">The newly created user.</param>
|
||||||
|
private static async Task PopulateSampleDataAsync(AppDbContext db, User user)
|
||||||
|
{
|
||||||
|
// Sample exercises
|
||||||
|
var exercises = new[]
|
||||||
|
{
|
||||||
|
new Exercise { Name = "Push-ups", UserId = user.Id },
|
||||||
|
new Exercise { Name = "Squats", UserId = user.Id },
|
||||||
|
new Exercise { Name = "Pull-ups", UserId = user.Id },
|
||||||
|
new Exercise { Name = "Bench Press", UserId = user.Id },
|
||||||
|
new Exercise { Name = "Deadlift", UserId = user.Id }
|
||||||
|
};
|
||||||
|
|
||||||
|
db.Exercises.AddRange(exercises);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Sample routines
|
||||||
|
var routine1 = new Routine { Name = "Upper Body", UserId = user.Id };
|
||||||
|
var routine2 = new Routine { Name = "Lower Body", UserId = user.Id };
|
||||||
|
|
||||||
|
db.Routines.AddRange(routine1, routine2);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Associate exercises with routines
|
||||||
|
var pushUps = exercises.First(e => e.Name == "Push-ups");
|
||||||
|
var pullUps = exercises.First(e => e.Name == "Pull-ups");
|
||||||
|
var benchPress = exercises.First(e => e.Name == "Bench Press");
|
||||||
|
var squats = exercises.First(e => e.Name == "Squats");
|
||||||
|
var deadlift = exercises.First(e => e.Name == "Deadlift");
|
||||||
|
|
||||||
|
var routineExercises1 = new[]
|
||||||
|
{
|
||||||
|
new RoutineExercise { RoutineId = routine1.Id, ExerciseId = pushUps.Id, Order = 0 },
|
||||||
|
new RoutineExercise { RoutineId = routine1.Id, ExerciseId = pullUps.Id, Order = 1 },
|
||||||
|
new RoutineExercise { RoutineId = routine1.Id, ExerciseId = benchPress.Id, Order = 2 }
|
||||||
|
};
|
||||||
|
|
||||||
|
var routineExercises2 = new[]
|
||||||
|
{
|
||||||
|
new RoutineExercise { RoutineId = routine2.Id, ExerciseId = squats.Id, Order = 0 },
|
||||||
|
new RoutineExercise { RoutineId = routine2.Id, ExerciseId = deadlift.Id, Order = 1 }
|
||||||
|
};
|
||||||
|
|
||||||
|
db.RoutineExercises.AddRange(routineExercises1);
|
||||||
|
db.RoutineExercises.AddRange(routineExercises2);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether a user id matches the expected format.
|
/// Determines whether a user id matches the expected format.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -41,17 +41,19 @@
|
|||||||
<div class="list">
|
<div class="list">
|
||||||
@foreach (var exercise in ExerciseList)
|
@foreach (var exercise in ExerciseList)
|
||||||
{
|
{
|
||||||
<div class="list-item">
|
<div class="list-item" style="flex-direction: column; align-items: flex-start;">
|
||||||
@if (EditingId == exercise.Id)
|
@if (EditingId == exercise.Id)
|
||||||
{
|
{
|
||||||
<input class="input" @bind="EditingName" @bind:event="oninput" />
|
<input class="input" @bind="EditingName" @bind:event="oninput" />
|
||||||
<button class="primary" @onclick="() => SaveEditAsync(exercise.Id)">Save</button>
|
<div class="item-actions">
|
||||||
<button class="ghost" @onclick="CancelEdit">Cancel</button>
|
<button class="primary" @onclick="() => SaveEditAsync(exercise.Id)">Save</button>
|
||||||
|
<button class="ghost" @onclick="CancelEdit">Cancel</button>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<div class="item-title">@exercise.Name</div>
|
<div class="item-title" style="text-overflow: ellipsis; white-space: nowrap; overflow: hidden; width: 100%;">@exercise.Name</div>
|
||||||
<div class="actions">
|
<div class="item-actions">
|
||||||
<button class="ghost" @onclick="() => StartEdit(exercise)" aria-label="Edit exercise">✏️</button>
|
<button class="ghost" @onclick="() => StartEdit(exercise)" aria-label="Edit exercise">✏️</button>
|
||||||
<button class="ghost" @onclick="() => DeleteExerciseAsync(exercise.Id)" aria-label="Delete exercise">🗑️</button>
|
<button class="ghost" @onclick="() => DeleteExerciseAsync(exercise.Id)" aria-label="Delete exercise">🗑️</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user