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