╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3179 break :blk formWidget(form, .patch_source); 3180 } else null; 3181 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 3182 .failure = failure, 3183 .fields = if (comptime supports_drafts) .{ 3184 .title = try aa.dupe(u8, title), 3185 .labels = try aa.dupe(u8, labels), 3186 .description = try aa.dupe(u8, description), 3187 .target_branch = try aa.dupe(u8, target_branch), 3188 .source_branch = if (source) |value| try value.field().text(aa) else "", 3189 .source_kind = if (source) |value| value.selectedKind() else .fork, 3190 } else .{ 3191 .title = try aa.dupe(u8, title), 3192 .labels = try aa.dupe(u8, labels), 3193 .description = try aa.dupe(u8, description), 3194 }, 3195 }); 3196 } 3197 3198 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 3199 switch (confirmation(self.data.view) orelse return) { 3200 .publish => if (comptime supports_drafts) { 3201 if (comptime wasm) return; 3202 const entry = self.data.selectedThread() orelse return; 3203 if (!entryDraft(entry.*)) return; 3204 const author = ((try self.session.authorize(self.data.identity, .read, kind)) orelse return).author; 3205 try self.data.publishDraft(self.session, allocator, author, entry.id); 3206 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), "", entry.id) orelse return; 3207 try self.session.navigate(route); 3208 } else unreachable, 3209 .merge => if (comptime supports_merge) { 3210 if (comptime wasm) return; 3211 const entry = self.data.selectedThread() orelse return; 3212 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 3213 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 3214 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 3215 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 3216 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 3217 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 3218 try self.session.navigate(route); 3219 return; 3220 }, 3221 else => return err, 3222 }; 3223 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 3224 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 3225 try self.session.navigate(route); 3226 } else unreachable, 3227 .remove => try self.submitRemove(allocator), 3228 } 3229 } 3230 3231 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3232 const comment = self.data.comment_id.len != 0; 3233 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3234 const id = evt.parseEventId(event_id) catch return; 3235 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3236 } 3237 3238 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3239 if (comptime wasm) return; 3240 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3241 const author = actor.author; 3242 3243 if (comptime supports_drafts) { 3244 const selected = self.data.selectedThread() orelse return; 3245 if (event_kind == kind and entryDraft(selected.*)) { 3246 try Data.removeDraft(self.session, allocator, author, &id); 3247 const route = draftsRoute(self.data.identity) orelse return; 3248 try self.session.navigate(route); 3249 return; 3250 } 3251 } 3252 3253 const io = self.session.io orelse return; 3254 const src = self.data.repo_source orelse return; 3255 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3256 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3257 3258 switch (src.repo_kind) { 3259 inline else => |repo_kind| { 3260 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3261 defer any_repo.deinit(io, allocator); 3262 switch (any_repo) { 3263 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), 3264 } 3265 }, 3266 } 3267 3268 const id_hex = std.fmt.bytesToHex(id, .lower); 3269 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex, null) orelse return; 3270 try self.session.navigate(route); 3271 } 3272 3273 // return to the list. 3274 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3275 root_focus.setFocus(self.listScroll(index).getFocus().id); 3276 } 3277 3278 // cross to the header tabs above the stack. 3279 fn focusHeader(self: *This, root_focus: *Focus) void { 3280 root_focus.setFocus(self.box.children.keys()[header_index]); 3281 } 3282 3283 pub fn clearGrid(self: *This) void { 3284 self.box.clearGrid(); 3285 } 3286 3287 pub fn getGrid(self: This) ?Grid { 3288 return self.box.getGrid(); 3289 } 3290 3291 pub fn getFocus(self: *This) *Focus { 3292 return self.box.getFocus(); 3293 } 3294 3295 // for the parent's "scroll up at the top jumps to the header" check: at the 3296 // top only while the header tabs hold focus, so up from the split 3297 // crosses into the tabs first. 3298 pub fn atTop(self: *This) bool { 3299 return self.headerActive(); 3300 } 3301 }; 3302 } 3303