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