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'import { leadLook } from './styles.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 {pLead = leadLookavatarField {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" Style.pLead "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
- d69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmre
- 3a64dc48ident#34: chipLook: radius as the same var() string (a bare token name in a static does not compile); selector gate selectormre
- eb039073ident#34: tests: signin and migration find the choice without the classmre
- 4b94a594ident#34: tests: fix selector of the identity choicemre
- bebc88e4ident#34: main.hl drops the unstyled classes inboxlink and whomre
- b4e7ad04ident#34: the identity choice link/button has no class (rule on #chooselist a)mre
- 3c33d6eaident#34: the connection link in inbox has no class (rule on #conns a)mre
- dc97ec0dident#34: the Notif. chip and the Used in link share chipLook (Style.pChip) instead of the classes chip/used/notifmre
- 378bd432ident#34: the identity picture look is a static in styles.hl (Style.pAvatar); sizes stay with each listmre
- 1cf79e7eident#34: the wide page column is a static in styles.hl (Style.pWide), not the class "wide"mre
- ddc7d135Merge branch 'f7-hooks' into mainIdent
- eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
- ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
- 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
- 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
- 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
- 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
- 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
- e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
- fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre