╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2881 .arrow_down, .tab => if (index + 1 < form.children.count()) root_focus.setFocus(form.children.keys()[index + 1]), 2882 .enter => try self.submitConfirmation(allocator, index), 2883 .mouse => |mouse| for (form.children.keys()[1..], 1..) |button_id, button_index| { 2884 if (inp.leftClickOn(root_focus, button_id, mouse)) { 2885 try self.submitConfirmation(allocator, button_index); 2886 break; 2887 } 2888 }, 2889 else => {}, 2890 } 2891 } 2892 2893 // the multiline hunk inputs keep enter and any up/down that has a row to 2894 // move to; enter on a "use this" link is a navigation the host follows 2895 // before this runs. 2896 fn resolveInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2897 const form = self.formBox() orelse return; 2898 const cid = form.getFocus().child_id orelse return; 2899 const cur = form.children.getIndex(cid) orelse return; 2900 const child = &form.children.values()[cur]; 2901 2902 if (child.widget == .text_input) { 2903 const ti = &child.widget.text_input; 2904 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 2905 return child.widget.input(allocator, key, root_focus); 2906 } 2907 2908 const on_submit = child.widget == .submit_button; 2909 2910 switch (key) { 2911 .arrow_up, .back_tab => if (formStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 2912 .arrow_down, .tab => if (formStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 2913 .arrow_left, .arrow_right => switch (child.widget) { 2914 .box => |*row| _ = widget.moveInRow(row, root_focus, key == .arrow_right), 2915 else => try child.widget.input(allocator, key, root_focus), 2916 }, 2917 .enter => if (on_submit) try self.submitResolution(allocator), 2918 .mouse => |mouse| if (on_submit) { 2919 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 2920 }, 2921 else => try child.widget.input(allocator, key, root_focus), 2922 } 2923 } 2924 2925 // a multiline input keeps enter and any up/down that has a row to move to 2926 fn multilineKeepsKey(text_input: *wgt.TextInput, allocator: std.mem.Allocator, key: Key) !bool { 2927 return switch (key) { 2928 .enter => true, 2929 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 2930 .arrow_down => !try text_input.cursorOnLastRow(allocator), 2931 else => false, 2932 }; 2933 } 2934 2935 // the neighboring form control, skipping spacers and blank rows 2936 fn formStep(form: *wgt.Box(Widget), cur: usize, down: bool) ?usize { 2937 var i = cur; 2938 while (true) { 2939 if (down) { 2940 i += 1; 2941 if (i >= form.children.count()) return null; 2942 } else { 2943 if (i == 0) return null; 2944 i -= 1; 2945 } 2946 const child = &form.children.values()[i]; 2947 if (child.hidden) continue; 2948 switch (child.widget) { 2949 .spacer, .text => continue, 2950 else => return i, 2951 } 2952 } 2953 } 2954 2955 // focus the resolve-form child at `i` (a version row focuses its selected 2956 // child) and keep it visible on the terminal 2957 fn focusResolveChild(self: *This, form: *wgt.Box(Widget), i: usize, root_focus: *Focus) void { 2958 const child = &form.children.values()[i]; 2959 switch (child.widget) { 2960 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 2961 else => root_focus.setFocus(form.children.keys()[i]), 2962 } 2963 if (self.session.is_terminal) { 2964 if (self.resolveScroll()) |sc| { 2965 if (child.rect) |rect| sc.scrollToRect(rect); 2966 } 2967 } 2968 } 2969 2970 // re-emit the conflicted thread's event with the resolved content; any 2971 // event on the thread settles its conflict entry. this is the terminal 2972 // path; the web posts the form to the resolve route. 2973 fn submitResolution(self: *This, allocator: std.mem.Allocator) !void { 2974 if (comptime wasm) return; 2975 const io = self.session.io orelse return; 2976 const src = self.data.repo_source orelse return; 2977 const entry = self.data.selectedThread() orelse return; 2978 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 2979 const form = self.formBox() orelse return; 2980 2981 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 2982 var title: ?[]u8 = null; 2983 var labels: ?[]u8 = null; 2984 var hunks: std.ArrayList([]const u8) = .empty; 2985 defer { 2986 if (title) |t| allocator.free(t); 2987 if (labels) |t| allocator.free(t); 2988 for (hunks.items) |h| allocator.free(h); 2989 hunks.deinit(allocator); 2990 } 2991 for (form.children.values()) |*child| switch (child.widget) { 2992 .text_input => |*ti| { 2993 const text = try ti.text(allocator); 2994 errdefer allocator.free(text); 2995 if (std.mem.eql(u8, ti.options.name, "title")) { 2996 title = text; 2997 } else if (std.mem.eql(u8, ti.options.name, "labels")) { 2998 labels = text; 2999 } else { 3000 try hunks.append(allocator, text); 3001 } 3002 }, 3003 else => {}, 3004 }; 3005 3006 const id_bytes = try evt.parseEventId(entry.id); 3007 3008 switch (src.repo_kind) { 3009 inline else => |repo_kind| { 3010 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3011 defer any_repo.deinit(io, allocator); 3012 switch (any_repo) { 3013 inline else => |*repo| { 3014 var resolution: Event.Resolve = .{ 3015 .title = title, 3016 .labels = labels, 3017 .hunks = hunks.items, 3018 }; 3019 if (comptime @hasField(Event.Resolve, "theirs")) resolution.theirs = self.data.theirs_picks; 3020 const change = Event.Update{ .resolve = resolution }; 3021 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, change, author) catch |err| switch (err) { 3022 // leave the form up for correction 3023 error.InvalidFields => return, 3024 else => |e| return e, 3025 }; 3026 }, 3027 } 3028 }, 3029 } 3030 3031 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3032 try self.session.navigate(route); 3033 } 3034 3035 // commit a new or edited comment and navigate to its permalink. this is the 3036 // terminal path; the web posts the form to its comment route. 3037 fn submitComment(self: *This, allocator: std.mem.Allocator) !void { 3038 if (comptime wasm) return; 3039 const io = self.session.io orelse return; 3040 const src = self.data.repo_source orelse return; 3041 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3042 const author = actor.author; 3043 const form = self.formBox() orelse return; 3044 const body_input = try formField(form, "body"); 3045 const body = try body_input.text(allocator); 3046 defer allocator.free(body); 3047 if (!evt.Comment.fieldsValid(body)) return; 3048 3049 var thread_id: [evt.event_id_size * 2]u8 = undefined; 3050 @memcpy(&thread_id, self.data.selected_id); 3051 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 3052 var parent: [evt.event_id_size * 2]u8 = undefined; 3053 @memcpy(&parent, self.data.comment_id); 3054 break :blk parent; 3055 }; 3056 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 3057 const editing = self.data.view == .edit_comment; 3058 if (editing) { 3059 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 3060 if (!try src.canModify(io, allocator, actor, .comment, &comment_id)) return; 3061 } 3062 switch (src.repo_kind) { 3063 inline else => |repo_kind| { 3064 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3065 defer any_repo.deinit(io, allocator); 3066 switch (any_repo) { 3067 inline else => |*repo| if (editing) { 3068 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 3069 try evt.Comment.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, &comment_id, body, author); 3070 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 3071 } else { 3072 event_id_hex = try evt.Comment.create(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, &parent_id, body, author); 3073 }, 3074 } 3075 }, 3076 } 3077 3078 body_input.clear(allocator); 3079 const route = ui.RoutablePage.repoThreadCommentRoute(kind, self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 3080 try self.session.navigate(route); 3081 } 3082 3083 // terminal form submissions; the web posts to the forms' routes instead 3084 fn submitForm(self: *This, allocator: std.mem.Allocator) !void { 3085 switch (self.data.view) { 3086 .new_comment, .edit_comment => try self.submitComment(allocator), 3087 .edit => try self.submitEditedThread(allocator), 3088 else => try self.submitNewThread(allocator), 3089 } 3090 } 3091 3092 // commit the new thread to the repo's events branch and navigate to it. 3093 // this is the terminal path; the web posts the form to the thread route, 3094 // so the wasm side never runs (or compiles) the repo access below. 3095 fn submitNewThread(self: *This, allocator: std.mem.Allocator) !void { 3096 if (comptime wasm) return; 3097 const io = self.session.io orelse return; 3098 const src = self.data.repo_source orelse return; 3099 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3100 3101 const form = self.threadForm() orelse return; 3102 const title_input = try formField(form, "title"); 3103 const labels_input = try formField(form, "labels"); 3104 const description_input = try formField(form, "description"); 3105 3106 const title = try title_input.text(allocator); 3107 defer allocator.free(title); 3108 const labels = try labels_input.text(allocator); 3109 defer allocator.free(labels); 3110 const description = try description_input.text(allocator); 3111 defer allocator.free(description); 3112 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 3113 defer if (comptime supports_drafts) allocator.free(target_branch); 3114 3115 if (!Event.fieldsValid(title, labels)) { 3116 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, labels, description, target_branch); 3117 return; 3118 } 3119 3120 if (comptime supports_drafts) { 3121 const source = formWidget(form, .patch_source) orelse return error.MissingFormField; 3122 const source_branch = switch (source.selectedKind()) { 3123 .fork => null, 3124 .branch => try source.field().text(allocator), 3125 }; 3126 defer if (source_branch) |branch| allocator.free(branch); 3127 const event_id_hex = Data.create(self.data, self.session, allocator, actor, title, labels, description, target_branch, source_branch) catch |err| { 3128 const failure = FeedbackFailure.fromError(err) orelse return err; 3129 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3130 return; 3131 }; 3132 title_input.clear(allocator); 3133 labels_input.clear(allocator); 3134 description_input.clear(allocator); 3135 (try formField(form, "target_branch")).clear(allocator); 3136 const route = ui.RoutablePage.repoThreadCommentsRoute(kind, self.data.identity, &event_id_hex, 0) orelse return; 3137 try self.session.navigate(route); 3138 return; 3139 } 3140 3141 var id_bytes: [evt.event_id_size]u8 = undefined; 3142 io.random(&id_bytes); 3143 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 3144 3145 const event = evt.EventWithId{ 3146 .id = event_id_hex, 3147 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 3148 .author = actor.author, 3149 .event = @unionInit(evt.Event, @tagName(kind), Event{ 3150 .title = title, 3151 .description = description, 3152 .labels = labels, 3153 }), 3154 }; 3155 3156 switch (src.repo_kind) { 3157 inline else => |repo_kind| { 3158 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3159 defer any_repo.deinit(io, allocator); 3160 switch (any_repo) { 3161 inline else => |*repo| try evt.consume(self.session.eventHost(), .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 3162 } 3163 }, 3164 } 3165 3166 // wipe the form so a return visit starts fresh 3167 title_input.clear(allocator); 3168 labels_input.clear(allocator); 3169 description_input.clear(allocator); 3170 3171 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), &event_id_hex) orelse return; 3172 try self.session.navigate(route); 3173 } 3174 3175 // re-emit the selected thread's event with the form's content (status 3176 // preserved), then reload the thread's page. this is the terminal path; 3177 // the web posts the form to the edit route. 3178 fn submitEditedThread(self: *This, allocator: std.mem.Allocator) !void { 3179 if (comptime wasm) return; 3180 const io = self.session.io orelse return; 3181 const entry = self.data.selectedThread() orelse return; 3182 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3183 const author = actor.author; 3184 3185 const form = self.threadForm() orelse return; 3186 const title_input = try formField(form, "title"); 3187 const labels_input = try formField(form, "labels"); 3188 const description_input = try formField(form, "description"); 3189 3190 const title = try title_input.text(allocator); 3191 defer allocator.free(title); 3192 const labels = try labels_input.text(allocator); 3193 defer allocator.free(labels); 3194 const description = try description_input.text(allocator); 3195 defer allocator.free(description); 3196 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 3197 defer if (comptime supports_drafts) allocator.free(target_branch); 3198 3199 if (!Event.fieldsValid(title, labels)) { 3200 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, labels, description, target_branch); 3201 return; 3202 } 3203 const src = self.data.repo_source orelse return; 3204 3205 if (comptime supports_drafts) { 3206 if (entryDraft(entry.*)) { 3207 self.data.editDraft(self.session, allocator, author, entry.id, title, labels, description, target_branch) catch |err| { 3208 const failure = FeedbackFailure.fromError(err) orelse return err; 3209 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3210 return; 3211 }; 3212 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3213 try self.session.navigate(route); 3214 return; 3215 } 3216 } 3217 3218 const id_bytes = try evt.parseEventId(entry.id); 3219 if (!try src.canModify(io, allocator, actor, kind, &id_bytes)) return; 3220 3221 switch (src.repo_kind) { 3222 inline else => |repo_kind| { 3223 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3224 defer any_repo.deinit(io, allocator); 3225 switch (any_repo) { 3226 inline else => |*repo| if (supports_drafts) { 3227 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3228 .title = title, 3229 .labels = labels, 3230 .description = description, 3231 .target_branch = target_branch, 3232 } }, author) catch |err| { 3233 const failure = FeedbackFailure.fromError(err) orelse return err; 3234 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3235 return; 3236 }; 3237 } else if (has_status) 3238 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3239 .title = title, 3240 .labels = labels, 3241 .description = description, 3242 } }, author) 3243 else 3244 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, labels, description, author), 3245 } 3246 }, 3247 } 3248 3249 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3250 try self.session.navigate(route); 3251 } 3252 3253 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, labels: []const u8, description: []const u8, target_branch: []const u8) !void { 3254 const aa = self.session.arena.allocator(); 3255 const source = if (supports_drafts) blk: { 3256 const form = self.threadForm() orelse break :blk null; 3257 break :blk formWidget(form, .patch_source); 3258 } else null; 3259 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 3260 .failure = failure, 3261 .fields = if (comptime supports_drafts) .{ 3262 .title = try aa.dupe(u8, title), 3263 .labels = try aa.dupe(u8, labels), 3264 .description = try aa.dupe(u8, description), 3265 .target_branch = try aa.dupe(u8, target_branch), 3266 .source_branch = if (source) |value| try value.field().text(aa) else "", 3267 .source_kind = if (source) |value| value.selectedKind() else .fork, 3268 } else .{ 3269 .title = try aa.dupe(u8, title), 3270 .labels = try aa.dupe(u8, labels), 3271 .description = try aa.dupe(u8, description), 3272 }, 3273 }); 3274 } 3275 3276 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 3277 switch (confirmation(self.data.view) orelse return) { 3278 .publish => if (comptime supports_drafts) { 3279 if (comptime wasm) return; 3280 const entry = self.data.selectedThread() orelse return; 3281 if (!entryDraft(entry.*)) return; 3282 const author = ((try self.session.authorize(self.data.identity, .read, kind)) orelse return).author; 3283 try self.data.publishDraft(self.session, allocator, author, entry.id); 3284 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), entry.id) orelse return; 3285 try self.session.navigate(route); 3286 } else unreachable, 3287 .merge => if (comptime supports_merge) { 3288 if (comptime wasm) return; 3289 const entry = self.data.selectedThread() orelse return; 3290 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 3291 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 3292 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 3293 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 3294 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 3295 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3296 try self.session.navigate(route); 3297 return; 3298 }, 3299 else => return err, 3300 }; 3301 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 3302 const route = listRoute(self.data.identity, merged, entry.id) orelse return; 3303 try self.session.navigate(route); 3304 } else unreachable, 3305 .remove => try self.submitRemove(allocator), 3306 } 3307 } 3308 3309 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3310 const comment = self.data.comment_id.len != 0; 3311 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3312 const id = evt.parseEventId(event_id) catch return; 3313 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3314 } 3315 3316 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3317 if (comptime wasm) return; 3318 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3319 const author = actor.author; 3320 3321 if (comptime supports_drafts) { 3322 const selected = self.data.selectedThread() orelse return; 3323 if (event_kind == kind and entryDraft(selected.*)) { 3324 try Data.removeDraft(self.session, allocator, author, &id); 3325 const route = draftsRoute(self.data.identity) orelse return; 3326 try self.session.navigate(route); 3327 return; 3328 } 3329 } 3330 3331 const io = self.session.io orelse return; 3332 const src = self.data.repo_source orelse return; 3333 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3334 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3335 3336 switch (src.repo_kind) { 3337 inline else => |repo_kind| { 3338 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3339 defer any_repo.deinit(io, allocator); 3340 switch (any_repo) { 3341 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), 3342 } 3343 }, 3344 } 3345 3346 const id_hex = std.fmt.bytesToHex(id, .lower); 3347 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex, null) orelse return; 3348 try self.session.navigate(route); 3349 } 3350 3351 // enter the detail pane, landing on the way back to the list when it shows 3352 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 3353 if (widget.listBackId(self.detailFrame(index)) != null) return widget.focusListBack(self.detailFrame(index), root_focus); 3354 _ = self.detail(index).focusFirst(root_focus); 3355 } 3356 3357 // return to the list. 3358 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3359 root_focus.setFocus(self.listScroll(index).getFocus().id); 3360 } 3361 3362 // cross to the header tabs above the stack. 3363 fn focusHeader(self: *This, root_focus: *Focus) void { 3364 root_focus.setFocus(self.box.children.keys()[header_index]); 3365 } 3366 3367 pub fn clearGrid(self: *This) void { 3368 self.box.clearGrid(); 3369 } 3370 3371 pub fn getGrid(self: This) ?Grid { 3372 return self.box.getGrid(); 3373 } 3374 3375 pub fn getFocus(self: *This) *Focus { 3376 return self.box.getFocus(); 3377 } 3378 3379 // for the parent's "scroll up at the top jumps to the header" check: at the 3380 // top only while the header tabs hold focus, so up from the split 3381 // crosses into the tabs first. 3382 pub fn atTop(self: *This) bool { 3383 return self.headerActive(); 3384 } 3385 }; 3386 } 3387