feat: quick actions on email rows (read/unread, star, trash)
- EmailRow shared component with hover action buttons: mark read/unread, star/unstar, trash
- Optimistic UI — local state patches immediately on click; row fades and becomes non-interactive during the API call
- Trashed rows disappear from the current folder view via onRemove callback
- Backend: EmailController single-email endpoints (POST /email/{id}/read|unread|star|unstar|trash|untrash)
- Star/Unstar added to CleanupActionType enum and CleanupService (maps to STARRED Gmail label via BatchModifyAsync)
- UserId scope enforced in ResolveTargetsAsync — a user can only act on their own emails
- action buttons use stopPropagation so clicking them does not open Gmail
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using InboxIntel.Application.Abstractions;
|
||||
using InboxIntel.Application.DTOs;
|
||||
using InboxIntel.Domain.Enums;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace InboxIntel.Api.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Single-email quick actions. All writes are scoped to the authenticated user's
|
||||
/// UserId so one user cannot mutate another user's email.
|
||||
/// Read/star are non-destructive and execute without confirmation.
|
||||
/// Trash is reversible and also executes without a separate confirm step —
|
||||
/// the single-email context makes the intent unambiguous.
|
||||
/// </summary>
|
||||
public class EmailController : ApiControllerBase
|
||||
{
|
||||
private readonly ICleanupService _cleanup;
|
||||
public EmailController(ICleanupService cleanup) => _cleanup = cleanup;
|
||||
|
||||
[HttpPost("{id:guid}/read")]
|
||||
public Task<IActionResult> MarkRead(Guid id, CancellationToken ct) => Act(id, CleanupActionType.MarkRead, ct);
|
||||
|
||||
[HttpPost("{id:guid}/unread")]
|
||||
public Task<IActionResult> MarkUnread(Guid id, CancellationToken ct) => Act(id, CleanupActionType.MarkUnread, ct);
|
||||
|
||||
[HttpPost("{id:guid}/star")]
|
||||
public Task<IActionResult> Star(Guid id, CancellationToken ct) => Act(id, CleanupActionType.Star, ct);
|
||||
|
||||
[HttpPost("{id:guid}/unstar")]
|
||||
public Task<IActionResult> Unstar(Guid id, CancellationToken ct) => Act(id, CleanupActionType.Unstar, ct);
|
||||
|
||||
[HttpPost("{id:guid}/trash")]
|
||||
public Task<IActionResult> Trash(Guid id, CancellationToken ct) => Act(id, CleanupActionType.Trash, ct);
|
||||
|
||||
[HttpPost("{id:guid}/untrash")]
|
||||
public Task<IActionResult> Untrash(Guid id, CancellationToken ct) => Act(id, CleanupActionType.Archive, ct);
|
||||
|
||||
private async Task<IActionResult> Act(Guid id, CleanupActionType action, CancellationToken ct)
|
||||
{
|
||||
var req = new CleanupRequestDto(action, new[] { id }, null, null, Confirmed: true);
|
||||
var result = await _cleanup.ExecuteAsync(UserId, req, ct);
|
||||
return result.Succeeded ? Ok() : BadRequest(new { error = result.Error });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user