wip: server action

This commit is contained in:
Nurul Huda (Apon) 2026-02-08 20:51:46 +06:00
parent 5dcbb21d66
commit bf3aaadae0
No known key found for this signature in database
GPG Key ID: 5D3F1DE2855A2F79
3 changed files with 23 additions and 2 deletions

View File

@ -92,7 +92,7 @@ pub fn build(b: *std.Build) !void {
.experimental_enabled_csr = true,
.copy_embedded_sources = true,
.steps = .{ .serve = "serve", .dev = "dev", .@"export" = "export", .bundle = "bundle" },
// .edge_path = b.path("site/edge.zig"),
.edge_path = b.path("site/edge.zig"),
.plugins = &.{
plugins.esbuild(b, .{
.bin = b.path("site/node_modules/.bin/esbuild"),

View File

@ -35,7 +35,7 @@ pub fn Page(ctx: zx.PageCtx(void, AuthState)) zx.Component {
);
}
fn handleAction(ctx: zx.PageCtx(void, @import("proxy.zig").AuthState)) void {
fn handleAction(ctx: zx.PageCtx(void, AuthState)) void {
if (ctx.request.method != .POST) return;
const fd = ctx.request.formData();

View File

@ -0,0 +1,21 @@
pub fn Page(ctx: zx.PageContext) zx.Component {
const allocator = ctx.arena;
return (
<div @{allocator}>
<form onsubmit={handleSubmit}>
<label>Username: <input type="text" name="username" required /></label>
<input type="submit" name="action" value="Login" />
</form>
</div>
);
}
// this should get added to server action registry maybe inside meta.zig as a list of functions, and when rendered on the client side the event handler is replaced with a stub that makes fetch call to the current page endpoint
// with autogenerated action id like we generate component id, the server than finds the actual server action and invokes it with the event data, and returns the result to the client
pub fn handleSubmit(ctx: zx.EventContext) void {
_ = ctx;
}
const zx = @import("zx");
const std = @import("std");