╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ UserSettings.zig ─────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
184 // the rect of the control at `index` in the form's space; a password's is 185 // offset by its box 186 fn controlRect(self: *View, index: usize) ?layout.IRect { 187 const form, const passwords = self.formBoxes(); 188 return switch (index) { 189 0 => form.children.values()[0].rect, 190 self.control_ids.len - 1 => form.children.values()[submit_index].rect, 191 else => { 192 const outer = form.children.values()[passwords_index].rect orelse return null; 193 const inner = passwords.children.values()[index - 1].rect orelse return null; 194 return .{ .x = outer.x + inner.x, .y = outer.y + inner.y, .size = inner.size }; 195 }, 196 }; 197 } 198 199 // update the user. this is the terminal path; the web posts the form to 200 // the user route. 201 fn submitForm(self: *View, allocator: std.mem.Allocator) !void { 202 if (comptime wasm) return; 203 const io = self.session.io orelse return; 204 const users_dir = self.session.users_dir orelse return; 205 const admin_repo = self.session.admin_repo orelse return; 206 const user_id = self.session.userId() orelse return; 207 208 const email = try (try self.formField("email")).text(allocator); 209 defer allocator.free(email); 210 const current_password = try (try self.formField("current_password")).text(allocator); 211 defer allocator.free(current_password); 212 const new_password = try (try self.formField("new_password")).text(allocator); 213 defer allocator.free(new_password); 214 const new_password_again = try (try self.formField("new_password_again")).text(allocator); 215 defer allocator.free(new_password_again); 216 217 evt.updateUser(io, allocator, users_dir, admin_repo, &user_id, email, current_password, new_password, new_password_again) catch |err| switch (err) { 218 // the account was removed under them 219 error.NotFound => return ui.UserNotifications.logOut(self.session), 220 else => { 221 const failure = ui.Session.FormFeedback.UserFailure.fromError(err) orelse return err; 222 const aa = self.session.arena.allocator(); 223 self.session.data.form_feedback = .{ .user_settings = .{ .failure = failure, .fields = .{ .email = try aa.dupe(u8, email) } } }; 224 return; 225 }, 226 }; 227 228 // reload the page with the saved email and the password fields cleared 229 self.session.haxy_moment = try evt.currentMoment(evt.admin_repo_opts, admin_repo); 230 try self.session.loadUser(); 231 try self.session.navigate(self.session.data.current_page); 232 } 233 234 fn formScroll(self: *View) *wgt.Scroll(ui.Widget) { 235 return &self.box.children.values()[scroll_index].widget.scroll; 236 } 237 238 fn formBox(self: *View) *wgt.Box(ui.Widget) { 239 return &self.formScroll().child.center.child.box; 240 } 241 242 pub fn clearGrid(self: *View) void { 243 self.box.clearGrid(); 244 } 245 246 pub fn getGrid(self: View) ?Grid { 247 return self.box.getGrid(); 248 } 249 250 pub fn getFocus(self: *View) *Focus { 251 return self.box.getFocus(); 252 } 253 254 // up leaves the view from the first control 255 pub fn atTop(self: *View, root_focus: *Focus) bool { 256 return root_focus.grandchild_id == self.control_ids[0]; 257 } 258 }; 259