mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-20 18:49:33 -06:00
wip: server action
This commit is contained in:
parent
5dcbb21d66
commit
bf3aaadae0
@ -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"),
|
||||
|
||||
@ -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();
|
||||
|
||||
21
site/pages/examples/server-action/page.zx
Normal file
21
site/pages/examples/server-action/page.zx
Normal 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");
|
||||
Loading…
x
Reference in New Issue
Block a user