╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2650 .title = try aa.dupe(u8, title), 2651 .tags = try aa.dupe(u8, tags), 2652 .description = try aa.dupe(u8, description), 2653 }, 2654 }); 2655 } 2656 2657 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 2658 switch (confirmation(self.data.view) orelse return) { 2659 .publish => if (comptime supports_drafts) { 2660 if (comptime wasm) return; 2661 const entry = self.data.selectedThread() orelse return; 2662 if (!entryDraft(entry.*)) return; 2663 try self.data.publishDraft(self.session, allocator, entry.id); 2664 const route = listRoute(self.data.identity, @enumFromInt(0), "", entry.id) orelse return; 2665 try self.session.navigate(route); 2666 } else unreachable, 2667 .merge => if (comptime supports_merge) { 2668 if (comptime wasm) return; 2669 const entry = self.data.selectedThread() orelse return; 2670 try self.data.mergePatch(self.session, allocator, entry.id, button_index > 1); 2671 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 2672 const route = listRoute(self.data.identity, merged, "", entry.id) orelse return; 2673 try self.session.navigate(route); 2674 } else unreachable, 2675 .remove => try self.submitRemove(allocator), 2676 } 2677 } 2678 2679 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 2680 const comment = self.data.comment_id.len != 0; 2681 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 2682 const id = evt.parseEventId(event_id) catch return; 2683 try self.removeEvent(allocator, if (comment) .comment else kind, id); 2684 } 2685 2686 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2687 if (comptime wasm) return; 2688 2689 if (comptime supports_drafts) { 2690 const selected = self.data.selectedThread() orelse return; 2691 if (event_kind == kind and entryDraft(selected.*)) { 2692 try Data.removeDraft(self.session, allocator, &id); 2693 const route = draftsRoute(self.data.identity) orelse return; 2694 try self.session.navigate(route); 2695 return; 2696 } 2697 } 2698 2699 const io = self.session.io orelse return; 2700 const src = self.data.repo_source orelse return; 2701 const author = (try self.session.eventAuthor()) orelse return; 2702 2703 switch (src.repo_kind) { 2704 inline else => |repo_kind| { 2705 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2706 defer any_repo.deinit(io, allocator); 2707 switch (any_repo) { 2708 inline else => |*repo| try evt.remove(.repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2709 } 2710 }, 2711 } 2712 2713 const id_hex = std.fmt.bytesToHex(id, .lower); 2714 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2715 try self.session.navigate(route); 2716 } 2717 2718 // return to the list. 2719 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2720 root_focus.setFocus(self.listScroll(index).getFocus().id); 2721 } 2722 2723 // cross to the header tabs above the stack. 2724 fn focusHeader(self: *This, root_focus: *Focus) void { 2725 root_focus.setFocus(self.box.children.keys()[header_index]); 2726 } 2727 2728 pub fn clearGrid(self: *This) void { 2729 self.box.clearGrid(); 2730 } 2731 2732 pub fn getGrid(self: This) ?Grid { 2733 return self.box.getGrid(); 2734 } 2735 2736 pub fn getFocus(self: *This) *Focus { 2737 return self.box.getFocus(); 2738 } 2739 2740 // for the parent's "scroll up at the top jumps to the header" check: at the 2741 // top only while the header tabs hold focus, so up from the split 2742 // crosses into the tabs first. 2743 pub fn getSelectedIndex(self: *This) ?usize { 2744 return if (self.headerActive()) 0 else 1; 2745 } 2746 }; 2747 } 2748