Updated home page

This commit is contained in:
2026-05-05 20:38:02 +05:00
parent 22577fe3fb
commit aede9a796e
6 changed files with 2010 additions and 15 deletions
+1
View File
@@ -7,6 +7,7 @@ public static partial class RouteMap
public static void MapHtmxRoutes(this WebApplication app)
{
MapGetIndex(app);
MapGetGreet(app);
GetRegister(app);
PostRegister(app);
PostLogout(app);
+5 -3
View File
@@ -1,6 +1,8 @@
<div id="Greeting-$$GreetingId$$" class="greeting">
<h1>Hello, $$User$$!</h1>
<p>Welcome to high-performance htmx rendering.</p>
<button hx-get="/greet/$$User$$/$$Count$$/$$GreetingId$$" hx-target="#Greeting-$$GreetingId$$" hx-swap="outerHTML">Click to increase count $$Count$$</button>
<p class="pb-2">Welcome to high-performance htmx rendering.</p>
$$Separator$$
<div class="m-3">
$$CountButton$$
</div>
</div>
+21 -9
View File
@@ -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);
}
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Builder;
using Htmx.ApiDemo.Templates;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
namespace Htmx.ApiDemo;
@@ -12,7 +14,13 @@ public static partial class RouteMap
var context = contextAccessor.HttpContext
?? throw new InvalidOperationException("HttpContext is not available.");
var greet = new Greeting { Username = "Enciphered", Count = 0, GreetingId = Guid.NewGuid() };
var isAuthenticate = context.User.Identity?.IsAuthenticated ?? false;
var JohnDoe = "John Doe";
var claimedName = context.User.Claims.FirstOrDefault(c => c.Type == "DisplayName")?.Value ?? JohnDoe;
string name =
isAuthenticate && claimedName is not null ? claimedName : JohnDoe;
var greet = new Greeting { Username = name, Count = 0, GreetingId = Guid.NewGuid() };
greet.HtmxAwareWriteToBody(
context: context,
title: "Home",
@@ -20,4 +28,26 @@ public static partial class RouteMap
pageTitle: "Home"
);
});
private static void MapGetGreet(WebApplication app)
=> app.MapGet("/greet/{name}/{count}/{greetid}",
(
[FromRoute] string name,
[FromRoute] int count,
[FromRoute] string greetid,
[FromServices] IHttpContextAccessor contextAccessor
) =>
{
var context = contextAccessor.HttpContext
?? throw new InvalidOperationException("HttpContext is not available.");
var id = Guid.TryParse(greetid, out var parsedId) ? parsedId : Guid.NewGuid();
var greet = new Greeting { Username = name, Count = ++count, GreetingId = id };
greet.HtmxAwareWriteToBody(
context: context,
title: "Greet",
appName: "HtmxApp",
pageTitle: "Greet"
);
});
}
+1 -1
View File
@@ -55,7 +55,7 @@
<!-- Sidebar footer -->
<div class="border-t border-border px-5 py-3 text-xs text-muted-foreground">
© 2026 $$AppName$$
© 2026 $$AppName$$ - Enciphered
</div>
</aside>
<!-- ── /Sidebar ── -->
File diff suppressed because one or more lines are too long