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