╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2551 }, 2552 } 2553 2554 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2555 try self.session.navigate(route); 2556 } 2557 2558 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 2559 switch (confirmation(self.data.view) orelse return) { 2560 .publish => if (comptime supports_drafts) { 2561 if (comptime wasm) return; 2562 const entry = self.data.selectedThread() orelse return; 2563 if (!entryDraft(entry.*)) return; 2564 try self.data.publishDraft(self.session, allocator, entry.id); 2565 const route = listRoute(self.data.identity, @enumFromInt(0), "", entry.id) orelse return; 2566 try self.session.navigate(route); 2567 } else unreachable, 2568 .merge => if (comptime supports_merge) { 2569 if (comptime wasm) return; 2570 const entry = self.data.selectedThread() orelse return; 2571 try self.data.mergePatch(self.session, allocator, entry.id, button_index > 1); 2572 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2573 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2574 try self.session.navigate(route); 2575 } else unreachable, 2576 .remove => try self.submitRemove(allocator), 2577 } 2578 } 2579 2580 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2581 const comment = self.data.comment_id.len != 0; 2582 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2583 const id = evt.parseEventId(event_id) catch return; 2584 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2585 } 2586 2587 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2588 if (comptime wasm) return; 2589 2590 if (comptime supports_drafts) { 2591 const selected = self.data.selectedThread() orelse return; 2592 if (event_kind == kind and entryDraft(selected.*)) { 2593 try Data.removeDraft(self.session, allocator, &id); 2594 const route = draftsRoute(self.data.identity) orelse return; 2595 try self.session.navigate(route); 2596 return; 2597 } 2598 } 2599 2600 const io = self.session.io orelse return; 2601 const src = self.data.repo_source orelse return; 2602 const author = (try self.session.eventAuthor()) orelse return; 2603 2604 switch (src.repo_kind) { 2605 inline else => |repo_kind| { 2606 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2607 defer any_repo.deinit(io, allocator); 2608 switch (any_repo) { 2609 inline else => |*repo| try evt.remove(.repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2610 } 2611 }, 2612 } 2613 2614 const id_hex = std.fmt.bytesToHex(id, .lower); 2615 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2616 try self.session.navigate(route); 2617 } 2618 2619 // return to the list. 2620 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2621 root_focus.setFocus(self.listScroll(index).getFocus().id); 2622 } 2623 2624 // cross to the header tabs above the stack. 2625 fn focusHeader(self: *This, root_focus: *Focus) void { 2626 root_focus.setFocus(self.box.children.keys()[header_index]); 2627 } 2628 2629 pub fn clearGrid(self: *This) void { 2630 self.box.clearGrid(); 2631 } 2632 2633 pub fn getGrid(self: This) ?Grid { 2634 return self.box.getGrid(); 2635 } 2636 2637 pub fn getFocus(self: *This) *Focus { 2638 return self.box.getFocus(); 2639 } 2640 2641 // for the parent's "scroll up at the top jumps to the header" check: at the 2642 // top only while the header tabs hold focus, so up from the split 2643 // crosses into the tabs first. 2644 pub fn getSelectedIndex(self: *This) ?usize { 2645 return if (self.headerActive()) 0 else 1; 2646 } 2647 }; 2648 } 2649