aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/gallery/root.zig
blob: 7a06d5f86988a4d83190a4084715ee0f02fb049d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const std = @import("std");
const zilch = @import("zilch");
const Object = zilch.Object;
const components = @import("../root.zig");
const Image = components.Image;

const app = @import("root").app;

pub const component: zilch.Component = .build(.{
    .name = "gallery",
    .html = .parse(@embedFile("index.html")),
    .css = @embedFile("index.css"),
    .link = @This(),
});

const Self = @This();

element: *Object,
image: *Image,
body: *Object,

pub fn init(self: *Self, element: *Object) !void {
    var env: zilch.Env = .default;
    defer env.deinit();

    self.element = element;

    self.image = try std.heap.wasm_allocator.create(Image);
    var el = Image.component.new(self.image, &env);
    try self.image.init(try el.await(&env));

    var body = self.element.get(&env, "shadowRoot");

    var append_call = Object.call(body, &env, "append", .{self.image.element});
    append_call.ignore(&env);

    self.body = try body.await(&env, *Object);
}