╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ NewRepo.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
97 if (direction == .up or key == .back_tab) return if (cur > 0) root_focus.setFocus(self.formBox().children.keys()[cur - 1]); 98 if (direction == .down or key == .tab) return if (cur + 1 < self.formBox().children.count()) root_focus.setFocus(self.formBox().children.keys()[cur + 1]); 99 switch (key) { 100 .enter => if (on_submit) return self.submitForm(allocator), 101 .mouse => |mouse| if (on_submit) { 102 if (inp.leftClickOn(root_focus, child.widget.submit_button.buttonId(), mouse)) return self.submitForm(allocator); 103 }, 104 else => {}, 105 } 106 try child.widget.input(allocator, key, root_focus); 107 } 108 109 fn formRadio(form: *wgt.Box(ui.Widget), name: []const u8) !*ui.widget.Radio { 110 for (form.children.values()) |*child| switch (child.widget) { 111 .radio => |*radio| if (std.mem.eql(u8, radio.name, name)) return radio, 112 else => {}, 113 }; 114 return error.MissingFormField; 115 } 116 117 fn formField(form: *wgt.Box(ui.Widget), name: []const u8) !*wgt.TextInput { 118 for (form.children.values()) |*child| switch (child.widget) { 119 .text_input => |*text_input| if (std.mem.eql(u8, text_input.options.name, name)) return text_input, 120 else => {}, 121 }; 122 return error.MissingFormField; 123 } 124 125 // create the repo and navigate to it. this is the terminal path; the web 126 // posts the form to the new-repo route. 127 fn submitForm(self: *View, allocator: std.mem.Allocator) !void { 128 if (comptime wasm) return; 129 const io = self.session.io orelse return; 130 const users_dir = self.session.users_dir orelse return; 131 const admin_repo = self.session.admin_repo orelse return; 132 const user_id = self.session.userId() orelse return; 133 const moment = try evt.currentMoment(evt.admin_repo_opts, admin_repo); 134 const user = (try ui.activeUser(moment, self.session.page_arena, user_id)) orelse return; 135 136 const name_input = try formField(self.formBox(), "name"); 137 const description_input = try formField(self.formBox(), "description"); 138 const name = try name_input.text(allocator); 139 defer allocator.free(name); 140 const description = try description_input.text(allocator); 141 defer allocator.free(description); 142 const hash_kind = std.meta.stringToEnum(hash.HashKind, (try formRadio(self.formBox(), "hash")).selected()) orelse unreachable; 143 const access = std.meta.stringToEnum(evt.Repo.Access, (try formRadio(self.formBox(), "access")).selected()) orelse unreachable; 144 145 _ = evt.createRepo(io, allocator, users_dir, &user_id, .{ .name = user.event.name, .email = user.event.email }, name, description, access, hash_kind) catch |err| { 146 const failure = ui.Session.FormFeedback.RepoFailure.fromError(err) orelse return err; 147 const aa = self.session.arena.allocator(); 148 self.session.data.form_feedback = .{ .repo = .{ .failure = failure, .fields = .{ 149 .name = try aa.dupe(u8, name), 150 .description = try aa.dupe(u8, description), 151 .hash = hash_kind, 152 .access = access, 153 } } }; 154 return; 155 }; 156 157 // wipe the form so a return visit starts fresh 158 name_input.clear(allocator); 159 description_input.clear(allocator); 160 161 const identity = try self.session.page_arena.allocator().print("{s}:{s}", .{ user.event.name, name }); 162 try self.session.navigate(ui.RoutablePage.repoFilesRoute(identity, null, "", "", 0) orelse return); 163 } 164 165 fn formBox(self: *View) *wgt.Box(ui.Widget) { 166 return &self.center.child.box; 167 } 168 169 pub fn clearGrid(self: *View) void { 170 self.center.clearGrid(); 171 } 172 173 pub fn getGrid(self: View) ?Grid { 174 return self.center.getGrid(); 175 } 176 177 pub fn getFocus(self: *View) *Focus { 178 return self.center.getFocus(); 179 } 180 181 // up leaves the form from its first control 182 pub fn atTop(self: View) bool { 183 const box = &self.center.child.box; 184 return box.focus.child_id == box.children.keys()[0]; 185 } 186 }; 187