╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2613 2614 switch (src.repo_kind) { 2615 inline else => |repo_kind| { 2616 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2617 defer any_repo.deinit(io, allocator); 2618 switch (any_repo) { 2619 inline else => |*repo| if (supports_drafts) { 2620 Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2621 .title = title, 2622 .tags = tags, 2623 .description = description, 2624 .target_branch = target_branch, 2625 } }, author) catch |err| switch (err) { 2626 error.InvalidFields => { 2627 try self.rememberThreadFeedback(.invalid_target_branch, title, tags, description, target_branch); 2628 return; 2629 }, 2630 else => |other| return other, 2631 }; 2632 } else if (has_status) 2633 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2634 .title = title, 2635 .tags = tags, 2636 .description = description, 2637 } }, author) 2638 else 2639 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, tags, description, author), 2640 } 2641 }, 2642 } 2643 2644 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2645 try self.session.navigate(route); 2646 } 2647 2648 fn rememberThreadFeedback(self: *This, failure: FeedbackFailure, title: []const u8, tags: []const u8, description: []const u8, target_branch: []const u8) !void { 2649 const aa = self.session.arena.allocator(); 2650 self.session.data.form_feedback = @unionInit(ui.Session.FormFeedback, @tagName(feedback_tag), .{ 2651 .failure = failure, 2652 .fields = if (comptime supports_drafts) .{ 2653 .title = try aa.dupe(u8, title), 2654 .tags = try aa.dupe(u8, tags), 2655 .description = try aa.dupe(u8, description), 2656 .target_branch = try aa.dupe(u8, target_branch), 2657 } else .{ 2658 .title = try aa.dupe(u8, title), 2659 .tags = try aa.dupe(u8, tags), 2660 .description = try aa.dupe(u8, description), 2661 }, 2662 }); 2663 } 2664 2665 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 2666 switch (confirmation(self.data.view) orelse return) { 2667 .publish => if (comptime supports_drafts) { 2668 if (comptime wasm) return; 2669 const entry = self.data.selectedThread() orelse return; 2670 if (!entryDraft(entry.*)) return; 2671 try self.data.publishDraft(self.session, allocator, entry.id); 2672 const route = listRoute(self.data.identity, @enumFromInt(0), "", entry.id) orelse return; 2673 try self.session.navigate(route); 2674 } else unreachable, 2675 .merge => if (comptime supports_merge) { 2676 if (comptime wasm) return; 2677 const entry = self.data.selectedThread() orelse return; 2678 try self.data.mergePatch(self.session, allocator, entry.id, button_index > 1); 2679 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2680 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2681 try self.session.navigate(route); 2682 } else unreachable, 2683 .remove => try self.submitRemove(allocator), 2684 } 2685 } 2686 2687 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2688 const comment = self.data.comment_id.len != 0; 2689 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2690 const id = evt.parseEventId(event_id) catch return; 2691 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2692 } 2693 2694 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2695 if (comptime wasm) return; 2696 2697 if (comptime supports_drafts) { 2698 const selected = self.data.selectedThread() orelse return; 2699 if (event_kind == kind and entryDraft(selected.*)) { 2700 try Data.removeDraft(self.session, allocator, &id); 2701 const route = draftsRoute(self.data.identity) orelse return; 2702 try self.session.navigate(route); 2703 return; 2704 } 2705 } 2706 2707 const io = self.session.io orelse return; 2708 const src = self.data.repo_source orelse return; 2709 const author = (try self.session.eventAuthor()) orelse return; 2710 2711 switch (src.repo_kind) { 2712 inline else => |repo_kind| { 2713 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2714 defer any_repo.deinit(io, allocator); 2715 switch (any_repo) { 2716 inline else => |*repo| try evt.remove(.repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2717 } 2718 }, 2719 } 2720 2721 const id_hex = std.fmt.bytesToHex(id, .lower); 2722 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2723 try self.session.navigate(route); 2724 } 2725 2726 // return to the list. 2727 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2728 root_focus.setFocus(self.listScroll(index).getFocus().id); 2729 } 2730 2731 // cross to the header tabs above the stack. 2732 fn focusHeader(self: *This, root_focus: *Focus) void { 2733 root_focus.setFocus(self.box.children.keys()[header_index]); 2734 } 2735 2736 pub fn clearGrid(self: *This) void { 2737 self.box.clearGrid(); 2738 } 2739 2740 pub fn getGrid(self: This) ?Grid { 2741 return self.box.getGrid(); 2742 } 2743 2744 pub fn getFocus(self: *This) *Focus { 2745 return self.box.getFocus(); 2746 } 2747 2748 // for the parent's "scroll up at the top jumps to the header" check: at the 2749 // top only while the header tabs hold focus, so up from the split 2750 // crosses into the tabs first. 2751 pub fn atTop(self: *This) bool { 2752 return self.headerActive(); 2753 } 2754 }; 2755 } 2756