╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Threads.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2394 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2395 .title = title, 2396 .tags = tags, 2397 .description = description, 2398 } }, author) 2399 else 2400 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, tags, description, author), 2401 } 2402 }, 2403 } 2404 2405 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2406 try self.session.navigate(route); 2407 } 2408 2409 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2410 const comment = self.data.comment_id.len != 0; 2411 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2412 const id = evt.parseEventId(event_id) catch return; 2413 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2414 } 2415 2416 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2417 if (comptime wasm) return; 2418 const io = self.session.io orelse return; 2419 const src = self.data.repo_source orelse return; 2420 const author = (try self.session.eventAuthor()) orelse return; 2421 2422 switch (src.repo_kind) { 2423 inline else => |repo_kind| { 2424 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2425 defer any_repo.deinit(io, allocator); 2426 switch (any_repo) { 2427 inline else => |*repo| try evt.remove(.repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2428 } 2429 }, 2430 } 2431 2432 const id_hex = std.fmt.bytesToHex(id, .lower); 2433 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2434 try self.session.navigate(route); 2435 } 2436 2437 // flip the shown thread's status by re-emitting its event, then reload the 2438 // page rooted at the thread so the view reflects the change. this is the 2439 // terminal path; the web posts the button's form to the status route. 2440 fn toggleStatus(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2441 if (comptime !has_status) return; 2442 if (comptime wasm) return; 2443 const io = self.session.io orelse return; 2444 const src = self.data.repo_source orelse return; 2445 const sel = self.detailed_index[index] orelse return; 2446 const entry = self.window(index).items[sel]; 2447 const author = (try self.session.eventAuthor()) orelse return; 2448 2449 const status = (statusChange(entryStatus(entry)) orelse return).status; 2450 2451 const id_bytes = try evt.parseEventId(entry.id); 2452 2453 switch (src.repo_kind) { 2454 inline else => |repo_kind| { 2455 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2456 defer any_repo.deinit(io, allocator); 2457 switch (any_repo) { 2458 inline else => |*repo| try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author), 2459 } 2460 }, 2461 } 2462 2463 const route = listRoute(self.data.identity, status, "", entry.id) orelse return; 2464 try self.session.navigate(route); 2465 } 2466 2467 // arrow keys move the tag selection; at the flow's edges focus crosses to 2468 // the neighboring widgets. 2469 fn tagsInput(self: *This, index: usize, child_index: usize, tf: *ui.TagFlow, key: Key, root_focus: *Focus) void { 2470 const cid = tf.focus.child_id orelse return; 2471 const cur = tf.indexOfFocusId(cid) orelse return; 2472 const count = tf.text_boxes.items.len; 2473 switch (key) { 2474 .arrow_left => if (cur > 0) self.focusTag(index, child_index, tf, root_focus, cur - 1) else self.focusList(index, root_focus), 2475 .arrow_right => if (cur + 1 < count) self.focusTag(index, child_index, tf, root_focus, cur + 1), 2476 .arrow_up => if (tf.rowStep(cur, false)) |i| { 2477 self.focusTag(index, child_index, tf, root_focus, i); 2478 } else { 2479 _ = self.moveDetailVertical(index, root_focus, false); 2480 }, 2481 .arrow_down => if (tf.rowStep(cur, true)) |i| { 2482 self.focusTag(index, child_index, tf, root_focus, i); 2483 } else { 2484 _ = self.moveDetailVertical(index, root_focus, true); 2485 }, 2486 .home => self.focusTag(index, child_index, tf, root_focus, 0), 2487 .end => self.focusTag(index, child_index, tf, root_focus, count - 1), 2488 else => {}, 2489 } 2490 } 2491 2492 const title_child_index: usize = 0; 2493 2494 // the tool row's first child after the spacer that pushes it right 2495 const first_in_row_index: usize = 1; 2496 2497 fn toolRowFocused(self: *This, index: usize) bool { 2498 const outer = self.detailOuter(index); 2499 const cid = outer.getFocus().child_id orelse return false; 2500 return outer.children.getIndex(cid) == tool_row_index; 2501 } 2502 2503 fn focusTag(self: *This, index: usize, child_index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2504 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2505 // keep the tag visible on the terminal: its rect offset by the flow's 2506 // position in the pane. 2507 if (self.session.is_terminal and item < tf.rects.items.len) { 2508 if (self.detailInner(index).children.values()[child_index].rect) |flow_rect| { 2509 var rect = tf.rects.items[item]; 2510 rect.x += flow_rect.x; 2511 rect.y += flow_rect.y; 2512 self.detailScroll(index).scrollToRect(rect); 2513 } 2514 } 2515 } 2516 2517 // return to the tool row's last-focused button (the header when the 2518 // description page shows no row). 2519 fn focusToolRow(self: *This, index: usize, root_focus: *Focus) void { 2520 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2521 root_focus.setFocus(cid); 2522 } 2523 2524 // enter the detail pane. an empty pane can't be entered. 2525 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 2526 if (self.detailInner(index).children.count() == 0) return; 2527 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2528 } 2529 2530 // return to the list. 2531 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2532 root_focus.setFocus(self.listScroll(index).getFocus().id); 2533 } 2534 2535 // cross to the header tabs above the stack. 2536 fn focusHeader(self: *This, root_focus: *Focus) void { 2537 root_focus.setFocus(self.box.children.keys()[header_index]); 2538 } 2539 2540 pub fn clearGrid(self: *This) void { 2541 self.box.clearGrid(); 2542 } 2543 2544 pub fn getGrid(self: This) ?Grid { 2545 return self.box.getGrid(); 2546 } 2547 2548 pub fn getFocus(self: *This) *Focus { 2549 return self.box.getFocus(); 2550 } 2551 2552 // for the parent's "scroll up at the top jumps to the header" check: at the 2553 // top only while the header tabs hold focus, so up from the split 2554 // crosses into the tabs first. 2555 pub fn getSelectedIndex(self: *This) ?usize { 2556 return if (self.headerActive()) 0 else 1; 2557 } 2558 }; 2559 } 2560