╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
371 const reply_tab_label = "reply"; 372 const remove_tab_label = "remove"; 373 const resolve_tab_label = "resolve"; 374 const new_tab_label = "new"; 375 const conflicts_tab_label = "conflicts"; 376 377 // tabs switching between the issues page's views 378 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 379 var header = try Header.init(allocator, session, data.search); 380 errdefer header.deinit(allocator); 381 const aa = session.page_arena.allocator(); 382 const selected_index = View.viewIndex(data.view); 383 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_issues; 384 385 // a list tab per status, labeled with its listing's issue count 386 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label }; 387 for ([_]evt.Issue.Status{ .open, .closed }, status_labels, 0..) |status, status_label, index| { 388 const route = try thread.searchRoute(ui.RoutablePage.repoIssuesRoute(data.identity, status, data.label, ""), data.search); 389 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 390 var label_buf: [64]u8 = undefined; 391 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 392 try header.addTab(allocator, label, link, index); 393 } 394 395 // labels tab, showing the active label filter 396 { 397 const labels_route = try thread.searchRoute(ui.RoutablePage.repoThreadLabelsRoute(.issue, data.identity, data.label), data.search); 398 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 399 const label = if (data.label.len == 0) labels_tab_label else blk: { 400 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.label)); 401 break :blk try std.fmt.allocPrint(aa, labels_tab_label ++ " ({s})", .{decoded}); 402 }; 403 try header.addTab(allocator, label, labels_link, View.viewIndex(.labels)); 404 } 405 406 // new-issue tab; an edit or resolve url shows its tab in this place 407 { 408 const route = switch (data.view) { 409 .edit => ui.RoutablePage.repoThreadEditRoute(.issue, data.identity, data.selected_id) orelse return error.RouteTooLong, 410 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 411 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 412 .remove => ui.RoutablePage.repoThreadRemoveRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 413 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 414 else => ui.RoutablePage.repoThreadNewRoute(.issue, data.identity) orelse return error.RouteTooLong, 415 }; 416 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 417 const label: []const u8 = switch (data.view) { 418 .edit => edit_tab_label, 419 .new_comment => reply_tab_label, 420 .edit_comment => edit_tab_label, 421 .remove => remove_tab_label, 422 .resolve => resolve_tab_label, 423 else => new_tab_label, 424 }; 425 try header.addTab(allocator, label, link, View.viewIndex(.new)); 426 } 427 428 // conflicts tab, labeled with the conflict count 429 if (data.conflicts.count > 0) { 430 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 431 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 432 var label_buf: [64]u8 = undefined; 433 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 434 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 435 } 436 437 header.select(View.viewIndex(data.view)); 438 return header; 439 } 440