gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit876d22b2876d22b2reports/H1-hydrate.mdmre876d22b2/components/main.hl

5.7 KB

  1. // components/main.hl — THE SHELL (mission 006, phone first on the WorldAPI theme): the theme's AppHeader (brand · main menu ·
  2. // user icon), the phone's Sidebar (☰ → the main menu) and the slot every page renders into; the pages render
  3. // in the theme's ContentFirst shell (a month is one big content area, no list beside it; ContentFirst without a desktop sidebar
  4. // gives it the whole 72rem column). The theme's shell files theme/shell/*.hl are never
  5. // edited here. Signed in the user icon opens the UserMenu (Log out); signed out the ident icon opens ident's selector + "Log in
  6. // with ident" (from 60rem they stand in the header). App CSS is in components/styles.hl.
  7. // THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in gitoria. Choosing an identity
  8. // fires `ident-login` (one-time code); /login.js hands it to the hidden input #identcode, whose `change` goes to the
  9. // face calendarLogin (server-side exchange, lib/users.hl userOfLoginCode; no reload). The element's class is `in` / `out`; /login.js mirrors it into
  10. // the selector's `loggedIn`.
  11. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl loginCallback).
  12. // After a login or logout in this tab the page is fetched again (navigate('/')): the calendar of the session show.
  13. import { navigate } from 'hl:web'
  14. import { siteName } from '../project.hl'
  15. import { identKey, selectorScript, loginHref, userIdOfSession, userOfLoginCode } from '../lib/users.hl'
  16. import { randomBytes } from 'hl:crypto'
  17. import AppHeader from '../theme/shell/app-header.hl'
  18. import MainMenu from '../theme/shell/main-menu.hl'
  19. import UserMenu from '../theme/shell/user-menu.hl'
  20. import Sidebar from '../theme/shell/app-sidebar.hl'
  21. import ContentFirst from '../theme/shell/content-first.hl'
  22. slot = null
  23. session = null
  24. loggedIn = userIdOfSession(session) != null
  25. loggedOut = userIdOfSession(session) == null
  26. buttonHref = loginHref
  27. selectorClass = loggedIn ? 'in' : 'out'
  28. selectorKey = identKey
  29. identScript = selectorScript
  30. loginError = ''
  31. hasLoginError = false
  32. // the main menu: the header from 60rem, the phone's sidebar below — one list (one page so far; the menu is the shell's place for more)
  33. menu = [ { label = 'Calendar' href = '/' } ]
  34. View {
  35. body {
  36. AppHeader { brand = siteName
  37. MainMenu { items = menu }
  38. if (loggedIn) {
  39. UserMenu {
  40. p { id = "whoami" class = "who" "Signed in with ident" }
  41. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  42. }
  43. }
  44. // signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it
  45. // is hidden (class `in`), the selector element stays: /login.js mirrors its state
  46. identMenu { class = selectorClass
  47. button { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"
  48. // the ident icon: a small i standing beside a big D lying on the floor; the D's lower face is its thickness
  49. svg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"
  50. path { class = "ident-d-side" d = "M5 22.6 L7.8 14.2 C15.1 14.2 19 16.6 19.6 18.4 C20.2 20.2 16.2 22.6 5 22.6 Z" }
  51. path { class = "ident-d" "fill-rule" = "evenodd" d = "M5 21 L7.8 12.6 C15.1 12.6 19 15 19.6 16.8 C20.2 18.6 16.2 21 5 21 Z M10.7 14.4 C13.6 14.4 15.4 15.3 15.6 16.8 C15.8 18.3 13.7 19.2 10 19.2 Z" }
  52. rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }
  53. circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }
  54. }
  55. }
  56. identPanel { id = "ident-panel" popover = "auto"
  57. identSelector { id = "selector" key = selectorKey class = selectorClass }
  58. if (loggedOut) {
  59. a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }
  60. }
  61. }
  62. }
  63. }
  64. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  65. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  66. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem); then the page in the
  67. // content-first shell — hybriel#130: the page slot starts its own line
  68. Sidebar { desktop = "false" MainMenu { items = menu } }
  69. main {
  70. ContentFirst { slot }
  71. }
  72. script { src = identScript }
  73. script { src = "/login.js" }
  74. }
  75. }
  76. showIn = () => {
  77. loggedIn = true
  78. loggedOut = false
  79. selectorClass = 'in'
  80. loginError = ''
  81. hasLoginError = false
  82. }
  83. showOut = () => {
  84. loggedIn = false
  85. loggedOut = true
  86. selectorClass = 'out'
  87. }
  88. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  89. on gotCode(e) {
  90. code = e.target.value
  91. e.target.value = ''
  92. if (code == null || code == '') { return null }
  93. r = emit server calendarLogin(code)
  94. if (r == null || r.error != null) {
  95. loginError = r != null ? r.error : 'the login failed'
  96. hasLoginError = true
  97. return null
  98. }
  99. showIn()
  100. navigate('/')
  101. }
  102. on client calendarSignedIn(tag) {
  103. showIn()
  104. navigate('/')
  105. }
  106. on client calendarSignedOut(tag) {
  107. showOut()
  108. navigate('/')
  109. }
  110. on doLogout(e) {
  111. emit server calendarLogOut()
  112. showOut()
  113. navigate('/')
  114. }
  115. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  116. on server calendarLogin(code, session) {
  117. if (session == null) { return { error = 'no session — reload the page' } }
  118. x = userOfLoginCode(code)
  119. if (x.error != null) { return { error = x.error } }
  120. tag = randomBytes(16)
  121. session.user = { id = x.user.id }
  122. session.data.tag = tag
  123. emit client calendarSignedIn(tag)
  124. return { ok = true }
  125. }
  126. on server calendarLogOut(session) {
  127. if (session == null) { return { error = 'no session' } }
  128. emit client calendarSignedOut(session.data.tag)
  129. session.user = null
  130. return { ok = true }
  131. }

