╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1514 const route = ui.RoutablePage.repoIssuesRoute(identity, status, encoded, "") orelse return error.RouteTooLong; 1515 const url = try route.toUrl(page_arena); 1516 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1517 } 1518 1519 // tabs switching between the issues page's views. 1520 pub const Header = struct { 1521 box: wgt.Box(ui.Widget), 1522 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 1523 1524 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1525 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1526 errdefer box.deinit(allocator); 1527 1528 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 1529 errdefer tab_ids.deinit(allocator); 1530 1531 const aa = session.page_arena.allocator(); 1532 1533 // a list tab per status, labeled with its listing's issue count 1534 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 1535 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 1536 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1537 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 1538 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1539 errdefer text_box.deinit(allocator); 1540 text_box.getFocus().focusable = true; 1541 text_box.getFocus().kind = .{ .custom = link }; 1542 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1543 try box.children.put(allocator, text_box.getFocus().id, .{ 1544 .widget = .{ .text_box = text_box }, 1545 .rect = null, 1546 .min_size = .{ .width = label.len + 2, .height = null }, 1547 }); 1548 } 1549 1550 // tags tab, labeled with the active tag filter 1551 { 1552 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 1553 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 1554 const label = if (data.tag.len == 0) "tags" else blk: { 1555 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 1556 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 1557 }; 1558 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1559 errdefer text_box.deinit(allocator); 1560 text_box.getFocus().focusable = true; 1561 text_box.getFocus().kind = .{ .custom = tags_link }; 1562 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1563 try box.children.put(allocator, text_box.getFocus().id, .{ 1564 .widget = .{ .text_box = text_box }, 1565 .rect = null, 1566 .min_size = .{ .width = label.len + 2, .height = null }, 1567 }); 1568 } 1569 1570 // new-issue tab; an edit url shows the edit tab in its place 1571 { 1572 const route = if (data.view == .edit) 1573 ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong 1574 else 1575 ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong; 1576 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1577 const label: []const u8 = if (data.view == .edit) "edit" else "new"; 1578 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1579 errdefer text_box.deinit(allocator); 1580 text_box.getFocus().focusable = true; 1581 text_box.getFocus().kind = .{ .custom = link }; 1582 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1583 try box.children.put(allocator, text_box.getFocus().id, .{ 1584 .widget = .{ .text_box = text_box }, 1585 .rect = null, 1586 .min_size = .{ .width = label.len + 2, .height = null }, 1587 }); 1588 } 1589 1590 var self = Header{ .box = box, .tab_ids = tab_ids }; 1591 // the tab matching the page's view is selected initially. 1592 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 1593 return self; 1594 } 1595 1596 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 1597 self.box.deinit(allocator); 1598 self.tab_ids.deinit(allocator); 1599 } 1600 1601 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1602 self.clearGrid(); 1603 // only the selected tab shows its border 1604 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 1605 switch (child.widget) { 1606 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 1607 else => {}, 1608 } 1609 } 1610 try self.box.build(allocator, constraint, root_focus); 1611 } 1612 1613 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1614 _ = allocator; 1615 const current_tab = self.currentTabIndex() orelse return; 1616 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 1617 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 1618 } 1619 } 1620 1621 pub fn clearGrid(self: *Header) void { 1622 self.box.clearGrid(); 1623 } 1624 1625 pub fn getGrid(self: Header) ?Grid { 1626 return self.box.getGrid(); 1627 } 1628 1629 pub fn getFocus(self: *Header) *Focus { 1630 return self.box.getFocus(); 1631 } 1632 1633 pub fn getSelectedIndex(self: Header) ?usize { 1634 return self.currentTabIndex(); 1635 } 1636 1637 fn currentTabIndex(self: Header) ?usize { 1638 const child_id = self.box.focus.child_id orelse return null; 1639 return self.tab_ids.getIndex(child_id); 1640 } 1641 }; 1642