gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit52d8d24252d8d242notes: e2e script checks Log out and the selector in the header instead of the user menumre52d8d242/components/main.hl

5.1 KB

  1. // components/main.hl — THE SHELL (mission 011, 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 page chooses its shell (the
  3. // notes page ListFirst, /login/failed and the signed-out hint ContentFirst). The theme's shell files theme/shell/*.hl are never
  4. // edited here. App CSS is in components/styles.hl.
  5. // IDENT'S SELECTOR STANDS IN THE HEADER, visible signed in and signed out, on the phone and on the desktop (creator 2026-10-24: the
  6. // theme move hid it behind an icon and replaced it by the user menu — never again; the gate checks it at 390 and 1280). Signed in the
  7. // user icon beside it opens the UserMenu (Log out). Nothing else stands beside the selector: no second "Log in" button (creator 2026-10-24).
  8. // THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in gitoria. Choosing an identity
  9. // fires `ident-login` (one-time code); /login.js hands it to the hidden input #identcode, whose `change` goes to the
  10. // face notesLogin (server-side exchange, lib/users.hl userOfLoginCode; no reload). The element's class is `in` / `out`; /login.js mirrors it into
  11. // the selector's `loggedIn`.
  12. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl loginCallback).
  13. // After a login or logout in this tab the page is fetched again (navigate('/')): the notes of the session show.
  14. import { navigate } from 'hl:web'
  15. import { siteName } from '../project.hl'
  16. import { identKey, selectorScript, userIdOfSession, userOfLoginCode } from '../lib/users.hl'
  17. import { randomBytes } from 'hl:crypto'
  18. import AppHeader from '../theme/shell/app-header.hl'
  19. import MainMenu from '../theme/shell/main-menu.hl'
  20. import Sidebar from '../theme/shell/app-sidebar.hl'
  21. slot = null
  22. session = null
  23. loggedIn = userIdOfSession(session) != null
  24. loggedOut = userIdOfSession(session) == null
  25. selectorClass = loggedIn ? 'in' : 'out'
  26. selectorKey = identKey
  27. identScript = selectorScript
  28. loginError = ''
  29. hasLoginError = false
  30. // 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)
  31. // `current = true` STAYS (mission 015, hybriel#197): the menu now marks an item from the route, but only the page '/' itself (an item
  32. // with href '/' is not "above" other pages, by design) — on /note/:id and /login/failed the route marks nothing (server HTML checked in
  33. // tests/browser.mjs "server html …"; without current = true those two fail), and the one item is the whole app
  34. menu = [ { label = 'Notes' href = '/' current = true } ]
  35. View {
  36. body {
  37. AppHeader { brand = siteName
  38. MainMenu { items = menu }
  39. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (signed in it shows the
  40. // chosen identity). /login.js mirrors its state from the class (`in` / `out`). Nothing else stands beside it: no second "Log in" button (creator 2026-10-24).
  41. identSelector { id = "selector" key = selectorKey class = selectorClass }
  42. // signed in, like before the theme missions: Log out stands beside the selector
  43. if (loggedIn) {
  44. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  45. }
  46. }
  47. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  48. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  49. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem); the page (its own
  50. // shell: list-first for the notes, content-first for the rest) follows — hybriel#130: the page slot starts its own line
  51. Sidebar { desktop = "false" MainMenu { items = menu } }
  52. slot
  53. script { src = identScript }
  54. script { src = "/login.js" }
  55. }
  56. }
  57. showIn = () => {
  58. loggedIn = true
  59. loggedOut = false
  60. selectorClass = 'in'
  61. loginError = ''
  62. hasLoginError = false
  63. }
  64. showOut = () => {
  65. loggedIn = false
  66. loggedOut = true
  67. selectorClass = 'out'
  68. }
  69. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  70. on gotCode(e) {
  71. code = e.target.value
  72. e.target.value = ''
  73. if (code == null || code == '') { return null }
  74. r = emit server notesLogin(code)
  75. if (r == null || r.error != null) {
  76. loginError = r != null ? r.error : 'the login failed'
  77. hasLoginError = true
  78. return null
  79. }
  80. showIn()
  81. navigate('/')
  82. }
  83. on client notesSignedIn(tag) {
  84. showIn()
  85. navigate('/')
  86. }
  87. on client notesSignedOut(tag) {
  88. showOut()
  89. navigate('/')
  90. }
  91. on doLogout(e) {
  92. emit server notesLogOut()
  93. showOut()
  94. navigate('/')
  95. }
  96. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  97. on server notesLogin(code, session) {
  98. if (session == null) { return { error = 'no session — reload the page' } }
  99. x = userOfLoginCode(code)
  100. if (x.error != null) { return { error = x.error } }
  101. tag = randomBytes(16)
  102. session.user = { id = x.user.id }
  103. session.data.tag = tag
  104. emit client notesSignedIn(tag)
  105. return { ok = true }
  106. }
  107. on server notesLogOut(session) {
  108. if (session == null) { return { error = 'no session' } }
  109. emit client notesSignedOut(session.data.tag)
  110. session.user = null
  111. session.data.tag = null
  112. return { ok = true }
  113. }

Branches

Latest commits

  • 52d8d242notes: e2e script checks Log out and the selector in the header instead of the user menumre
  • e5abf7b7notes header: the selector alone top right plus Log out as before the theme missions; the user icon is gonemre
  • a2e343aeident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • b96c7f70theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 6140e6a0sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • cb7e6469deploy: security gate (tests/security.mjs)mre
  • 774bf34bnotes security: CSRF guard on /api/notes, new session at login, Secure cookie, uploadMax 0, login rate limit, nosniff, face payload check; tests/security.mjs; SN reportmre
  • ef18a68fsync components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
  • c37488b1MN report: alignment updatemre
  • 4fb35a0enotes mobile: Delete note and the delete row exactly on the editor's edges; gate asserts 1 pxmre
  • 91736270MN report and logmre
  • 15667425notes: delete confirmation buttons at most 12rem wide on the desktopmre
  • 8f7a6a95gate: MN phone checks (list header gutter, back gap, delete question)mre
  • 90c73ed3notes mobile: back link gapmre
  • 72bd4f83notes mobile: list header on the gutter, delete confirmation as a question + two equal buttons, Delete note under the editor edgemre
  • ba1e73f8notes: a sent edit is done once the server's version is not older, so a second writer's text shows in the first tab; gate: two writers both waysmre
  • c69ef9ebsync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
  • 2eb783f5sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
  • 4dd46dadsync-components: copy icons/icons.hl + README (F4); testsmre
  • c92e4a0ftests/e2e-outside.mjs: real-Chrome E2E, a note pushed from another device while open, then typingmre