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