gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7215903e7215903eident#34: access: the unstyled classes all, app, tick, apptick, plus are dropped; the gate finds the app ticks by input[name=app]mre7215903e/components/identityform.hl

5.9 KB

  1. // components/identityform.hl — THE IDENTITY FORM (ident#40.3), placed by components/home.hl while it is open: a new identity, an edit,
  2. // and right after the first login the default identity ("welcome": the names are optional, Skip closes it). The host decides what
  3. // the form shows and passes it in: the heading, whether it is the welcome form, which identity (editId, or welcomeId for the welcome
  4. // form; '' = a new one) and the starting values (the f… fields). This component owns the typing, the avatar picture and the save
  5. // (faces addIdentity and editIdentity, lib/identities.hl). Every typed value is also handed up ($parent.setF), so the host's copy
  6. // stays the one it resets when it opens the form for another identity. The host shows the messages: $parent.status(message, notice);
  7. // $parent.formSaved(rows, text) takes the new rows, $parent.closeForm() closes the form (Skip, Cancel).
  8. import { accountOfSession } from '../lib/accounts.hl'
  9. import { identityRows, createIdentity, updateIdentity } from '../lib/identities.hl'
  10. import { leadLook } from './styles.hl'
  11. editHeading = ''
  12. welcome = false
  13. notWelcome = !welcome // `if (!welcome)` in a View renders nothing: an `if` takes a member
  14. editId = ''
  15. welcomeId = ''
  16. fIdentityName = ''
  17. fNickname = ''
  18. fFirstname = ''
  19. fLastname = ''
  20. fAvatar = ''
  21. hasAvatarPreview = false
  22. // the preview and the Remove button are hidden (the attribute) while there is no picture
  23. noAvatarPreview = !hasAvatarPreview
  24. Style {
  25. pLead = leadLook
  26. avatarField {
  27. display = 'flex'
  28. flexWrap = 'wrap'
  29. alignItems = 'center'
  30. gap = '.6rem'
  31. // 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 shrink
  32. label {
  33. flex = '1 1 12rem'
  34. minWidth = '0'
  35. }
  36. }
  37. '#avatarpreview' {
  38. width = '48px'
  39. height = '48px'
  40. objectFit = 'cover'
  41. borderRadius = '50%'
  42. background = 'var(--color-background-sunken)'
  43. }
  44. '#identityform input[type=file]' {
  45. width = '100%'
  46. maxWidth = '100%'
  47. minWidth = '0'
  48. }
  49. '#avatarnote' {
  50. flexBasis = '100%'
  51. color = 'var(--color-danger)'
  52. fontSize = '.875rem'
  53. empty { display = 'none' }
  54. }
  55. }
  56. View {
  57. form { id = "identityform"
  58. on submit(e) {
  59. e.preventDefault()
  60. emit saveForm(e)
  61. }
  62. h1 { id = "formheading" editHeading }
  63. if (welcome) {
  64. 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." }
  65. }
  66. label { "Identity name " fieldHint { "(shown when you pick an identity in an app; optional)" }
  67. input { id = "fidentityname" name = "identityName" maxlength = "60" autocomplete = "off" value = fIdentityName on input(e) { emit setF('identityName', e.target.value) } }
  68. }
  69. label { "Nickname " fieldHint { "(optional)" }
  70. input { id = "fnickname" name = "nickname" maxlength = "60" autocomplete = "nickname" value = fNickname on input(e) { emit setF('nickname', e.target.value) } }
  71. }
  72. label { "First name " fieldHint { "(optional)" }
  73. input { id = "ffirstname" name = "firstname" maxlength = "60" autocomplete = "given-name" value = fFirstname on input(e) { emit setF('firstname', e.target.value) } }
  74. }
  75. label { "Last name " fieldHint { "(optional)" }
  76. input { id = "flastname" name = "lastname" maxlength = "60" autocomplete = "family-name" value = fLastname on input(e) { emit setF('lastname', e.target.value) } }
  77. }
  78. avatarField {
  79. img { id = "avatarpreview" hidden = noAvatarPreview src = fAvatar alt = "" width = "48" height = "48" }
  80. label { "Avatar " fieldHint { "(optional; a picture apps can show, e.g. next to your comments)" }
  81. input { id = "favatarfile" type = "file" accept = "image/png,image/jpeg,image/webp,image/gif" }
  82. }
  83. input { id = "favatar" name = "avatar" type = "hidden" value = fAvatar on input(e) { emit setF('avatar', e.target.value) } }
  84. button { id = "avatarremove" type = "button" class = "quiet small" hidden = noAvatarPreview "Remove picture" on click(e) { emit setF('avatar', '') } }
  85. span { id = "avatarnote" }
  86. }
  87. formButtons {
  88. button { id = "saveidentity" type = "submit" "Save" }
  89. if (welcome) { button { id = "skip" type = "button" class = "quiet" "Skip" on click(e) { $parent.closeForm() } } }
  90. if (notWelcome) { button { id = "cancel" type = "button" class = "quiet" "Cancel" on click(e) { $parent.closeForm() } } }
  91. }
  92. }
  93. }
  94. on setF(name, v) {
  95. if (name == 'identityName') { fIdentityName = v }
  96. if (name == 'nickname') { fNickname = v }
  97. if (name == 'firstname') { fFirstname = v }
  98. if (name == 'lastname') { fLastname = v }
  99. if (name == 'avatar') { fAvatar = v hasAvatarPreview = v.trim() != '' }
  100. $parent.setF(name, v)
  101. }
  102. on saveForm(e) {
  103. $parent.status('', '')
  104. fields = { identityName = fIdentityName nickname = fNickname firstname = fFirstname lastname = fLastname avatar = fAvatar }
  105. let r = null
  106. if (editId == '' && welcome) {
  107. r = emit server editIdentity('' + welcomeId, fields)
  108. } else if (editId == '') {
  109. r = emit server addIdentity(fields)
  110. } else {
  111. r = emit server editIdentity('' + editId, fields)
  112. }
  113. if (r == null) {
  114. $parent.status('the server did not answer — try again', '')
  115. return null
  116. }
  117. if (r.error != null) {
  118. $parent.status(r.error, '')
  119. return null
  120. }
  121. $parent.formSaved(r.identities, editId == '' && !welcome ? 'Identity created.' : 'Identity saved.')
  122. }
  123. // A face runs on a BLANK instance (its arguments and its imports only); the account comes from the session.
  124. on server addIdentity(fields, session) {
  125. let me = accountOfSession(&session)
  126. if (me == null) { return { error = 'you are not signed in' } }
  127. r = createIdentity(me.id, fields)
  128. if (r.error != null) { return r }
  129. return { identity = r.identity identities = identityRows(me.id) }
  130. }
  131. on server editIdentity(id, fields, session) {
  132. let me = accountOfSession(&session)
  133. if (me == null) { return { error = 'you are not signed in' } }
  134. r = updateIdentity(me.id, id, fields)
  135. if (r.error != null) { return r }
  136. return { identity = r.identity identities = identityRows(me.id) }
  137. }

Branches

Latest commits

  • 7215903eident#34: access: the unstyled classes all, app, tick, apptick, plus are dropped; the gate finds the app ticks by input[name=app]mre
  • 69b0a0ceident#34: access: the pick buttons use Style.pickCard instead of class pickmre
  • dc702419Merge branch 'f9-choose' into mainIdent
  • 8caec771|||PR ident#34 restore .choose hookmre
  • 0dbff960Merge branch 'f8-shared' into mainIdent
  • 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