ident
All repositories: gitoria
5.9 KB
// components/identityform.hl — THE IDENTITY FORM (ident#40.3), placed by components/home.hl while it is open: a new identity, an edit,// and right after the first login the default identity ("welcome": the names are optional, Skip closes it). The host decides what// the form shows and passes it in: the heading, whether it is the welcome form, which identity (editId, or welcomeId for the welcome// form; '' = a new one) and the starting values (the f… fields). This component owns the typing, the avatar picture and the save// (faces addIdentity and editIdentity, lib/identities.hl). Every typed value is also handed up ($parent.setF), so the host's copy// stays the one it resets when it opens the form for another identity. The host shows the messages: $parent.status(message, notice);// $parent.formSaved(rows, text) takes the new rows, $parent.closeForm() closes the form (Skip, Cancel).import { accountOfSession } from '../lib/accounts.hl'import { identityRows, createIdentity, updateIdentity } from '../lib/identities.hl'editHeading = ''welcome = falsenotWelcome = !welcome // `if (!welcome)` in a View renders nothing: an `if` takes a membereditId = ''welcomeId = ''fIdentityName = ''fNickname = ''fFirstname = ''fLastname = ''fAvatar = ''hasAvatarPreview = false// the preview and the Remove button are hidden (the attribute) while there is no picturenoAvatarPreview = !hasAvatarPreviewStyle {avatarField {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.6rem'// real Chrome: a file input has an intrinsic width (its "No file chosen" text) that pushed the form to 413 px at 390: every item may shrinklabel {flex = '1 1 12rem'minWidth = '0'}}'#avatarpreview' {width = '48px'height = '48px'objectFit = 'cover'borderRadius = '50%'background = 'var(--color-background-sunken)'}'#identityform input[type=file]' {width = '100%'maxWidth = '100%'minWidth = '0'}'#avatarnote' {flexBasis = '100%'color = 'var(--color-danger)'fontSize = '.875rem'empty { display = 'none' }}}View {form { id = "identityform"on submit(e) {e.preventDefault()emit saveForm(e)}h1 { id = "formheading" editHeading }if (welcome) {p { id = "welcome" class = "lead" "Your account is ready and has a default identity. All of these fields are " strong { "optional" } " — fill in what you like, or skip it and do it later." }}label { "Identity name " fieldHint { "(shown when you pick an identity in an app; optional)" }input { id = "fidentityname" name = "identityName" maxlength = "60" autocomplete = "off" value = fIdentityName on input(e) { emit setF('identityName', e.target.value) } }}label { "Nickname " fieldHint { "(optional)" }input { id = "fnickname" name = "nickname" maxlength = "60" autocomplete = "nickname" value = fNickname on input(e) { emit setF('nickname', e.target.value) } }}label { "First name " fieldHint { "(optional)" }input { id = "ffirstname" name = "firstname" maxlength = "60" autocomplete = "given-name" value = fFirstname on input(e) { emit setF('firstname', e.target.value) } }}label { "Last name " fieldHint { "(optional)" }input { id = "flastname" name = "lastname" maxlength = "60" autocomplete = "family-name" value = fLastname on input(e) { emit setF('lastname', e.target.value) } }}avatarField {img { id = "avatarpreview" hidden = noAvatarPreview src = fAvatar alt = "" width = "48" height = "48" }label { "Avatar " fieldHint { "(optional; a picture apps can show, e.g. next to your comments)" }input { id = "favatarfile" type = "file" accept = "image/png,image/jpeg,image/webp,image/gif" }}input { id = "favatar" name = "avatar" type = "hidden" value = fAvatar on input(e) { emit setF('avatar', e.target.value) } }button { id = "avatarremove" type = "button" class = "quiet small" hidden = noAvatarPreview "Remove picture" on click(e) { emit setF('avatar', '') } }span { id = "avatarnote" }}formButtons {button { id = "saveidentity" type = "submit" "Save" }if (welcome) { button { id = "skip" type = "button" class = "quiet" "Skip" on click(e) { $parent.closeForm() } } }if (notWelcome) { button { id = "cancel" type = "button" class = "quiet" "Cancel" on click(e) { $parent.closeForm() } } }}}}on setF(name, v) {if (name == 'identityName') { fIdentityName = v }if (name == 'nickname') { fNickname = v }if (name == 'firstname') { fFirstname = v }if (name == 'lastname') { fLastname = v }if (name == 'avatar') { fAvatar = v hasAvatarPreview = v.trim() != '' }$parent.setF(name, v)}on saveForm(e) {$parent.status('', '')fields = { identityName = fIdentityName nickname = fNickname firstname = fFirstname lastname = fLastname avatar = fAvatar }let r = nullif (editId == '' && welcome) {r = emit server editIdentity('' + welcomeId, fields)} else if (editId == '') {r = emit server addIdentity(fields)} else {r = emit server editIdentity('' + editId, fields)}if (r == null) {$parent.status('the server did not answer — try again', '')return null}if (r.error != null) {$parent.status(r.error, '')return null}$parent.formSaved(r.identities, editId == '' && !welcome ? 'Identity created.' : 'Identity saved.')}// A face runs on a BLANK instance (its arguments and its imports only); the account comes from the session.on server addIdentity(fields, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = createIdentity(me.id, fields)if (r.error != null) { return r }return { identity = r.identity identities = identityRows(me.id) }}on server editIdentity(id, fields, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = updateIdentity(me.id, id, fields)if (r.error != null) { return r }return { identity = r.identity identities = identityRows(me.id) }}
Branches
Latest commits
- 40bf3b97ident#33: the 404 page's home link rule moves into notfound.hlmre
- 40627a89ident#33: the time zone section's spacing moves into timezone.hlmre
- d389db08ident#33: the identity page's rules and the Notif. chip move into identity.hl's Stylemre
- ddda0b5bident#33: the identity row's parts move into identitylist.hl's Stylemre
- 47e516afident#33 ident#34: the identity form's avatar rules move into identityform.hl; the preview and Remove button are hidden with the hidden attribute instead of built class strings (avatarPreviewClass, avatarRemoveClass gone)mre
- 5cb5cf0eident#33: the code field's look moves into codestep.hl's Stylemre
- f421cd60ident#33: the shell's own rules (user menu address, offline note, network probe) move into main.hl's Stylemre
- c512fb96Merge branch 'f4-homesplit' into mainIdent
- 07d1717c|||PR ident#40 home.hl is split into components, one per area: email step, identity form, identity list, app identity choice, time zone; each moves its faces with it, the email step is shared with embed.hl (#40.3, rest of #40.2)mre
- 59e8fcc1ident#40.3: the app's identity choice is one component (components/chooseidentity.hl); its face chooseIdentity moves with itmre
- e23efdfcident#40.3: the identity list is one component (components/identitylist.hl); its delete and face dropIdentity move with itmre
- e24b59a6ident#40.3: the time zone is one component (components/timezone.hl); its face changeTimeZone moves with itmre
- 8cbc5717ident#40.3: the email step is one component (components/emailstep.hl) placed by home.hl and embed.hlmre
- 6fad3bd2Merge branch 'f3-codestep' into mainIdent
- 51e387f2|||PR ident#40 the code step is one component (components/codestep.hl) placed by home.hl and embed.hl; its verify face, setCode, browserZone and verify call exist once (#40.2)mre
- c28bddeeMerge branch 'f2-shell' into mainIdent
- c3a40ff6|||PR ident#40 one shell for the app and /start (account part off on /start, #40.1); startshell.hl removed; unused signOut faces gone (#40.4)mre
- 060f3870ident#40.4: use the shell sign-out faces in regression gatesmre
- 9b94aa6aMerge branch 'f1b-cleanup' into mainIdent
- edcfce3f|||PR ident#41 ident#43 ident#44 login error page as a component (same status codes and text, pixel-identical), declarations and route wiring cleaned upmre