gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit07d1717c07d1717c|||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)mre07d1717c/components/identityform.hl

5.3 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. avatarPreviewClass = hasAvatarPreview ? 'avatar' : 'avatar hidden'
  22. avatarRemoveClass = hasAvatarPreview ? 'quiet small' : 'quiet small hidden'
  23. View {
  24. form { id = "identityform"
  25. on submit(e) {
  26. e.preventDefault()
  27. emit saveForm(e)
  28. }
  29. h1 { id = "formheading" editHeading }
  30. if (welcome) {
  31. 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." }
  32. }
  33. label { "Identity name " fieldHint { "(shown when you pick an identity in an app; optional)" }
  34. input { id = "fidentityname" name = "identityName" maxlength = "60" autocomplete = "off" value = fIdentityName on input(e) { emit setF('identityName', e.target.value) } }
  35. }
  36. label { "Nickname " fieldHint { "(optional)" }
  37. input { id = "fnickname" name = "nickname" maxlength = "60" autocomplete = "nickname" value = fNickname on input(e) { emit setF('nickname', e.target.value) } }
  38. }
  39. label { "First name " fieldHint { "(optional)" }
  40. input { id = "ffirstname" name = "firstname" maxlength = "60" autocomplete = "given-name" value = fFirstname on input(e) { emit setF('firstname', e.target.value) } }
  41. }
  42. label { "Last name " fieldHint { "(optional)" }
  43. input { id = "flastname" name = "lastname" maxlength = "60" autocomplete = "family-name" value = fLastname on input(e) { emit setF('lastname', e.target.value) } }
  44. }
  45. avatarField {
  46. img { id = "avatarpreview" class = avatarPreviewClass src = fAvatar alt = "" width = "48" height = "48" }
  47. label { "Avatar " fieldHint { "(optional; a picture apps can show, e.g. next to your comments)" }
  48. input { id = "favatarfile" type = "file" accept = "image/png,image/jpeg,image/webp,image/gif" }
  49. }
  50. input { id = "favatar" name = "avatar" type = "hidden" value = fAvatar on input(e) { emit setF('avatar', e.target.value) } }
  51. button { id = "avatarremove" type = "button" class = avatarRemoveClass "Remove picture" on click(e) { emit setF('avatar', '') } }
  52. span { id = "avatarnote" class = "avatar-note" }
  53. }
  54. formButtons {
  55. button { id = "saveidentity" type = "submit" "Save" }
  56. if (welcome) { button { id = "skip" type = "button" class = "quiet" "Skip" on click(e) { $parent.closeForm() } } }
  57. if (notWelcome) { button { id = "cancel" type = "button" class = "quiet" "Cancel" on click(e) { $parent.closeForm() } } }
  58. }
  59. }
  60. }
  61. on setF(name, v) {
  62. if (name == 'identityName') { fIdentityName = v }
  63. if (name == 'nickname') { fNickname = v }
  64. if (name == 'firstname') { fFirstname = v }
  65. if (name == 'lastname') { fLastname = v }
  66. if (name == 'avatar') { fAvatar = v hasAvatarPreview = v.trim() != '' }
  67. $parent.setF(name, v)
  68. }
  69. on saveForm(e) {
  70. $parent.status('', '')
  71. fields = { identityName = fIdentityName nickname = fNickname firstname = fFirstname lastname = fLastname avatar = fAvatar }
  72. let r = null
  73. if (editId == '' && welcome) {
  74. r = emit server editIdentity('' + welcomeId, fields)
  75. } else if (editId == '') {
  76. r = emit server addIdentity(fields)
  77. } else {
  78. r = emit server editIdentity('' + editId, fields)
  79. }
  80. if (r == null) {
  81. $parent.status('the server did not answer — try again', '')
  82. return null
  83. }
  84. if (r.error != null) {
  85. $parent.status(r.error, '')
  86. return null
  87. }
  88. $parent.formSaved(r.identities, editId == '' && !welcome ? 'Identity created.' : 'Identity saved.')
  89. }
  90. // A face runs on a BLANK instance (its arguments and its imports only); the account comes from the session.
  91. on server addIdentity(fields, session) {
  92. let me = accountOfSession(&session)
  93. if (me == null) { return { error = 'you are not signed in' } }
  94. r = createIdentity(me.id, fields)
  95. if (r.error != null) { return r }
  96. return { identity = r.identity identities = identityRows(me.id) }
  97. }
  98. on server editIdentity(id, fields, session) {
  99. let me = accountOfSession(&session)
  100. if (me == null) { return { error = 'you are not signed in' } }
  101. r = updateIdentity(me.id, id, fields)
  102. if (r.error != null) { return r }
  103. return { identity = r.identity identities = identityRows(me.id) }
  104. }

Branches

Latest commits

  • 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
  • 3ac85995ident#43 ident#44: plain declarations for never-reassigned lets, one envString helper, named route functions and audience rule out of project.hlmre
  • c7eef14aMerge branch 'nv1-navigate' into mainIdent
  • 644f9775|||PR ident#36 navigate() instead of window.location in the shell, start shell and homemre
  • 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
  • 23971fb7ident#49: media queries in the language's @media formmre
  • 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
  • aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
  • ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre