╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ UserKeys.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
207 if (inp.rowDelta(key, @intCast(rows.children.count()))) |delta| { 208 ui.widget.moveRowFocus(rows, &self.scroll, root_focus, delta); 209 return; 210 } 211 // a row's ✕ is a link the host follows 212 if (key == .arrow_left or key == .arrow_right) _ = ui.widget.moveInSelectedRow(rows, root_focus, key == .arrow_right); 213 } 214 215 // the terminal changes the keys itself; the web posts the form instead 216 fn addKey(self: *View, allocator: std.mem.Allocator, key: []const u8) !void { 217 if (comptime wasm) return; 218 const io = self.session.io orelse return; 219 const users_dir = self.session.users_dir orelse return; 220 const admin_repo = self.session.admin_repo orelse return; 221 const user_id = self.session.userId() orelse return; 222 evt.addUserKey(io, allocator, users_dir, admin_repo, &user_id, key) catch |err| switch (err) { 223 // the account was removed under them 224 error.NotFound => return ui.UserNotifications.logOut(self.session), 225 else => { 226 const failure = ui.Session.FormFeedback.KeyFailure.fromError(err) orelse return err; 227 self.session.data.form_feedback = .{ .user_keys = .{ .failure = failure, .key = try self.session.arena.allocator().dupe(u8, key) } }; 228 return; 229 }, 230 }; 231 // reload the page with the keys as they are now 232 self.session.haxy_moment = try evt.currentMoment(evt.admin_repo_opts, admin_repo); 233 try self.session.navigate(self.session.data.current_page); 234 } 235 236 // the terminal removes the key itself; the web posts the form instead 237 fn removeKey(self: *View, allocator: std.mem.Allocator, key: []const u8) !void { 238 if (comptime wasm) return; 239 const io = self.session.io orelse return; 240 const users_dir = self.session.users_dir orelse return; 241 const admin_repo = self.session.admin_repo orelse return; 242 const user_id = self.session.userId() orelse return; 243 const fingerprint = evt.User.fingerprintOfKey(key) orelse unreachable; 244 evt.removeUserKey(io, allocator, users_dir, admin_repo, &user_id, &fingerprint) catch |err| switch (err) { 245 // the account was removed under them 246 error.NotFound => return ui.UserNotifications.logOut(self.session), 247 else => return err, 248 }; 249 self.session.haxy_moment = try evt.currentMoment(evt.admin_repo_opts, admin_repo); 250 try self.session.navigate(self.session.data.current_page.withUserTab(.{ .view = .keys })); 251 } 252 253 pub fn clearGrid(self: *View) void { 254 self.scroll.clearGrid(); 255 } 256 257 pub fn getGrid(self: View) ?Grid { 258 return self.scroll.getGrid(); 259 } 260 261 pub fn getFocus(self: *View) *Focus { 262 return self.scroll.getFocus(); 263 } 264 265 // up leaves the view from the add row or the confirmation 266 pub fn atTop(self: *View) bool { 267 return self.data.confirm != null or self.addActive(); 268 } 269 }; 270