╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3213 return; 3214 } 3215 } 3216 3217 const id_bytes = try evt.parseEventId(entry.id); 3218 if (!try src.canModify(io, allocator, actor, kind, &id_bytes)) return; 3219 3220 switch (src.repo_kind) { 3221 inline else => |repo_kind| { 3222 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3223 defer any_repo.deinit(io, allocator); 3224 switch (any_repo) { 3225 inline else => |*repo| if (supports_drafts) { 3226 Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3227 .title = title, 3228 .labels = labels, 3229 .description = description, 3230 .target_branch = target_branch, 3231 } }, author) catch |err| { 3232 const failure = FeedbackFailure.fromError(err) orelse return err; 3233 try self.rememberThreadFeedback(failure, title, labels, description, target_branch); 3234 return; 3235 }; 3236 } else if (has_status) 3237 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 3238 .title = title, 3239 .labels = labels, 3240 .description = description, 3241 } }, author) 3242 else 3243 try Event.update(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, labels, description, author), 3244 } 3245 }, 3246 } 3247 3248 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3249 try self.session.navigate(route); 3250 } 3251 3252 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, labels: []const u8, description: []const u8, target_branch: []const u8) !void { 3253 const aa = self.session.arena.allocator(); 3254 const source = if (supports_drafts) blk: { 3255 const form = self.threadForm() orelse break :blk null; 3256 break :blk formWidget(form, .patch_source); 3257 } else null; 3258 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 3259 .failure = failure, 3260 .fields = if (comptime supports_drafts) .{ 3261 .title = try aa.dupe(u8, title), 3262 .labels = try aa.dupe(u8, labels), 3263 .description = try aa.dupe(u8, description), 3264 .target_branch = try aa.dupe(u8, target_branch), 3265 .source_branch = if (source) |value| try value.field().text(aa) else "", 3266 .source_kind = if (source) |value| value.selectedKind() else .fork, 3267 } else .{ 3268 .title = try aa.dupe(u8, title), 3269 .labels = try aa.dupe(u8, labels), 3270 .description = try aa.dupe(u8, description), 3271 }, 3272 }); 3273 } 3274 3275 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 3276 switch (confirmation(self.data.view) orelse return) { 3277 .publish => if (comptime supports_drafts) { 3278 if (comptime wasm) return; 3279 const entry = self.data.selectedThread() orelse return; 3280 if (!entryDraft(entry.*)) return; 3281 const author = ((try self.session.authorize(self.data.identity, .read, kind)) orelse return).author; 3282 try self.data.publishDraft(self.session, allocator, author, entry.id); 3283 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), entry.id) orelse return; 3284 try self.session.navigate(route); 3285 } else unreachable, 3286 .merge => if (comptime supports_merge) { 3287 if (comptime wasm) return; 3288 const entry = self.data.selectedThread() orelse return; 3289 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 3290 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 3291 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 3292 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 3293 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 3294 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3295 try self.session.navigate(route); 3296 return; 3297 }, 3298 else => return err, 3299 }; 3300 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 3301 const route = listRoute(self.data.identity, merged, entry.id) orelse return; 3302 try self.session.navigate(route); 3303 } else unreachable, 3304 .remove => try self.submitRemove(allocator), 3305 } 3306 } 3307 3308 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3309 const comment = self.data.comment_id.len != 0; 3310 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3311 const id = evt.parseEventId(event_id) catch return; 3312 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3313 } 3314 3315 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3316 if (comptime wasm) return; 3317 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3318 const author = actor.author; 3319 3320 if (comptime supports_drafts) { 3321 const selected = self.data.selectedThread() orelse return; 3322 if (event_kind == kind and entryDraft(selected.*)) { 3323 try Data.removeDraft(self.session, allocator, author, &id); 3324 const route = draftsRoute(self.data.identity) orelse return; 3325 try self.session.navigate(route); 3326 return; 3327 } 3328 } 3329 3330 const io = self.session.io orelse return; 3331 const src = self.data.repo_source orelse return; 3332 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3333 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3334 3335 switch (src.repo_kind) { 3336 inline else => |repo_kind| { 3337 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3338 defer any_repo.deinit(io, allocator); 3339 switch (any_repo) { 3340 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), 3341 } 3342 }, 3343 } 3344 3345 const id_hex = std.fmt.bytesToHex(id, .lower); 3346 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex, null) orelse return; 3347 try self.session.navigate(route); 3348 } 3349 3350 // enter the detail pane, landing on the way back to the list when it shows 3351 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 3352 if (widget.listBackId(self.detailFrame(index)) != null) return widget.focusListBack(self.detailFrame(index), root_focus); 3353 _ = self.detail(index).focusFirst(root_focus); 3354 } 3355 3356 // return to the list. 3357 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3358 root_focus.setFocus(self.listScroll(index).getFocus().id); 3359 } 3360 3361 // cross to the header tabs above the stack. 3362 fn focusHeader(self: *This, root_focus: *Focus) void { 3363 root_focus.setFocus(self.box.children.keys()[header_index]); 3364 } 3365 3366 pub fn clearGrid(self: *This) void { 3367 self.box.clearGrid(); 3368 } 3369 3370 pub fn getGrid(self: This) ?Grid { 3371 return self.box.getGrid(); 3372 } 3373 3374 pub fn getFocus(self: *This) *Focus { 3375 return self.box.getFocus(); 3376 } 3377 3378 // for the parent's "scroll up at the top jumps to the header" check: at the 3379 // top only while the header tabs hold focus, so up from the split 3380 // crosses into the tabs first. 3381 pub fn atTop(self: *This) bool { 3382 return self.headerActive(); 3383 } 3384 }; 3385 } 3386