Updated home page
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Htmx.ApiDemo.Templates.Components;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -5,14 +6,25 @@ namespace Htmx.ApiDemo.Templates;
|
||||
|
||||
public sealed class Greeting : GreetingBase
|
||||
{
|
||||
private byte[] _userData = [];
|
||||
private byte[] _countData = [];
|
||||
private byte[] _greetingIdData = [];
|
||||
public required string Username { init => _userData = value.ToUtf8Bytes(); }
|
||||
public required int Count { init => _countData = $"{value}".ToUtf8Bytes(); }
|
||||
public required Guid GreetingId { init => _greetingIdData = $"{value}".ToUtf8Bytes(); }
|
||||
public required int Count { get; init; }
|
||||
public required string Username { get; init; }
|
||||
public required Guid GreetingId { get; init; }
|
||||
|
||||
protected override void RenderCount(HtmxRenderContext context) => context.Writer.WriteUtf8(_countData);
|
||||
protected override void RenderGreetingId(HtmxRenderContext context) => context.Writer.WriteUtf8(_greetingIdData);
|
||||
protected override void RenderUser(HtmxRenderContext context) => context.Writer.WriteUtf8(_userData);
|
||||
protected override void RenderCountButton(HtmxRenderContext context)
|
||||
{
|
||||
var button = new Button(
|
||||
$"Click to increase count {Count}",
|
||||
"outline",
|
||||
hxAttrs: $"hx-get=\"/greet/{Username}/{Count}/{GreetingId}\"" +
|
||||
$" hx-target=\"#Greeting-{GreetingId}\" hx-swap=\"outerHTML\""
|
||||
);
|
||||
button.Render(context);
|
||||
}
|
||||
|
||||
protected override void RenderUser(HtmxRenderContext context)
|
||||
=> context.Writer.WriteUtf8(Username.ToUtf8Bytes());
|
||||
protected override void RenderGreetingId(HtmxRenderContext context)
|
||||
=> context.Writer.WriteUtf8(GreetingId.ToString().ToUtf8Bytes());
|
||||
protected override void RenderSeparator(HtmxRenderContext context)
|
||||
=> new Separator().Render(context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user