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