╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2258 else 2259 self.focusHeader(root_focus), 2260 .arrow_down, .tab => return if (formStep(form, cur, true)) |i| root_focus.setFocus(form.children.keys()[i]), 2261 .enter => if (on_submit) return self.submitForm(allocator), 2262 .mouse => |mouse| if (on_submit) { 2263 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) return self.submitForm(allocator); 2264 }, 2265 else => {}, 2266 } 2267 try child.widget.input(allocator, key, root_focus); 2268 } 2269 2270 fn confirmationFormInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2271 const form = self.confirmationForm() orelse return; 2272 const child_id = form.getFocus().child_id orelse return; 2273 const index = form.children.getIndex(child_id) orelse return; 2274 switch (key) { 2275 .arrow_up, .back_tab => if (index > 1) 2276 root_focus.setFocus(form.children.keys()[index - 1]) 2277 else 2278 self.focusHeader(root_focus), 2279 .arrow_down, .tab => if (index + 1 < form.children.count()) root_focus.setFocus(form.children.keys()[index + 1]), 2280 .enter => try self.submitConfirmation(allocator, index), 2281 .mouse => |mouse| for (form.children.keys()[1..], 1..) |button_id, button_index| { 2282 if (inp.leftClickOn(root_focus, button_id, mouse)) { 2283 try self.submitConfirmation(allocator, button_index); 2284 break; 2285 } 2286 }, 2287 else => {}, 2288 } 2289 } 2290 2291 // the multiline hunk inputs keep enter and any up/down that has a row to 2292 // move to; enter on a "use this" link is a navigation the host follows 2293 // before this runs. 2294 fn resolveInput(self: *This, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2295 const form = self.formBox() orelse return; 2296 const cid = form.getFocus().child_id orelse return; 2297 const cur = form.children.getIndex(cid) orelse return; 2298 const child = &form.children.values()[cur]; 2299 2300 if (child.widget == .text_input) { 2301 const ti = &child.widget.text_input; 2302 if (ti.options.multiline and try multilineKeepsKey(ti, allocator, key)) 2303 return child.widget.input(allocator, key, root_focus); 2304 } 2305 2306 const on_submit = child.widget == .submit_button; 2307 2308 switch (key) { 2309 .arrow_up, .back_tab => if (formStep(form, cur, false)) |i| self.focusResolveChild(form, i, root_focus) else self.focusHeader(root_focus), 2310 .arrow_down, .tab => if (formStep(form, cur, true)) |i| self.focusResolveChild(form, i, root_focus), 2311 .arrow_left, .arrow_right => switch (child.widget) { 2312 .box => |*row| { 2313 const row_cid = row.getFocus().child_id orelse return; 2314 const row_index = row.children.getIndex(row_cid) orelse return; 2315 if (key == .arrow_left) { 2316 if (row_index > 0) root_focus.setFocus(row.children.keys()[row_index - 1]); 2317 } else if (row_index + 1 < row.children.count()) { 2318 root_focus.setFocus(row.children.keys()[row_index + 1]); 2319 } 2320 }, 2321 else => try child.widget.input(allocator, key, root_focus), 2322 }, 2323 .enter => if (on_submit) try self.submitResolution(allocator), 2324 .mouse => |mouse| if (on_submit) { 2325 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) try self.submitResolution(allocator); 2326 }, 2327 else => try child.widget.input(allocator, key, root_focus), 2328 } 2329 } 2330 2331 // a multiline input keeps enter and any up/down that has a row to move to 2332 fn multilineKeepsKey(text_input: *wgt.TextInput, allocator: std.mem.Allocator, key: Key) !bool { 2333 return switch (key) { 2334 .enter => true, 2335 .arrow_up => !try text_input.cursorOnFirstRow(allocator), 2336 .arrow_down => !try text_input.cursorOnLastRow(allocator), 2337 else => false, 2338 }; 2339 } 2340 2341 // the neighboring form control, skipping spacers and blank rows 2342 fn formStep(form: *wgt.Box(Widget), cur: usize, down: bool) ?usize { 2343 var i = cur; 2344 while (true) { 2345 if (down) { 2346 i += 1; 2347 if (i >= form.children.count()) return null; 2348 } else { 2349 if (i == 0) return null; 2350 i -= 1; 2351 } 2352 const child = &form.children.values()[i]; 2353 if (child.hidden) continue; 2354 switch (child.widget) { 2355 .spacer, .text => continue, 2356 else => return i, 2357 } 2358 } 2359 } 2360 2361 // focus the resolve-form child at `i` (a version row focuses its selected 2362 // child) and keep it visible on the terminal 2363 fn focusResolveChild(self: *This, form: *wgt.Box(Widget), i: usize, root_focus: *Focus) void { 2364 const child = &form.children.values()[i]; 2365 switch (child.widget) { 2366 .box => |*row| root_focus.setFocus(row.getFocus().child_id orelse form.children.keys()[i]), 2367 else => root_focus.setFocus(form.children.keys()[i]), 2368 } 2369 if (self.session.is_terminal) { 2370 if (self.resolveScroll()) |sc| { 2371 if (child.rect) |rect| sc.scrollToRect(rect); 2372 } 2373 } 2374 } 2375 2376 // re-emit the conflicted thread's event with the resolved content; any 2377 // event on the thread settles its conflict entry. this is the terminal 2378 // path; the web posts the form to the resolve route. 2379 fn submitResolution(self: *This, allocator: std.mem.Allocator) !void { 2380 if (comptime wasm) return; 2381 const io = self.session.io orelse return; 2382 const src = self.data.repo_source orelse return; 2383 const entry = self.data.selectedThread() orelse return; 2384 const author = (try self.session.eventAuthor()) orelse return; 2385 const form = self.formBox() orelse return; 2386 2387 // gather the inputs by name; the d<n> hunk inputs appear in chunk order 2388 var title: ?[]u8 = null; 2389 var tags: ?[]u8 = null; 2390 var hunks: std.ArrayList([]const u8) = .empty; 2391 defer { 2392 if (title) |t| allocator.free(t); 2393 if (tags) |t| allocator.free(t); 2394 for (hunks.items) |h| allocator.free(h); 2395 hunks.deinit(allocator); 2396 } 2397 for (form.children.values()) |*child| switch (child.widget) { 2398 .text_input => |*ti| { 2399 const text = try ti.text(allocator); 2400 errdefer allocator.free(text); 2401 if (std.mem.eql(u8, ti.options.name, "title")) { 2402 title = text; 2403 } else if (std.mem.eql(u8, ti.options.name, "tags")) { 2404 tags = text; 2405 } else { 2406 try hunks.append(allocator, text); 2407 } 2408 }, 2409 else => {}, 2410 }; 2411 2412 const id_bytes = try evt.parseEventId(entry.id); 2413 2414 switch (src.repo_kind) { 2415 inline else => |repo_kind| { 2416 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2417 defer any_repo.deinit(io, allocator); 2418 switch (any_repo) { 2419 inline else => |*repo| { 2420 var resolution: Event.Resolve = .{ 2421 .title = title, 2422 .tags = tags, 2423 .hunks = hunks.items, 2424 }; 2425 if (comptime @hasField(Event.Resolve, "theirs")) resolution.theirs = self.data.theirs_picks; 2426 const change = Event.Update{ .resolve = resolution }; 2427 Event.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, change, author) catch |err| switch (err) { 2428 // leave the form up for correction 2429 error.InvalidFields => return, 2430 else => |e| return e, 2431 }; 2432 }, 2433 } 2434 }, 2435 } 2436 2437 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2438 try self.session.navigate(route); 2439 } 2440 2441 // commit a new or edited comment and navigate to its permalink. this is the 2442 // terminal path; the web posts the form to its comment route. 2443 fn submitComment(self: *This, allocator: std.mem.Allocator) !void { 2444 if (comptime wasm) return; 2445 const io = self.session.io orelse return; 2446 const src = self.data.repo_source orelse return; 2447 const author = (try self.session.eventAuthor()) orelse return; 2448 const form = self.formBox() orelse return; 2449 const body_input = try formField(form, "body"); 2450 const body = try body_input.text(allocator); 2451 defer allocator.free(body); 2452 if (!evt.Comment.fieldsValid(body)) return; 2453 2454 var thread_id: [evt.event_id_size * 2]u8 = undefined; 2455 @memcpy(&thread_id, self.data.selected_id); 2456 const parent_id = if (self.data.comment_id.len == 0) thread_id else blk: { 2457 var parent: [evt.event_id_size * 2]u8 = undefined; 2458 @memcpy(&parent, self.data.comment_id); 2459 break :blk parent; 2460 }; 2461 var event_id_hex: [evt.event_id_size * 2]u8 = undefined; 2462 const editing = self.data.view == .edit_comment; 2463 switch (src.repo_kind) { 2464 inline else => |repo_kind| { 2465 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2466 defer any_repo.deinit(io, allocator); 2467 switch (any_repo) { 2468 inline else => |*repo| if (editing) { 2469 const comment_id = evt.parseEventId(self.data.comment_id) catch return; 2470 try evt.Comment.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &comment_id, body, author); 2471 event_id_hex = std.fmt.bytesToHex(comment_id, .lower); 2472 } else { 2473 event_id_hex = try evt.Comment.create(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &thread_id, &parent_id, body, author); 2474 }, 2475 } 2476 }, 2477 } 2478 2479 body_input.clear(allocator); 2480 const route = ui.RoutablePage.repoThreadCommentRoute(kind, self.data.identity, &thread_id, &event_id_hex, 0) orelse return; 2481 try self.session.navigate(route); 2482 } 2483 2484 // terminal form submissions; the web posts to the forms' routes instead 2485 fn submitForm(self: *This, allocator: std.mem.Allocator) !void { 2486 switch (self.data.view) { 2487 .new_comment, .edit_comment => try self.submitComment(allocator), 2488 .edit => try self.submitEditedThread(allocator), 2489 else => try self.submitNewThread(allocator), 2490 } 2491 } 2492 2493 // commit the new thread to the repo's events branch and navigate to it. 2494 // this is the terminal path; the web posts the form to the thread route, 2495 // so the wasm side never runs (or compiles) the repo access below. 2496 fn submitNewThread(self: *This, allocator: std.mem.Allocator) !void { 2497 if (comptime wasm) return; 2498 const io = self.session.io orelse return; 2499 const src = self.data.repo_source orelse return; 2500 const author = (try self.session.eventAuthor()) orelse return; 2501 2502 const form = self.threadForm() orelse return; 2503 const title_input = try formField(form, "title"); 2504 const tags_input = try formField(form, "tags"); 2505 const description_input = try formField(form, "description"); 2506 2507 const title = try title_input.text(allocator); 2508 defer allocator.free(title); 2509 const tags = try tags_input.text(allocator); 2510 defer allocator.free(tags); 2511 const description = try description_input.text(allocator); 2512 defer allocator.free(description); 2513 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 2514 defer if (comptime supports_drafts) allocator.free(target_branch); 2515 2516 if (!Event.fieldsValid(title, tags)) { 2517 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, tags, description, target_branch); 2518 return; 2519 } 2520 2521 if (comptime supports_drafts) { 2522 const source = formWidget(form, .patch_source) orelse return error.MissingFormField; 2523 const source_branch = switch (source.selected) { 2524 .fork => null, 2525 .branch => try source.field().text(allocator), 2526 }; 2527 defer if (source_branch) |branch| allocator.free(branch); 2528 const event_id_hex = Data.create(self.data, self.session, allocator, title, tags, description, target_branch, source_branch) catch |err| { 2529 const failure = FeedbackFailure.fromError(err) orelse return err; 2530 try self.rememberThreadFeedback(failure, title, tags, description, target_branch); 2531 return; 2532 }; 2533 title_input.clear(allocator); 2534 tags_input.clear(allocator); 2535 description_input.clear(allocator); 2536 (try formField(form, "target_branch")).clear(allocator); 2537 const route = ui.RoutablePage.repoThreadCommentsRoute(kind, self.data.identity, &event_id_hex, 0) orelse return; 2538 try self.session.navigate(route); 2539 return; 2540 } 2541 2542 var id_bytes: [evt.event_id_size]u8 = undefined; 2543 io.random(&id_bytes); 2544 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 2545 2546 const event = evt.EventWithId{ 2547 .id = event_id_hex, 2548 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 2549 .author = author, 2550 .event = @unionInit(evt.Event, @tagName(kind), Event{ 2551 .title = title, 2552 .description = description, 2553 .tags = tags, 2554 }), 2555 }; 2556 2557 switch (src.repo_kind) { 2558 inline else => |repo_kind| { 2559 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2560 defer any_repo.deinit(io, allocator); 2561 switch (any_repo) { 2562 inline else => |*repo| try evt.consume(self.session.data.host_kind, .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 2563 } 2564 }, 2565 } 2566 2567 // wipe the form so a return visit starts fresh 2568 title_input.clear(allocator); 2569 tags_input.clear(allocator); 2570 description_input.clear(allocator); 2571 2572 const route = listRoute(self.data.identity, @enumFromInt(0), "", &event_id_hex) orelse return; 2573 try self.session.navigate(route); 2574 } 2575 2576 // re-emit the selected thread's event with the form's content (status 2577 // preserved), then reload the thread's page. this is the terminal path; 2578 // the web posts the form to the edit route. 2579 fn submitEditedThread(self: *This, allocator: std.mem.Allocator) !void { 2580 if (comptime wasm) return; 2581 const io = self.session.io orelse return; 2582 const entry = self.data.selectedThread() orelse return; 2583 2584 const form = self.threadForm() orelse return; 2585 const title_input = try formField(form, "title"); 2586 const tags_input = try formField(form, "tags"); 2587 const description_input = try formField(form, "description"); 2588 2589 const title = try title_input.text(allocator); 2590 defer allocator.free(title); 2591 const tags = try tags_input.text(allocator); 2592 defer allocator.free(tags); 2593 const description = try description_input.text(allocator); 2594 defer allocator.free(description); 2595 const target_branch = if (comptime supports_drafts) try (try formField(form, "target_branch")).text(allocator) else ""; 2596 defer if (comptime supports_drafts) allocator.free(target_branch); 2597 2598 if (!Event.fieldsValid(title, tags)) { 2599 if (!evt.titleValid(title)) try self.rememberThreadFeedback(.required_title, title, tags, description, target_branch); 2600 return; 2601 } 2602 const src = self.data.repo_source orelse return; 2603 2604 if (comptime supports_drafts) { 2605 if (entryDraft(entry.*)) { 2606 self.data.editDraft(self.session, allocator, entry.id, title, tags, description, target_branch) catch |err| { 2607 const failure = FeedbackFailure.fromError(err) orelse return err; 2608 try self.rememberThreadFeedback(failure, title, tags, description, target_branch); 2609 return; 2610 }; 2611 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2612 try self.session.navigate(route); 2613 return; 2614 } 2615 } 2616 2617 const id_bytes = try evt.parseEventId(entry.id); 2618 const author = (try self.session.eventAuthor()) orelse return; 2619 2620 switch (src.repo_kind) { 2621 inline else => |repo_kind| { 2622 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2623 defer any_repo.deinit(io, allocator); 2624 switch (any_repo) { 2625 inline else => |*repo| if (supports_drafts) { 2626 Event.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2627 .title = title, 2628 .tags = tags, 2629 .description = description, 2630 .target_branch = target_branch, 2631 } }, author) catch |err| { 2632 const failure = FeedbackFailure.fromError(err) orelse return err; 2633 try self.rememberThreadFeedback(failure, title, tags, description, target_branch); 2634 return; 2635 }; 2636 } else if (has_status) 2637 try Event.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2638 .title = title, 2639 .tags = tags, 2640 .description = description, 2641 } }, author) 2642 else 2643 try Event.update(self.session.data.host_kind, repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, tags, description, author), 2644 } 2645 }, 2646 } 2647 2648 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2649 try self.session.navigate(route); 2650 } 2651 2652 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, tags: []const u8, description: []const u8, target_branch: []const u8) !void { 2653 const aa = self.session.arena.allocator(); 2654 const source = if (supports_drafts) blk: { 2655 const form = self.threadForm() orelse break :blk null; 2656 break :blk formWidget(form, .patch_source); 2657 } else null; 2658 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 2659 .failure = failure, 2660 .fields = if (comptime supports_drafts) .{ 2661 .title = try aa.dupe(u8, title), 2662 .tags = try aa.dupe(u8, tags), 2663 .description = try aa.dupe(u8, description), 2664 .target_branch = try aa.dupe(u8, target_branch), 2665 .source_branch = if (source) |value| try value.field().text(aa) else "", 2666 .source_kind = if (source) |value| value.selected else .fork, 2667 } else .{ 2668 .title = try aa.dupe(u8, title), 2669 .tags = try aa.dupe(u8, tags), 2670 .description = try aa.dupe(u8, description), 2671 }, 2672 }); 2673 } 2674 2675 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 2676 switch (confirmation(self.data.view) orelse return) { 2677 .publish => if (comptime supports_drafts) { 2678 if (comptime wasm) return; 2679 const entry = self.data.selectedThread() orelse return; 2680 if (!entryDraft(entry.*)) return; 2681 try self.data.publishDraft(self.session, allocator, entry.id); 2682 const route = listRoute(self.data.identity, @enumFromInt(0), "", entry.id) orelse return; 2683 try self.session.navigate(route); 2684 } else unreachable, 2685 .merge => if (comptime supports_merge) { 2686 if (comptime wasm) return; 2687 const entry = self.data.selectedThread() orelse return; 2688 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 2689 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 2690 self.data.mergePatch(self.session, allocator, entry.id, revision) catch |err| switch (err) { 2691 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 2692 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2693 try self.session.navigate(route); 2694 return; 2695 }, 2696 else => return err, 2697 }; 2698 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2699 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2700 try self.session.navigate(route); 2701 } else unreachable, 2702 .remove => try self.submitRemove(allocator), 2703 } 2704 } 2705 2706 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2707 const comment = self.data.comment_id.len != 0; 2708 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2709 const id = evt.parseEventId(event_id) catch return; 2710 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2711 } 2712 2713 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2714 if (comptime wasm) return; 2715 2716 if (comptime supports_drafts) { 2717 const selected = self.data.selectedThread() orelse return; 2718 if (event_kind == kind and entryDraft(selected.*)) { 2719 try Data.removeDraft(self.session, allocator, &id); 2720 const route = draftsRoute(self.data.identity) orelse return; 2721 try self.session.navigate(route); 2722 return; 2723 } 2724 } 2725 2726 const io = self.session.io orelse return; 2727 const src = self.data.repo_source orelse return; 2728 const author = (try self.session.eventAuthor()) orelse return; 2729 2730 switch (src.repo_kind) { 2731 inline else => |repo_kind| { 2732 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2733 defer any_repo.deinit(io, allocator); 2734 switch (any_repo) { 2735 inline else => |*repo| try evt.remove(self.session.data.host_kind, .repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2736 } 2737 }, 2738 } 2739 2740 const id_hex = std.fmt.bytesToHex(id, .lower); 2741 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2742 try self.session.navigate(route); 2743 } 2744 2745 // return to the list. 2746 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2747 root_focus.setFocus(self.listScroll(index).getFocus().id); 2748 } 2749 2750 // cross to the header tabs above the stack. 2751 fn focusHeader(self: *This, root_focus: *Focus) void { 2752 root_focus.setFocus(self.box.children.keys()[header_index]); 2753 } 2754 2755 pub fn clearGrid(self: *This) void { 2756 self.box.clearGrid(); 2757 } 2758 2759 pub fn getGrid(self: This) ?Grid { 2760 return self.box.getGrid(); 2761 } 2762 2763 pub fn getFocus(self: *This) *Focus { 2764 return self.box.getFocus(); 2765 } 2766 2767 // for the parent's "scroll up at the top jumps to the header" check: at the 2768 // top only while the header tabs hold focus, so up from the split 2769 // crosses into the tabs first. 2770 pub fn atTop(self: *This) bool { 2771 return self.headerActive(); 2772 } 2773 }; 2774 } 2775