╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2648 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2649 try self.session.navigate(route); 2650 } 2651 2652 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, tags: []const u8, description: []const u8, target_branch: []const u8) !void { 2653 const aa = self.session.arena.allocator(); 2654 const source = if (supports_drafts) blk: { 2655 const form = self.threadForm() orelse break :blk null; 2656 break :blk formWidget(form, .patch_source); 2657 } else null; 2658 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 2659 .failure = failure, 2660 .fields = if (comptime supports_drafts) .{ 2661 .title = try aa.dupe(u8, title), 2662 .tags = try aa.dupe(u8, tags), 2663 .description = try aa.dupe(u8, description), 2664 .target_branch = try aa.dupe(u8, target_branch), 2665 .source_branch = if (source) |value| try value.field().text(aa) else "", 2666 .source_kind = if (source) |value| value.selected else .fork, 2667 } else .{ 2668 .title = try aa.dupe(u8, title), 2669 .tags = try aa.dupe(u8, tags), 2670 .description = try aa.dupe(u8, description), 2671 }, 2672 }); 2673 } 2674 2675 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 2676 switch (confirmation(self.data.view) orelse return) { 2677 .publish => if (comptime supports_drafts) { 2678 if (comptime wasm) return; 2679 const entry = self.data.selectedThread() orelse return; 2680 if (!entryDraft(entry.*)) return; 2681 try self.data.publishDraft(self.session, allocator, entry.id); 2682 const route = listRoute(self.data.identity, @enumFromInt(0), "", entry.id) orelse return; 2683 try self.session.navigate(route); 2684 } else unreachable, 2685 .merge => if (comptime supports_merge) { 2686 if (comptime wasm) return; 2687 const entry = self.data.selectedThread() orelse return; 2688 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 2689 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 2690 self.data.mergePatch(self.session, allocator, entry.id, revision) catch |err| switch (err) { 2691 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 2692 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2693 try self.session.navigate(route); 2694 return; 2695 }, 2696 else => return err, 2697 }; 2698 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2699 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2700 try self.session.navigate(route); 2701 } else unreachable, 2702 .remove => try self.submitRemove(allocator), 2703 } 2704 } 2705 2706 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2707 const comment = self.data.comment_id.len != 0; 2708 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2709 const id = evt.parseEventId(event_id) catch return; 2710 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2711 } 2712 2713 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2714 if (comptime wasm) return; 2715 2716 if (comptime supports_drafts) { 2717 const selected = self.data.selectedThread() orelse return; 2718 if (event_kind == kind and entryDraft(selected.*)) { 2719 try Data.removeDraft(self.session, allocator, &id); 2720 const route = draftsRoute(self.data.identity) orelse return; 2721 try self.session.navigate(route); 2722 return; 2723 } 2724 } 2725 2726 const io = self.session.io orelse return; 2727 const src = self.data.repo_source orelse return; 2728 const author = (try self.session.eventAuthor()) orelse return; 2729 2730 switch (src.repo_kind) { 2731 inline else => |repo_kind| { 2732 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2733 defer any_repo.deinit(io, allocator); 2734 switch (any_repo) { 2735 inline else => |*repo| try evt.remove(self.session.data.host_kind, .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2736 } 2737 }, 2738 } 2739 2740 const id_hex = std.fmt.bytesToHex(id, .lower); 2741 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2742 try self.session.navigate(route); 2743 } 2744 2745 // return to the list. 2746 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2747 root_focus.setFocus(self.listScroll(index).getFocus().id); 2748 } 2749 2750 // cross to the header tabs above the stack. 2751 fn focusHeader(self: *This, root_focus: *Focus) void { 2752 root_focus.setFocus(self.box.children.keys()[header_index]); 2753 } 2754 2755 pub fn clearGrid(self: *This) void { 2756 self.box.clearGrid(); 2757 } 2758 2759 pub fn getGrid(self: This) ?Grid { 2760 return self.box.getGrid(); 2761 } 2762 2763 pub fn getFocus(self: *This) *Focus { 2764 return self.box.getFocus(); 2765 } 2766 2767 // for the parent's "scroll up at the top jumps to the header" check: at the 2768 // top only while the header tabs hold focus, so up from the split 2769 // crosses into the tabs first. 2770 pub fn atTop(self: *This) bool { 2771 return self.headerActive(); 2772 } 2773 }; 2774 } 2775