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