Branches

Latest commits

  • 876d22b2reports/H1-hydrate.mdmre
  • ef0cae45tests/dst.mjs: wait for hydration instead of a fixed 2.5 s sleep before clicking #gomre
  • d9cadecatests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
  • efa61227re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • 7808adbecalendar#12: report 011, LOG, STATUS, push-shots-testmre
  • df2e4fa0calendar#12: test push rate limit (1 per 30 s per device), owner-only gate checksmre
  • acb957cfcalendar#12: Send a test notification on a subscribed device (one push in ~10 s, owner's own device), push gate part 4mre
  • 0b222eb8tests: e2e-theme CDP port default from E2E_THEME_CDP_PORT (8756 unchanged)mre
  • 8b8a5abare-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • a69b27f9docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 1a97edfdcalendar mission 010: reminder rows at 390 px (the 7-column month grid no longer catches the reminder lists), gate checks, settings-shots, reportmre
  • 61b21404calendar mission 009: reminder times on hl:time in the browser (lib/push-plan.hl and the Intl code removed), DST gate tests/dst.mjs, E2E script, reportmre
  • 875353c1calendar mission 009: re-vendor Hybriel master 022a3ac1 (int 6 6b396322 hl:time browser side, int 7 65e8ec21; bin sha256 6e0f77d7, plugins whole)mre
  • ce16a4efdeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • f490bc8cdeploy: Web Push gate tests/push.mjs (PUSH_GATE_PORT)mre
  • 3af29fc8calendar mission 008 (A8): report, README, LOG, push-shots.mjsmre
  • f91f3663calendar mission 008 (A8): push only asked of the browser when the app has the VAPID settings (pushAvailable); real-FCM E2E scripts (push-real-app.mjs, push-real.mjs)mre
  • bf571badcalendar mission 008 (A8): Turn off on this device (unsubscribes the browser, server drops the device, choice kept), subscribe/refresh when the app is shown again; push gate part 3mre
  • 50985708calendar mission 008 (A7): Web Push report, README, mission, LOGmre
  • ee318774calendar mission 008 (A7): push-real.mjs, push sent log linemre