╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Threads.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2019 if (!Event.fieldsValid(title, tags)) return; 2020 2021 var id_bytes: [evt.event_id_size]u8 = undefined; 2022 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2023 2024 switch (src.repo_kind) { 2025 inline else => |repo_kind| { 2026 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2027 defer any_repo.deinit(io, allocator); 2028 switch (any_repo) { 2029 inline else => |*repo| if (has_status) 2030 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2031 .title = title, 2032 .tags = tags, 2033 .description = description, 2034 } }, author) 2035 else 2036 try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, title, tags, description, author), 2037 } 2038 }, 2039 } 2040 2041 const route = listRoute(self.data.identity, entryStatus(entry.*), "", entry.id) orelse return; 2042 try self.session.navigate(route); 2043 } 2044 2045 fn removeThread(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2046 const sel = self.detailed_index[index] orelse return; 2047 const entry = self.window(index).items[sel]; 2048 2049 var id_bytes: [evt.event_id_size]u8 = undefined; 2050 _ = std.fmt.hexToBytes(&id_bytes, entry.id) catch return; 2051 try self.removeEvent(allocator, kind, id_bytes); 2052 } 2053 2054 fn removeComment(self: *This, allocator: std.mem.Allocator, comment: *Comment.Item) !void { 2055 try self.removeEvent(allocator, .comment, comment.id); 2056 } 2057 2058 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2059 if (comptime wasm) return; 2060 const io = self.session.io orelse return; 2061 const src = self.data.repo_source orelse return; 2062 const author = (try self.session.eventAuthor()) orelse return; 2063 2064 switch (src.repo_kind) { 2065 inline else => |repo_kind| { 2066 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2067 defer any_repo.deinit(io, allocator); 2068 switch (any_repo) { 2069 inline else => |*repo| try evt.remove(repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2070 } 2071 }, 2072 } 2073 2074 const id_hex = std.fmt.bytesToHex(id, .lower); 2075 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2076 try self.session.navigate(route); 2077 } 2078 2079 // flip the shown issue's status by re-emitting its event, then reload the 2080 // page rooted at the issue so the view reflects the change. this is the 2081 // terminal path; the web posts the button's form to the status route. 2082 fn toggleStatus(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2083 if (comptime !has_status) return; 2084 if (comptime wasm) return; 2085 const io = self.session.io orelse return; 2086 const src = self.data.repo_source orelse return; 2087 const sel = self.detailed_index[index] orelse return; 2088 const entry = self.window(index).items[sel]; 2089 const author = (try self.session.eventAuthor()) orelse return; 2090 2091 const status: Status = switch (entryStatus(entry)) { 2092 .open => .closed, 2093 .closed => .open, 2094 }; 2095 2096 var id_bytes: [evt.event_id_size]u8 = undefined; 2097 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2098 2099 switch (src.repo_kind) { 2100 inline else => |repo_kind| { 2101 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2102 defer any_repo.deinit(io, allocator); 2103 switch (any_repo) { 2104 inline else => |*repo| try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author), 2105 } 2106 }, 2107 } 2108 2109 const route = listRoute(self.data.identity, status, "", entry.id) orelse return; 2110 try self.session.navigate(route); 2111 } 2112 2113 // arrow keys move the tag selection; at the flow's edges focus crosses to 2114 // the neighboring widgets. 2115 fn tagsInput(self: *This, index: usize, key: Key, root_focus: *Focus) !void { 2116 const tf = self.tagFlow(index) orelse return; 2117 const cid = tf.focus.child_id orelse return; 2118 const cur = tf.indexOfFocusId(cid) orelse return; 2119 const count = tf.text_boxes.items.len; 2120 switch (key) { 2121 .arrow_left => if (cur > 0) self.focusTag(index, tf, root_focus, cur - 1) else try self.focusList(index, root_focus), 2122 .arrow_right => if (cur + 1 < count) self.focusTag(index, tf, root_focus, cur + 1), 2123 .arrow_up => if (tf.rowStep(cur, false)) |i| { 2124 self.focusTag(index, tf, root_focus, i); 2125 } else { 2126 _ = self.moveDetailVertical(index, root_focus, false); 2127 }, 2128 .arrow_down => if (tf.rowStep(cur, true)) |i| { 2129 self.focusTag(index, tf, root_focus, i); 2130 } else { 2131 _ = self.moveDetailVertical(index, root_focus, true); 2132 }, 2133 .home => self.focusTag(index, tf, root_focus, 0), 2134 .end => self.focusTag(index, tf, root_focus, count - 1), 2135 else => {}, 2136 } 2137 } 2138 2139 const title_child_index: usize = 0; 2140 const tags_child_index: usize = 2; 2141 2142 // the tool row's first child after the spacer that pushes it right 2143 const first_in_row_index: usize = 1; 2144 2145 fn tagFlow(self: *This, index: usize) ?*ui.TagFlow { 2146 const inner = self.detailInner(index); 2147 if (inner.children.count() <= tags_child_index) return null; 2148 return switch (inner.children.values()[tags_child_index].widget) { 2149 .tag_flow => |*tf| tf, 2150 else => null, 2151 }; 2152 } 2153 2154 fn tagsFocused(self: *This, index: usize) bool { 2155 const inner = self.detailInner(index); 2156 const cid = inner.getFocus().child_id orelse return false; 2157 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null; 2158 } 2159 2160 fn toolRowFocused(self: *This, index: usize) bool { 2161 const outer = self.detailOuter(index); 2162 const cid = outer.getFocus().child_id orelse return false; 2163 return outer.children.getIndex(cid) == tool_row_index; 2164 } 2165 2166 fn focusTag(self: *This, index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2167 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2168 // keep the tag visible on the terminal: its rect offset by the flow's 2169 // position in the pane. 2170 if (self.session.is_terminal and item < tf.rects.items.len) { 2171 if (self.detailInner(index).children.values()[tags_child_index].rect) |flow_rect| { 2172 var rect = tf.rects.items[item]; 2173 rect.x += flow_rect.x; 2174 rect.y += flow_rect.y; 2175 self.detailScroll(index).scrollToRect(rect); 2176 } 2177 } 2178 } 2179 2180 fn titleFocused(self: *This, index: usize) bool { 2181 const inner = self.detailInner(index); 2182 const cid = inner.getFocus().child_id orelse return false; 2183 return inner.children.getIndex(cid) == title_child_index; 2184 } 2185 2186 fn authorFocused(self: *This, index: usize) bool { 2187 const inner = self.detailInner(index); 2188 const cid = inner.getFocus().child_id orelse return false; 2189 return cid == self.author_id[index]; 2190 } 2191 2192 fn descriptionFocused(self: *This, index: usize) bool { 2193 const cid = self.detailInner(index).getFocus().child_id orelse return false; 2194 return cid == self.description_id[index]; 2195 } 2196 2197 // return to the tool row's last-focused button (the header when the 2198 // description page shows no row). 2199 fn focusToolRow(self: *This, index: usize, root_focus: *Focus) void { 2200 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2201 root_focus.setFocus(cid); 2202 } 2203 2204 // enter the detail pane. an empty pane (no issues) can't be entered. 2205 fn focusDetail(self: *This, index: usize, root_focus: *Focus) !void { 2206 if (self.detailInner(index).children.count() == 0) return; 2207 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2208 } 2209 2210 // return to the list. 2211 fn focusList(self: *This, index: usize, root_focus: *Focus) !void { 2212 root_focus.setFocus(self.listScroll(index).getFocus().id); 2213 } 2214 2215 // cross to the header tabs above the stack. 2216 fn focusHeader(self: *This, root_focus: *Focus) void { 2217 root_focus.setFocus(self.box.children.keys()[header_index]); 2218 } 2219 2220 pub fn clearGrid(self: *This) void { 2221 self.box.clearGrid(); 2222 } 2223 2224 pub fn getGrid(self: This) ?Grid { 2225 return self.box.getGrid(); 2226 } 2227 2228 pub fn getFocus(self: *This) *Focus { 2229 return self.box.getFocus(); 2230 } 2231 2232 // for the parent's "scroll up at the top jumps to the header" check: at the 2233 // top only while the header tabs hold focus, so up from the split 2234 // crosses into the tabs first. 2235 pub fn getSelectedIndex(self: *This) ?usize { 2236 return if (self.headerActive()) 0 else 1; 2237 } 2238 }; 2239 } 2240