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