╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Comment.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
299 // append one comment's metadata bar and body. 300 pub fn appendComment(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), session: *ui.Session, identity: []const u8, thread_kind: evt.EventKind, can_reply: bool, entry: CommentWithId) !void { 301 var item = try Item.init(allocator, session, identity, thread_kind, can_reply, entry); 302 errdefer item.deinit(allocator); 303 try box.children.put(allocator, item.getFocus().id, .{ .widget = .{ .repo_comment = item }, .rect = null, .min_size = null }); 304 } 305 306 pub fn appendCount(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), count: usize, singular: []const u8, plural: []const u8) !void { 307 var text_buf: [64]u8 = undefined; 308 const text = try std.fmt.bufPrint(&text_buf, "{d} {s}", .{ count, if (count == 1) singular else plural }); 309 var count_box = try wgt.TextBox.init(allocator, text, .{ .border = .hidden, .wrap_kind = .none }); 310 errdefer count_box.deinit(allocator); 311 try box.children.put(allocator, count_box.getFocus().id, .{ .widget = .{ .text_box = count_box }, .rect = null, .min_size = null }); 312 } 313 314 pub fn appendWindowNav(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), session: *ui.Session, identity: []const u8, thread_kind: evt.EventKind, thread_id: []const u8, selected_id: ?[]const u8, window: Window) !void { 315 const has_prev = window.start > 0; 316 const has_more = window.start < window.count and window.count - window.start > page_size; 317 if (!has_prev and !has_more) return; 318 var row = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .horiz }); 319 errdefer row.deinit(allocator); 320 if (has_prev) { 321 const start = window.start -| page_size; 322 const route = commentsRoute(thread_kind, identity, thread_id, selected_id, start); 323 var previous = try linkBox(allocator, session, "← previous", route orelse return error.RouteTooLong); 324 errdefer previous.deinit(allocator); 325 try row.children.put(allocator, previous.getFocus().id, .{ .widget = .{ .text_box = previous }, .rect = null, .min_size = null }); 326 } 327 if (has_more) { 328 const start = window.start + page_size; 329 const route = commentsRoute(thread_kind, identity, thread_id, selected_id, start); 330 var next = try linkBox(allocator, session, "next →", route orelse return error.RouteTooLong); 331 errdefer next.deinit(allocator); 332 try row.children.put(allocator, next.getFocus().id, .{ .widget = .{ .text_box = next }, .rect = null, .min_size = null }); 333 } 334 row.getFocus().child_id = row.children.keys()[0]; 335 try box.children.put(allocator, row.getFocus().id, .{ .widget = .{ .box = row }, .rect = null, .min_size = null }); 336 } 337 338 fn commentsRoute(kind: evt.EventKind, identity: []const u8, thread_id: []const u8, selected_id: ?[]const u8, start: usize) ?ui.RoutablePage { 339 return if (selected_id) |id| 340 ui.RoutablePage.repoThreadCommentRoute(kind, identity, thread_id, id, start) 341 else 342 ui.RoutablePage.repoThreadCommentsRoute(kind, identity, thread_id, start); 343 } 344 345 fn commentNewRoute(kind: evt.EventKind, identity: []const u8, thread_id: []const u8, parent_id: []const u8) ?ui.RoutablePage { 346 return ui.RoutablePage.repoThreadCommentNewRoute(kind, identity, thread_id, parent_id); 347 } 348 349 fn commentEditRoute(kind: evt.EventKind, identity: []const u8, thread_id: []const u8, comment_id: []const u8) ?ui.RoutablePage { 350 return ui.RoutablePage.repoThreadCommentEditRoute(kind, identity, thread_id, comment_id); 351 } 352 353 fn removeRoute(kind: evt.EventKind, identity: []const u8, thread_id: []const u8, comment_id: []const u8) ?ui.RoutablePage { 354 return ui.RoutablePage.repoThreadRemoveRoute(kind, identity, thread_id, comment_id); 355 } 356 357 pub fn linkBox(allocator: std.mem.Allocator, session: *ui.Session, text: []const u8, route: ui.RoutablePage) !wgt.TextBox { 358 var box = try wgt.TextBox.init(allocator, text, .{ .border = .single, .round_corners = true, .wrap_kind = .none }); 359 errdefer box.deinit(allocator); 360 box.getFocus().mode = .all; 361 box.getFocus().kind = .{ .custom = try session.page_arena.allocator().print("a:{s}", .{try route.toUrl(session.page_arena)}) }; 362 return box; 363 } 364