gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain0f6d1592Merge branch 'f18b-shell-session' into mainIdentmain/components/timezone.hl

2.5 KB

  1. // components/timezone.hl — THE TIME ZONE of the signed-in account (ident#40.3), placed by components/home.hl on `/`. The host passes in
  2. // the account's current zone (timeZone); this component owns the input, the browser's zone and the save (face changeTimeZone, which
  3. // asks lib/accounts.hl setTimeZone). The host shows the messages: $parent.status(message, notice) and, after a save, $parent.zoneSaved(zone).
  4. import { accountOfSession, setTimeZone } from '../lib/accounts.hl'
  5. import { leadLook } from './styles.hl'
  6. timeZone = ''
  7. tzInput = timeZone
  8. Style {
  9. pLead = leadLook
  10. '#timezonesection' {
  11. marginTop = '.6rem'
  12. }
  13. }
  14. View {
  15. section { id = "timezonesection"
  16. h2 { "Time zone" }
  17. p { Style.pLead "Taken from your browser at your first login. Currently " strong { id = "timezone" timeZone } "." }
  18. p { id = "digestnote" Style.pLead "Your daily mail of notifications comes at 17:00 in this time zone." }
  19. form { id = "tzform"
  20. on submit(e) {
  21. e.preventDefault()
  22. emit saveZone(e)
  23. }
  24. label { "Time zone (IANA name, e.g. Europe/Vienna)"
  25. input { id = "tzinput" name = "timeZone" autocomplete = "off" maxlength = "64" required = "required" value = tzInput on input(e) { emit setTz(e.target.value) } }
  26. }
  27. formButtons {
  28. button { id = "savetz" type = "submit" "Save time zone" }
  29. button { id = "browsertz" type = "button" class = "quiet" "Use this browser's" on click(e) { emit useBrowserZone(e) } }
  30. }
  31. }
  32. }
  33. }
  34. on setTz(v) { tzInput = v }
  35. // the browser's own time zone (IANA name) and whether a name is one it knows (`Intl` is a
  36. // browser global of client code, hybriel#18)
  37. browserZone = () => { return Intl.DateTimeFormat().resolvedOptions().timeZone }
  38. knownZone = (v) => { return v == 'UTC' || Intl.supportedValuesOf('timeZone').includes(v) }
  39. on useBrowserZone(e) { tzInput = browserZone() }
  40. on saveZone(e) {
  41. $parent.status('', '')
  42. v = tzInput.trim()
  43. if (!knownZone(v)) {
  44. $parent.status('this browser does not know the time zone “' + v + '”', '')
  45. return null
  46. }
  47. r = emit server changeTimeZone(v)
  48. if (r == null) {
  49. $parent.status('the server did not answer — try again', '')
  50. return null
  51. }
  52. if (r.error != null) {
  53. $parent.status(r.error, '')
  54. return null
  55. }
  56. tzInput = r.timeZone
  57. $parent.zoneSaved(r.timeZone)
  58. }
  59. // A face runs on a BLANK instance (its arguments and its imports only); the account comes from the session.
  60. on server changeTimeZone(tz, session) {
  61. let me = accountOfSession(&session)
  62. if (me == null) { return { error = 'you are not signed in' } }
  63. r = setTimeZone(me.id, tz)
  64. if (r.error != null) { return r }
  65. return { timeZone = r.account.timeZone }
  66. }

Branches

Latest commits

  • 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
  • 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
  • 5d1b3fedMerge branch 'v61-day61' into mainIdent
  • 83faeb15|||PR ident: vendor Hybriel day61mre
  • b2572b34Merge branch 'v59-day59' into mainIdent
  • 67cf016d|||PR ident: vendor Hybriel day59mre
  • 600c043dMerge branch 'v58-day58' into mainIdent
  • 365f8c80|||PR ident: vendor Hybriel day58mre
  • 585126e5Merge branch 'f16-setf' into mainIdent
  • 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
  • a1419d9cMerge branch 'f15-navigate' into mainIdent
  • 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
  • e36f4516Merge branch 'f14-online' into mainIdent
  • 2c5eac91|||PR ident#38 online state without probe timermre
  • bf1980f2Merge branch 'v56-day56' into mainIdent
  • 62ae0adf|||PR ident: vendor Hybriel day56mre
  • 0d18abc4Merge branch 'f13-avatar' into mainIdent
  • 2a99730a|||PR ident#37 avatar in hlmre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre