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) public static void MapHtmxRoutes(this WebApplication app)
{ {
MapGetIndex(app); MapGetIndex(app);
MapGetGreet(app);
GetRegister(app); GetRegister(app);
PostRegister(app); PostRegister(app);
PostLogout(app); PostLogout(app);
+5 -3
View File
@@ -1,6 +1,8 @@
<div id="Greeting-$$GreetingId$$" class="greeting"> <div id="Greeting-$$GreetingId$$" class="greeting">
<h1>Hello, $$User$$!</h1> <h1>Hello, $$User$$!</h1>
<p>Welcome to high-performance htmx rendering.</p> <p class="pb-2">Welcome to high-performance htmx rendering.</p>
$$Separator$$
<button hx-get="/greet/$$User$$/$$Count$$/$$GreetingId$$" hx-target="#Greeting-$$GreetingId$$" hx-swap="outerHTML">Click to increase count $$Count$$</button> <div class="m-3">
$$CountButton$$
</div>
</div> </div>
+21 -9
View File
@@ -1,3 +1,4 @@
using Htmx.ApiDemo.Templates.Components;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -5,14 +6,25 @@ namespace Htmx.ApiDemo.Templates;
public sealed class Greeting : GreetingBase public sealed class Greeting : GreetingBase
{ {
private byte[] _userData = []; public required int Count { get; init; }
private byte[] _countData = []; public required string Username { get; init; }
private byte[] _greetingIdData = []; public required Guid GreetingId { get; init; }
public required string Username { init => _userData = value.ToUtf8Bytes(); }
public required int Count { init => _countData = $"{value}".ToUtf8Bytes(); }
public required Guid GreetingId { init => _greetingIdData = $"{value}".ToUtf8Bytes(); }
protected override void RenderCount(HtmxRenderContext context) => context.Writer.WriteUtf8(_countData); protected override void RenderCountButton(HtmxRenderContext context)
protected override void RenderGreetingId(HtmxRenderContext context) => context.Writer.WriteUtf8(_greetingIdData); {
protected override void RenderUser(HtmxRenderContext context) => context.Writer.WriteUtf8(_userData); 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.Http;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Htmx.ApiDemo.Templates; using Htmx.ApiDemo.Templates;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
namespace Htmx.ApiDemo; namespace Htmx.ApiDemo;
@@ -12,7 +14,13 @@ public static partial class RouteMap
var context = contextAccessor.HttpContext var context = contextAccessor.HttpContext
?? throw new InvalidOperationException("HttpContext is not available."); ?? 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( greet.HtmxAwareWriteToBody(
context: context, context: context,
title: "Home", title: "Home",
@@ -20,4 +28,26 @@ public static partial class RouteMap
pageTitle: "Home" 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 --> <!-- Sidebar footer -->
<div class="border-t border-border px-5 py-3 text-xs text-muted-foreground"> <div class="border-t border-border px-5 py-3 text-xs text-muted-foreground">
© 2026 $$AppName$$ © 2026 $$AppName$$ - Enciphered
</div> </div>
</aside> </aside>
<!-- ── /Sidebar ── --> <!-- ── /Sidebar ── -->
File diff suppressed because one or more lines are too long