gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf5-styles9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mref5-styles/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. editHeading = ''
  11. welcome = false
  12. notWelcome = !welcome // `if (!welcome)` in a View renders nothing: an `if` takes a member
  13. editId = ''
  14. welcomeId = ''
  15. fIdentityName = ''
  16. fNickname = ''
  17. fFirstname = ''
  18. fLastname = ''
  19. fAvatar = ''
  20. hasAvatarPreview = false
  21. // the preview and the Remove button are hidden (the attribute) while there is no picture
  22. noAvatarPreview = !hasAvatarPreview
  23. Style {
  24. avatarField {
  25. display = 'flex'
  26. flexWrap = 'wrap'
  27. alignItems = 'center'
  28. gap = '.6rem'
  29. // 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
  30. label {
  31. flex = '1 1 12rem'
  32. minWidth = '0'
  33. }
  34. }
  35. '#avatarpreview' {
  36. width = '48px'
  37. height = '48px'
  38. objectFit = 'cover'
  39. borderRadius = '50%'
  40. background = 'var(--color-background-sunken)'
  41. }
  42. '#identityform input[type=file]' {
  43. width = '100%'
  44. maxWidth = '100%'
  45. minWidth = '0'
  46. }
  47. '#avatarnote' {
  48. flexBasis = '100%'
  49. color = 'var(--color-danger)'
  50. fontSize = '.875rem'
  51. empty { display = 'none' }
  52. }
  53. }
  54. View {
  55. form { id = "identityform"
  56. on submit(e) {
  57. e.preventDefault()
  58. emit saveForm(e)
  59. }
  60. h1 { id = "formheading" editHeading }
  61. if (welcome) {
  62. 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." }
  63. }
  64. label { "Identity name " fieldHint { "(shown when you pick an identity in an app; optional)" }
  65. input { id = "fidentityname" name = "identityName" maxlength = "60" autocomplete = "off" value = fIdentityName on input(e) { emit setF('identityName', e.target.value) } }
  66. }
  67. label { "Nickname " fieldHint { "(optional)" }
  68. input { id = "fnickname" name = "nickname" maxlength = "60" autocomplete = "nickname" value = fNickname on input(e) { emit setF('nickname', e.target.value) } }
  69. }
  70. label { "First name " fieldHint { "(optional)" }
  71. input { id = "ffirstname" name = "firstname" maxlength = "60" autocomplete = "given-name" value = fFirstname on input(e) { emit setF('firstname', e.target.value) } }
  72. }
  73. label { "Last name " fieldHint { "(optional)" }
  74. input { id = "flastname" name = "lastname" maxlength = "60" autocomplete = "family-name" value = fLastname on input(e) { emit setF('lastname', e.target.value) } }
  75. }
  76. avatarField {
  77. img { id = "avatarpreview" hidden = noAvatarPreview src = fAvatar alt = "" width = "48" height = "48" }
  78. label { "Avatar " fieldHint { "(optional; a picture apps can show, e.g. next to your comments)" }
  79. input { id = "favatarfile" type = "file" accept = "image/png,image/jpeg,image/webp,image/gif" }
  80. }
  81. input { id = "favatar" name = "avatar" type = "hidden" value = fAvatar on input(e) { emit setF('avatar', e.target.value) } }
  82. button { id = "avatarremove" type = "button" class = "quiet small" hidden = noAvatarPreview "Remove picture" on click(e) { emit setF('avatar', '') } }
  83. span { id = "avatarnote" }
  84. }
  85. formButtons {
  86. button { id = "saveidentity" type = "submit" "Save" }
  87. if (welcome) { button { id = "skip" type = "button" class = "quiet" "Skip" on click(e) { $parent.closeForm() } } }
  88. if (notWelcome) { button { id = "cancel" type = "button" class = "quiet" "Cancel" on click(e) { $parent.closeForm() } } }
  89. }
  90. }
  91. }
  92. on setF(name, v) {
  93. if (name == 'identityName') { fIdentityName = v }
  94. if (name == 'nickname') { fNickname = v }
  95. if (name == 'firstname') { fFirstname = v }
  96. if (name == 'lastname') { fLastname = v }
  97. if (name == 'avatar') { fAvatar = v hasAvatarPreview = v.trim() != '' }
  98. $parent.setF(name, v)
  99. }
  100. on saveForm(e) {
  101. $parent.status('', '')
  102. fields = { identityName = fIdentityName nickname = fNickname firstname = fFirstname lastname = fLastname avatar = fAvatar }
  103. let r = null
  104. if (editId == '' && welcome) {
  105. r = emit server editIdentity('' + welcomeId, fields)
  106. } else if (editId == '') {
  107. r = emit server addIdentity(fields)
  108. } else {
  109. r = emit server editIdentity('' + editId, fields)
  110. }
  111. if (r == null) {
  112. $parent.status('the server did not answer — try again', '')
  113. return null
  114. }
  115. if (r.error != null) {
  116. $parent.status(r.error, '')
  117. return null
  118. }
  119. $parent.formSaved(r.identities, editId == '' && !welcome ? 'Identity created.' : 'Identity saved.')
  120. }
  121. // A face runs on a BLANK instance (its arguments and its imports only); the account comes from the session.
  122. on server addIdentity(fields, session) {
  123. let me = accountOfSession(&session)
  124. if (me == null) { return { error = 'you are not signed in' } }
  125. r = createIdentity(me.id, fields)
  126. if (r.error != null) { return r }
  127. return { identity = r.identity identities = identityRows(me.id) }
  128. }
  129. on server editIdentity(id, fields, session) {
  130. let me = accountOfSession(&session)
  131. if (me == null) { return { error = 'you are not signed in' } }
  132. r = updateIdentity(me.id, id, fields)
  133. if (r.error != null) { return r }
  134. return { identity = r.identity identities = identityRows(me.id) }
  135. }

Branches

Latest commits

  • 9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mre
  • f28333e4ident#33 ident#35: styles.hl keeps only the accent, the page column and the shared patterns; the account bar is written phone first (base rule + one min-width: 60rem block) instead of a max-width overridemre
  • 5b4541fcident#33: the selector sign-in frame's rules move into embed.hl's Stylemre
  • 00235f21ident#33: the per-app notification switches move into appsettings.hl's Stylemre
  • 2249945cident#33: the inbox and connection list rules move into inbox.hl's Stylemre
  • f2d9f79fident#33: the apps list and the secret box move into apps.hl's Stylemre
  • 8370b748ident#33: the app request box moves into home.hl's Stylemre
  • 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