╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2839 try self.session.navigate(route); 2840 } 2841 2842 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, labels: []const u8, description: []const u8, target_branch: []const u8) !void { 2843 const aa = self.session.arena.allocator(); 2844 const source = if (supports_drafts) blk: { 2845 const form = self.threadForm() orelse break :blk null; 2846 break :blk formWidget(form, .patch_source); 2847 } else null; 2848 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 2849 .failure = failure, 2850 .fields = if (comptime supports_drafts) .{ 2851 .title = try aa.dupe(u8, title), 2852 .labels = try aa.dupe(u8, labels), 2853 .description = try aa.dupe(u8, description), 2854 .target_branch = try aa.dupe(u8, target_branch), 2855 .source_branch = if (source) |value| try value.field().text(aa) else "", 2856 .source_kind = if (source) |value| value.selectedKind() else .fork, 2857 } else .{ 2858 .title = try aa.dupe(u8, title), 2859 .labels = try aa.dupe(u8, labels), 2860 .description = try aa.dupe(u8, description), 2861 }, 2862 }); 2863 } 2864 2865 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 2866 switch (confirmation(self.data.view) orelse return) { 2867 .publish => if (comptime supports_drafts) { 2868 if (comptime wasm) return; 2869 const entry = self.data.selectedThread() orelse return; 2870 if (!entryDraft(entry.*)) return; 2871 const author = ((try self.session.authorize(self.data.identity, .read)) orelse return).author; 2872 try self.data.publishDraft(self.session, allocator, author, entry.id); 2873 const route = listRoute(self.data.identity, @enumFromInt(0), "", entry.id) orelse return; 2874 try self.session.navigate(route); 2875 } else unreachable, 2876 .merge => if (comptime supports_merge) { 2877 if (comptime wasm) return; 2878 const entry = self.data.selectedThread() orelse return; 2879 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 2880 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 2881 const author = ((try self.session.authorize(self.data.identity, .write)) orelse return).author; 2882 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 2883 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 2884 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2885 try self.session.navigate(route); 2886 return; 2887 }, 2888 else => return err, 2889 }; 2890 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2891 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2892 try self.session.navigate(route); 2893 } else unreachable, 2894 .remove => try self.submitRemove(allocator), 2895 } 2896 } 2897 2898 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2899 const comment = self.data.comment_id.len != 0; 2900 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2901 const id = evt.parseEventId(event_id) catch return; 2902 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2903 } 2904 2905 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2906 if (comptime wasm) return; 2907 const actor = (try self.session.authorize(self.data.identity, .read)) orelse return; 2908 const author = actor.author; 2909 2910 if (comptime supports_drafts) { 2911 const selected = self.data.selectedThread() orelse return; 2912 if (event_kind == kind and entryDraft(selected.*)) { 2913 try Data.removeDraft(self.session, allocator, author, &id); 2914 const route = draftsRoute(self.data.identity) orelse return; 2915 try self.session.navigate(route); 2916 return; 2917 } 2918 } 2919 2920 const io = self.session.io orelse return; 2921 const src = self.data.repo_source orelse return; 2922 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 2923 2924 switch (src.repo_kind) { 2925 inline else => |repo_kind| { 2926 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2927 defer any_repo.deinit(io, allocator); 2928 switch (any_repo) { 2929 inline else => |*repo| try evt.remove(self.session.eventHost(), .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2930 } 2931 }, 2932 } 2933 2934 const id_hex = std.fmt.bytesToHex(id, .lower); 2935 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex, null) orelse return; 2936 try self.session.navigate(route); 2937 } 2938 2939 // return to the list. 2940 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2941 root_focus.setFocus(self.listScroll(index).getFocus().id); 2942 } 2943 2944 // cross to the header tabs above the stack. 2945 fn focusHeader(self: *This, root_focus: *Focus) void { 2946 root_focus.setFocus(self.box.children.keys()[header_index]); 2947 } 2948 2949 pub fn clearGrid(self: *This) void { 2950 self.box.clearGrid(); 2951 } 2952 2953 pub fn getGrid(self: This) ?Grid { 2954 return self.box.getGrid(); 2955 } 2956 2957 pub fn getFocus(self: *This) *Focus { 2958 return self.box.getFocus(); 2959 } 2960 2961 // for the parent's "scroll up at the top jumps to the header" check: at the 2962 // top only while the header tabs hold focus, so up from the split 2963 // crosses into the tabs first. 2964 pub fn atTop(self: *This) bool { 2965 return self.headerActive(); 2966 } 2967 }; 2968 } 2969