╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const evt = @import("../event.zig"); 3 const ui = @import("../ui.zig"); 4 const xit = @import("xit"); 5 const rp = xit.repo; 6 const hash = xit.hash; 7 const xitui = xit.xitui; 8 const wgt = xitui.widget; 9 const layout = xitui.layout; 10 const Key = xitui.input.Key; 11 const Grid = xitui.grid.Grid; 12 const Focus = xitui.focus.Focus; 13 const inp = @import("./input.zig"); 14 const fork = @import("../fork.zig"); 15 16 pub const Header = @import("./User/Header.zig"); 17 pub const Settings = @import("./Settings.zig"); 18 pub const Auth = @import("./Auth.zig"); 19 pub const Quit = @import("./Quit.zig"); 20 21 pub const page_size = 20; // how many repos one window of the repos tab shows 22 23 pub const ForkItem = struct { 24 id: []const u8, 25 // the fork route's identity, which names the forker 26 identity: []const u8, 27 target: []const u8, 28 title: []const u8, 29 }; 30 31 header: Header, 32 user: evt.User.Public, 33 repos: []const evt.Repo.Record, 34 repos_start: usize, // the repos window this page was built with, mirrored into the url 35 repos_next_start: ?usize, // the `start` for the "next" row, or null on the last window 36 repos_search: ?[]const u8, // the name prefix the repos are narrowed to (decoded; null = no search) 37 forks: []const ForkItem, 38 forks_start: usize, 39 forks_next_start: ?usize, 40 settings: Settings, 41 auth: Auth, 42 quit: Quit, 43 44 const Self = @This(); 45 46 pub fn init( 47 arena: *std.heap.ArenaAllocator, 48 session: *ui.Session, 49 haxy_moment: evt.AdminDB.HashMap(.read_only), 50 name: ui.RoutablePage.Array(evt.User.name_max_len), 51 repos_start: usize, 52 // the url-encoded repos search ("" = none) 53 repos_search: []const u8, 54 forks_start: usize, 55 ) !Self { 56 // admin and user repos share one db type 57 const DB = evt.AdminDB; 58 const hash_kind = evt.admin_repo_opts.hash; 59 60 // a route identifies a user by name, which everything below keys off of 61 const user_id = (try evt.User.readIdByName(DB, hash_kind, haxy_moment, name.slice())) orelse return error.NotFound; 62 const user = (try evt.User.readById(DB, hash_kind, haxy_moment, arena, &user_id)) orelse return error.NotFound; 63 64 const io = session.io orelse return error.NoMoment; 65 const users_dir = session.users_dir orelse return error.NoMoment; 66 const gpa = arena.child_allocator; 67 68 // a user with no user repo or no events has empty lists 69 var user_repo_maybe = try evt.openUserRepo(io, gpa, users_dir, &user_id); 70 defer if (user_repo_maybe) |*user_repo| user_repo.deinit(io, gpa); 71 const user_moment = if (user_repo_maybe) |*user_repo| try evt.userMoment(user_repo) else null; 72 73 const search: ?[]const u8 = if (repos_search.len == 0) null else std.Uri.percentDecodeInPlace(try arena.allocator().dupe(u8, repos_search)); 74 const prefix = search orelse ""; 75 76 var repos: std.ArrayList(evt.Repo.Record) = .empty; 77 var repos_next_start: ?usize = null; 78 if (user_moment) |moment| { 79 if (try moment.getCursor(hash.hashInt(hash_kind, evt.Repo.name_index_key))) |index_cursor| { 80 const index = try DB.SortedMap(.read_only).init(index_cursor); 81 82 // the names with the prefix are contiguous from its rank, so the 83 // window is one seek then a walk that stops at the first name without it 84 var taken: usize = 0; 85 var repos_iter = try index.iteratorFromIndex(try index.rank(prefix) +| repos_start); 86 while (try repos_iter.next()) |cursor| { 87 const pair = try cursor.readKeyValuePair(); 88 const repo_name = try pair.key_cursor.readBytesAlloc(arena.allocator(), null); 89 if (!std.mem.startsWith(u8, repo_name, prefix)) break; 90 if (taken == page_size) { 91 repos_next_start = repos_start + page_size; 92 break; 93 } 94 taken += 1; 95 var event_id: [evt.event_id_size]u8 = undefined; 96 _ = try pair.value_cursor.readBytes(&event_id); 97 const repo_event = (try evt.Repo.readById(DB, hash_kind, moment, arena, &event_id)) orelse continue; 98 // unreadable repos leave their window short rather than shifting the others 99 if (evt.Repo.roleOf(repo_event, session.userId()) == .none) continue; 100 try repos.append(arena.allocator(), repo_event); 101 } 102 } 103 } 104 105 var forks: std.ArrayList(ForkItem) = .empty; 106 var forks_next_start: ?usize = null; 107 if (user_moment) |moment| { 108 if (try moment.getCursor(hash.hashInt(hash_kind, evt.Fork.active_id_set_key))) |user_forks_cursor| { 109 const user_forks = try DB.SortedSet(.read_only).init(user_forks_cursor); 110 const count = try user_forks.count(); 111 const end = @min(forks_start +| page_size, count); 112 var iter = try user_forks.iteratorFromIndex(forks_start); 113 var i = forks_start; 114 while (i < end) : (i += 1) { 115 const kv_cursor = (try iter.next()) orelse break; 116 const fork_id = try evt.readOrderKeyId(DB, kv_cursor); 117 const fork_id_hex = std.fmt.bytesToHex(fork_id, .lower); 118 const record = (try evt.Fork.readById(DB, hash_kind, moment, arena, &fork_id)) orelse continue; 119 120 // the target lives in its owner's user repo 121 const owner_id = record.event.repo_user_id[0..evt.event_id_size]; 122 const target_repo = (try evt.readRepoById(io, gpa, arena, users_dir, owner_id, record.event.repo_id)) orelse continue; 123 if (evt.Repo.roleOf(target_repo, session.userId()) == .none) continue; 124 const owner = (try evt.User.readById(DB, hash_kind, haxy_moment, arena, owner_id)) orelse continue; 125 126 var title: []const u8 = "(unavailable)"; 127 const path = try fork.forkPath(arena.allocator(), users_dir, &user_id, &fork_id); 128 if (rp.Repo(.xit, .{}).open(io, gpa, .{ .path = path, .require_repo_root = true })) |opened| { 129 var fork_repo = opened; 130 defer fork_repo.deinit(io, gpa); 131 if (evt.currentMoment(.{}, &fork_repo)) |fork_moment| { 132 if (try evt.Patch.readById(evt.EventDB(.sha1), .sha1, fork_moment, arena, &fork_id)) |patch| title = patch.event.title; 133 } else |_| {} 134 } else |_| {} 135 try forks.append(arena.allocator(), .{ 136 .id = try arena.allocator().dupe(u8, &fork_id_hex), 137 .identity = try std.fmt.allocPrint(arena.allocator(), "{s}/{s}", .{ user.event.name, target_repo.event.name }), 138 .target = try std.fmt.allocPrint(arena.allocator(), "{s}/{s}", .{ owner.event.name, target_repo.event.name }), 139 .title = title, 140 }); 141 } 142 forks_next_start = if (end < count) end else null; 143 } 144 } 145 146 return .{ 147 .header = try Header.init(arena, user.event.name), 148 .user = evt.project(evt.User.Public, user.event), 149 .repos = repos.items, 150 .repos_start = repos_start, 151 .repos_next_start = repos_next_start, 152 .repos_search = search, 153 .forks = forks.items, 154 .forks_start = forks_start, 155 .forks_next_start = forks_next_start, 156 .settings = Settings.init(), 157 .auth = Auth.init(), 158 .quit = Quit.init(), 159 }; 160 } 161 162 pub const View = struct { 163 box: wgt.Box(ui.Widget), 164 165 const header_index: usize = 0; 166 const stack_index: usize = 1; 167 168 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 169 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .round_corners = true, .direction = .vert }); 170 errdefer box.deinit(allocator); 171 172 // build the header first so we can grab the repos-tab id for the auth 173 // view (it focuses there after login). 174 { 175 var header_view = try Header.View.init(allocator, &data.header, session); 176 errdefer header_view.deinit(allocator); 177 try box.children.put(allocator, header_view.getFocus().id, .{ .widget = .{ .user_header = header_view }, .rect = null, .min_size = null }); 178 } 179 180 { 181 var stack = try wgt.Stack(ui.Widget).init(allocator); 182 errdefer stack.deinit(allocator); 183 184 // repos list — the default tab 185 { 186 var repos_view = try ReposView.init(allocator, data, session); 187 errdefer repos_view.deinit(allocator); 188 try stack.children.put(allocator, repos_view.getFocus().id, .{ .user_repos = repos_view }); 189 } 190 191 // forks list 192 { 193 var list = try ui.widget.FlowBox.Scroll.init(allocator, .{}, !session.is_terminal); 194 errdefer list.deinit(allocator); 195 196 var item_arena = std.heap.ArenaAllocator.init(allocator); 197 defer item_arena.deinit(); 198 const aa = item_arena.allocator(); 199 var items: std.ArrayList(ui.widget.FlowBox.Item) = .empty; 200 if (data.forks_start > 0) 201 try items.append(aa, .{ .text = "← previous", .link = try std.fmt.allocPrint(aa, "a:/user/{s}/forks/start:{d}", .{ data.user.name, data.forks_start -| page_size }) }); 202 for (data.forks) |fork_item| { 203 const route = ui.RoutablePage.forkPatchRoute(fork_item.identity, fork_item.id) orelse return error.RouteTooLong; 204 try items.append(aa, .{ 205 .text = try std.fmt.allocPrint(aa, "{s}\n{s}", .{ fork_item.target, fork_item.title }), 206 .link = try std.fmt.allocPrint(aa, "a:{s}", .{try route.toUrl(session.page_arena)}), 207 }); 208 } 209 if (data.forks_next_start) |next_start| 210 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:/user/{s}/forks/start:{d}", .{ data.user.name, next_start }) }); 211 try list.setItems(allocator, items.items); 212 try stack.children.put(allocator, list.getFocus().id, .{ .flow_box_scroll = list }); 213 } 214 215 // the header has no settings tab without a login, so keep the 216 // stack's children 1:1 with the tabs by skipping the view too 217 if (session.data.user_id != null) { 218 var settings_view = try Settings.View.init(allocator, session); 219 errdefer settings_view.deinit(allocator); 220 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 221 } 222 223 { 224 var auth_view = try Auth.View.init(allocator, &data.auth, session); 225 errdefer auth_view.deinit(allocator); 226 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 227 } 228 229 if (session.is_terminal) { 230 var quit_view = try Quit.View.init(allocator, session); 231 errdefer quit_view.deinit(allocator); 232 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 233 } 234 235 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 236 } 237 238 var self = View{ .box = box }; 239 // search results open in the tab's own search box 240 self.getFocus().child_id = box.children.keys()[if (data.repos_search != null) stack_index else header_index]; 241 return self; 242 } 243 244 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 245 self.box.deinit(allocator); 246 } 247 248 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 249 self.clearGrid(); 250 const header = &self.box.children.values()[header_index].widget.user_header; 251 const stack = &self.box.children.values()[stack_index].widget.stack; 252 253 // each header tab maps 1:1 to a stack child by position 254 if (header.getSelectedIndex()) |index| 255 stack.getFocus().child_id = stack.children.keys()[index]; 256 try self.box.build(allocator, constraint, root_focus); 257 } 258 259 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 260 const stack = &self.box.children.values()[stack_index].widget.stack; 261 if (self.getFocus().child_id) |child_id| { 262 if (self.box.children.getIndex(child_id)) |current_index| { 263 const child = &self.box.children.values()[current_index].widget; 264 var index = current_index; 265 266 const direction = inp.vertDirection(key); 267 268 switch (direction) { 269 .up => { 270 switch (child.*) { 271 .user_header => { 272 try child.input(allocator, key, root_focus); 273 }, 274 .stack => { 275 if (child.stack.getSelected()) |selected_widget| { 276 if (selected_widget.atTop(root_focus)) { 277 index = header_index; 278 } else { 279 try child.input(allocator, key, root_focus); 280 } 281 } 282 }, 283 else => {}, 284 } 285 }, 286 .down => { 287 switch (child.*) { 288 .user_header => { 289 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 290 .user_repos => |*v| return v.focusHeader(root_focus), 291 // an empty list has nothing to focus 292 .flow_box_scroll => |*v| if (v.isEmpty()) return, 293 else => {}, 294 }; 295 index = stack_index; 296 }, 297 .stack => { 298 try child.input(allocator, key, root_focus); 299 }, 300 else => {}, 301 } 302 }, 303 .none => { 304 try child.input(allocator, key, root_focus); 305 }, 306 } 307 308 if (index != current_index) { 309 root_focus.setFocus(self.box.children.keys()[index]); 310 } 311 } 312 } 313 } 314 315 pub fn clearGrid(self: *View) void { 316 self.box.clearGrid(); 317 } 318 319 pub fn getGrid(self: View) ?Grid { 320 return self.box.getGrid(); 321 } 322 323 pub fn getFocus(self: *View) *Focus { 324 return self.box.getFocus(); 325 } 326 }; 327 328 pub const ReposView = struct { 329 // a vertical box: the search sub-header above the scrolling list. focus 330 // points at the header's box or the list's selected row. 331 box: wgt.Box(ui.Widget), 332 data: *const Self, 333 session: *ui.Session, 334 335 const header_index = 0; 336 const list_index = 1; 337 338 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !ReposView { 339 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 340 errdefer box.deinit(allocator); 341 342 { 343 var header = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 344 errdefer header.deinit(allocator); 345 { 346 var search_box = try ui.widget.SearchBox.init(allocator, session, " search ", "search", data.repos_search); 347 errdefer search_box.deinit(allocator); 348 header.getFocus().child_id = search_box.getFocus().id; 349 try header.children.put(allocator, search_box.getFocus().id, .{ .widget = .{ .search_box = search_box }, .rect = null, .min_size = ui.widget.SearchBox.min_size }); 350 } 351 // the spacer keeps the box at its own width 352 { 353 var spacer = try ui.widget.Spacer.init(allocator); 354 errdefer spacer.deinit(allocator); 355 try header.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 356 } 357 try box.children.put(allocator, header.getFocus().id, .{ .widget = .{ .box = header }, .rect = null, .min_size = .{ .width = null, .height = ui.widget.SearchBox.min_size.height } }); 358 } 359 360 { 361 var list = try ui.widget.FlowBox.Scroll.init(allocator, .{}, !session.is_terminal); 362 errdefer list.deinit(allocator); 363 364 var arena = std.heap.ArenaAllocator.init(allocator); 365 defer arena.deinit(); 366 const aa = arena.allocator(); 367 368 const route = (reposRoute(data.user.name) orelse return error.RouteTooLong).withSearch(data.repos_search orelse "") orelse return error.RouteTooLong; 369 370 // a leading "previous" row off the first window, one row per repo, 371 // then a trailing "next" row when more remain. each window row 372 // navigates to the adjacent window of this user's repos. 373 var items: std.ArrayList(ui.widget.FlowBox.Item) = .empty; 374 if (data.repos_start > 0) { 375 var prev = route; 376 prev.user_repos.start = data.repos_start -| page_size; 377 try items.append(aa, .{ .text = "← previous", .link = try std.fmt.allocPrint(aa, "a:{s}", .{try prev.toUrl(&arena)}) }); 378 } 379 for (data.repos) |repo| 380 // clicking a repo opens its page; the "a:" prefix makes the web 381 // renderer emit an <a href="/repo/alice/foo"> anchor. 382 try items.append(aa, .{ 383 .text = try std.fmt.allocPrint(aa, "{s} - {s}", .{ repo.event.name, repo.event.description }), 384 .link = try std.fmt.allocPrint(aa, "a:/repo/{s}/{s}", .{ data.user.name, repo.event.name }), 385 }); 386 if (data.repos_next_start) |next_start| { 387 var next = route; 388 next.user_repos.start = next_start; 389 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:{s}", .{try next.toUrl(&arena)}) }); 390 } 391 try list.setItems(allocator, items.items); 392 393 try box.children.put(allocator, list.getFocus().id, .{ .widget = .{ .flow_box_scroll = list }, .rect = null, .min_size = null }); 394 } 395 396 // search results start in the box so the term can be refined right away 397 box.getFocus().child_id = box.children.keys()[if (data.repos_search != null) header_index else list_index]; 398 return .{ .box = box, .data = data, .session = session }; 399 } 400 401 pub fn deinit(self: *ReposView, allocator: std.mem.Allocator) void { 402 self.box.deinit(allocator); 403 } 404 405 pub fn build(self: *ReposView, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 406 self.clearGrid(); 407 // clear the incoming min height so the list scrolls within what's left 408 try self.box.build(allocator, .{ 409 .min_size = .{ .width = null, .height = null }, 410 .max_size = constraint.max_size, 411 }, root_focus); 412 } 413 414 pub fn input(self: *ReposView, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 415 const direction = inp.vertDirection(key); 416 if (self.headerActive()) { 417 const search_box = self.searchBox(); 418 if (direction == .down) return root_focus.setFocus(self.listScroll().getFocus().id); 419 if (key == .enter) { 420 const text = try search_box.text(allocator); 421 defer allocator.free(text); 422 return self.submit(text); 423 } 424 return search_box.input(allocator, key, root_focus); 425 } 426 // up from the first row reaches the search box 427 if (direction == .up and self.listScroll().atTop()) return self.focusHeader(root_focus); 428 try self.listScroll().input(allocator, key, root_focus); 429 } 430 431 // the repos narrowed to `text` from the first window. an empty box on an 432 // unsearched page has nothing to clear. 433 fn submit(self: *ReposView, text: []const u8) !void { 434 if (text.len == 0 and self.data.repos_search == null) return; 435 const route = reposRoute(self.data.user.name) orelse return; 436 try self.session.navigate(route.withSearch(text) orelse return); 437 } 438 439 fn searchBox(self: *ReposView) *ui.widget.SearchBox { 440 return &self.box.children.values()[header_index].widget.box.children.values()[0].widget.search_box; 441 } 442 443 fn listScroll(self: *ReposView) *ui.widget.FlowBox.Scroll { 444 return &self.box.children.values()[list_index].widget.flow_box_scroll; 445 } 446 447 fn headerActive(self: *ReposView) bool { 448 return self.box.getFocus().child_id == self.box.children.keys()[header_index]; 449 } 450 451 pub fn clearGrid(self: *ReposView) void { 452 self.box.clearGrid(); 453 } 454 455 pub fn getGrid(self: ReposView) ?Grid { 456 return self.box.getGrid(); 457 } 458 459 pub fn getFocus(self: *ReposView) *Focus { 460 return self.box.getFocus(); 461 } 462 463 // up leaves the tab from the search box 464 pub fn atTop(self: *ReposView) bool { 465 return self.headerActive(); 466 } 467 468 pub fn focusHeader(self: *ReposView, root_focus: *Focus) void { 469 root_focus.setFocus(self.searchBox().getFocus().id); 470 } 471 }; 472 473 // the first window of `name`'s repos 474 fn reposRoute(name: []const u8) ?ui.RoutablePage { 475 return .{ .user_repos = .{ .name = ui.RoutablePage.Array(evt.User.name_max_len).from(name) orelse return null } }; 476 } 477