yavsc/src/Yavsc.Org/ViewComponents/CommentViewComponent.cs
Paul Schneider 15c64bbf7b Restore tree-structured comments in Blog Details
The $.psc.blogcomment widget (from the removed wwwroot/js/comment.js)
provided reply-to-comment nesting. Rewrite Details.cshtml to drive the
same /api/v1/blogcomments endpoint with ParentId, delegating reply
clicks so they work across the whole nested tree.

Render comment metadata server-side in the Comment view component
template (the widget used to add it client-side) and Include Author so
nested comments get their author instead of relying on the request-scoped
identity map.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-21 11:21:33 +01:00

36 lines
1.1 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using Yavsc.Models;
namespace Yavsc.ViewComponents
{
public class CommentViewComponent : ViewComponent
{
private readonly ApplicationDbContext context;
private readonly IStringLocalizer<CommentViewComponent> localizer;
public CommentViewComponent(IStringLocalizer<CommentViewComponent> localizer,
ApplicationDbContext context
)
{
this.context = context;
this.localizer = localizer;
}
public async Task<IViewComponentResult> InvokeAsync(long id)
{
var comment = await context.Comment
.Include(c => c.Children)
.Include(c => c.Author)
.FirstOrDefaultAsync(c => c.Id==id);
if (comment == null)
throw new InvalidOperationException();
ViewBag.apictlr = "/api/v1/blogcomments";
return View("Default", comment);
}
private string GetDebuggerDisplay()
{
return ToString();
}
}
}