╭ changed ──────────────╮ │src/ui/Repo/Comment.zig│ ╰───────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────╮ │138 │ │139 pub const Item = struct { │ │140 box: wgt.Box(ui.Widget), │ │141 + id: [evt.event_id_size]u8, │ │142 + remove_button_id: ?usize, │ │143 │ │144 const metadata_index: usize = 0;│ │145 const body_index: usize = 1; │ ╰─────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │149 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, identity: []const u8, entry: CommentWithId) !Item {│ │150 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); │ │151 errdefer box.deinit(allocator); │ │152 + var remove_button_id: ?usize = null; │ │153 │ │154 { │ │155 var bar = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │167 errdefer reply.deinit(allocator); │ │168 try bar.children.put(allocator, reply.getFocus().id, .{ .widget = .{ .text_box = reply }, .rect = null, .min_size = .{ .width = "new reply".len + 2, .height = null } }); │ │169 │ │167 - var edit = try linkBox(allocator, session, "edit comment", ui.RoutablePage.repoCommentEditRoute(identity, &entry.comment.event.thread_id, &entry.id) orelse return error.RouteTooLong); │ │168 - errdefer edit.deinit(allocator); │ │169 - try bar.children.put(allocator, edit.getFocus().id, .{ .widget = .{ .text_box = edit }, .rect = null, .min_size = .{ .width = "edit comment".len + 2, .height = null } }); │ │170 + if (!entry.comment.removed) { │ │171 + var edit = try linkBox(allocator, session, "edit comment", ui.RoutablePage.repoCommentEditRoute(identity, &entry.comment.event.thread_id, &entry.id) orelse return error.RouteTooLong);│ │172 + errdefer edit.deinit(allocator); │ │173 + try bar.children.put(allocator, edit.getFocus().id, .{ .widget = .{ .text_box = edit }, .rect = null, .min_size = .{ .width = "edit comment".len + 2, .height = null } }); │ │174 + } │ │175 │ │176 var permalink = try linkBox(allocator, session, "permalink", ui.RoutablePage.repoCommentsRoute(identity, &entry.comment.event.thread_id, &entry.id, 0) orelse return error.RouteTooLong); │ │177 errdefer permalink.deinit(allocator); │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │195 try bar.children.put(allocator, parent.getFocus().id, .{ .widget = .{ .text_box = parent }, .rect = null, .min_size = .{ .width = @max(parent_text.len, " replying to ".len) + 2, .height = null } });│ │196 } │ │197 │ │198 + if (!entry.comment.removed and (session.data.is_local or session.data.user_id != null)) { │ │199 + const route = ui.RoutablePage.repoCommentsRoute(identity, &entry.comment.event.thread_id, &entry.id, 0) orelse return error.RouteTooLong; │ │200 + bar.getFocus().kind = .{ .custom = try std.fmt.allocPrint(session.page_arena.allocator(), "form:{s}/remove", .{try route.toUrl(session.page_arena)}) }; │ │201 + var remove = try wgt.TextBox(ui.Widget).init(allocator, "✕", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); │ │202 + errdefer remove.deinit(allocator); │ │203 + remove.getFocus().focusable = true; │ │204 + remove.getFocus().kind = .{ .custom = "submit" }; │ │205 + remove_button_id = remove.getFocus().id; │ │206 + try bar.children.put(allocator, remove.getFocus().id, .{ .widget = .{ .text_box = remove }, .rect = null, .min_size = .{ .width = 3, .height = null } }); │ │207 + } │ │208 + │ │209 bar.getFocus().child_id = bar.children.keys()[metadata_first_link_index]; │ │210 try box.children.put(allocator, bar.getFocus().id, .{ .widget = .{ .box = bar }, .rect = null, .min_size = null }); │ │211 } │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │212 │ │197 - const body_text = if (entry.comment.deleted) "(deleted)" else entry.comment.event.body; │ │213 + const body_text = if (entry.comment.removed) "(removed)" else entry.comment.event.body; │ │214 var body_box = try wgt.TextBox(ui.Widget).init(allocator, body_text, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .word });│ │215 errdefer body_box.deinit(allocator); │ │216 body_box.getFocus().focusable = true; │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────╮ │222 │ │223 box.getFocus().child_id = box.children.keys()[metadata_index]; │ │224 │ │209 - return .{ .box = box }; │ │225 + return .{ │ │226 + .box = box, │ │227 + .id = idBytes(&entry.id) orelse return error.InvalidEventId,│ │228 + .remove_button_id = remove_button_id, │ │229 + }; │ │230 } │ │231 │ │232 fn metadata(self: *Item) *wgt.Box(ui.Widget) { │ ╰─────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────╮ │239 │ │240 pub fn bodyFocused(self: *Item) bool { │ │241 return self.box.getFocus().child_id == self.body().getFocus().id;│ │242 + } │ │243 + │ │244 + pub fn removeFocused(self: *Item) bool { │ │245 + const id = self.remove_button_id orelse return false; │ │246 + return self.metadata().getFocus().child_id == id; │ │247 } │ │248 │ │249 pub fn focusMetadata(self: *Item, root_focus: *Focus) void { │ ╰──────────────────────────────────────────────────────────────────────────────╯