improve Frontend

This commit is contained in:
Mika Kuns
2026-04-22 17:09:00 +02:00
parent 7de5510735
commit a4e313dbad
12 changed files with 437 additions and 12 deletions

View File

@@ -14,6 +14,13 @@ public sealed class TaskRepository
public async Task AddAsync(TaskEntity entity, CancellationToken ct = default)
{
// Append at bottom of the list by default: SortOrder = max(listId) + 1.
var maxSort = await _context.Tasks
.Where(t => t.ListId == entity.ListId)
.Select(t => (int?)t.SortOrder)
.MaxAsync(ct);
entity.SortOrder = (maxSort ?? -1) + 1;
_context.Tasks.Add(entity);
await _context.SaveChangesAsync(ct);
}
@@ -38,10 +45,32 @@ public sealed class TaskRepository
{
return await _context.Tasks
.Where(t => t.ListId == listId)
.OrderBy(t => t.CreatedAt)
.OrderBy(t => t.SortOrder).ThenBy(t => t.CreatedAt)
.ToListAsync(ct);
}
/// <summary>
/// Renumbers tasks in a list to 0..N-1 according to <paramref name="orderedTaskIds"/>.
/// Ids not belonging to the list are ignored; ids missing from the list are untouched.
/// </summary>
public async Task ReorderAsync(string listId, IReadOnlyList<string> orderedTaskIds, CancellationToken ct = default)
{
if (orderedTaskIds.Count == 0) return;
var idSet = orderedTaskIds.ToHashSet();
var tasks = await _context.Tasks
.Where(t => t.ListId == listId && idSet.Contains(t.Id))
.ToListAsync(ct);
for (int i = 0; i < orderedTaskIds.Count; i++)
{
var task = tasks.FirstOrDefault(t => t.Id == orderedTaskIds[i]);
if (task is not null) task.SortOrder = i;
}
await _context.SaveChangesAsync(ct);
}
// Kept for backwards-compatibility with callers using the old name.
public Task<List<TaskEntity>> GetByListAsync(string listId, CancellationToken ct = default)
=> GetByListIdAsync(listId, ct);
@@ -205,7 +234,7 @@ public sealed class TaskRepository
WHERE lt.list_id = t.list_id AND tg.name = 'agent'
)
)
ORDER BY t.created_at ASC
ORDER BY t.sort_order ASC, t.created_at ASC
LIMIT 1
)
RETURNING *