gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita2e343aea2e343aeident 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)mrea2e343ae/components/main.hl

5.2 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 UserMenu from '../theme/shell/user-menu.hl'
  21. import Sidebar from '../theme/shell/app-sidebar.hl'
  22. slot = null
  23. session = null
  24. loggedIn = userIdOfSession(session) != null
  25. loggedOut = userIdOfSession(session) == null
  26. selectorClass = loggedIn ? 'in' : 'out'
  27. selectorKey = identKey
  28. identScript = selectorScript
  29. loginError = ''
  30. hasLoginError = false
  31. // 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)
  32. // `current = true` STAYS (mission 015, hybriel#197): the menu now marks an item from the route, but only the page '/' itself (an item
  33. // with href '/' is not "above" other pages, by design) — on /note/:id and /login/failed the route marks nothing (server HTML checked in
  34. // tests/browser.mjs "server html …"; without current = true those two fail), and the one item is the whole app
  35. menu = [ { label = 'Notes' href = '/' current = true } ]
  36. View {
  37. body {
  38. AppHeader { brand = siteName
  39. MainMenu { items = menu }
  40. // 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
  41. // 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).
  42. identSelector { id = "selector" key = selectorKey class = selectorClass }
  43. if (loggedIn) {
  44. UserMenu {
  45. p { id = "whoami" class = "who" "Signed in with ident" }
  46. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  47. }
  48. }
  49. }
  50. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  51. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  52. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem); the page (its own
  53. // shell: list-first for the notes, content-first for the rest) follows — hybriel#130: the page slot starts its own line
  54. Sidebar { desktop = "false" MainMenu { items = menu } }
  55. slot
  56. script { src = identScript }
  57. script { src = "/login.js" }
  58. }
  59. }
  60. showIn = () => {
  61. loggedIn = true
  62. loggedOut = false
  63. selectorClass = 'in'
  64. loginError = ''
  65. hasLoginError = false
  66. }
  67. showOut = () => {
  68. loggedIn = false
  69. loggedOut = true
  70. selectorClass = 'out'
  71. }
  72. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  73. on gotCode(e) {
  74. code = e.target.value
  75. e.target.value = ''
  76. if (code == null || code == '') { return null }
  77. r = emit server notesLogin(code)
  78. if (r == null || r.error != null) {
  79. loginError = r != null ? r.error : 'the login failed'
  80. hasLoginError = true
  81. return null
  82. }
  83. showIn()
  84. navigate('/')
  85. }
  86. on client notesSignedIn(tag) {
  87. showIn()
  88. navigate('/')
  89. }
  90. on client notesSignedOut(tag) {
  91. showOut()
  92. navigate('/')
  93. }
  94. on doLogout(e) {
  95. emit server notesLogOut()
  96. showOut()
  97. navigate('/')
  98. }
  99. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  100. on server notesLogin(code, session) {
  101. if (session == null) { return { error = 'no session — reload the page' } }
  102. x = userOfLoginCode(code)
  103. if (x.error != null) { return { error = x.error } }
  104. tag = randomBytes(16)
  105. session.user = { id = x.user.id }
  106. session.data.tag = tag
  107. emit client notesSignedIn(tag)
  108. return { ok = true }
  109. }
  110. on server notesLogOut(session) {
  111. if (session == null) { return { error = 'no session' } }
  112. emit client notesSignedOut(session.data.tag)
  113. session.user = null
  114. session.data.tag = null
  115. return { ok = true }
  116. }

Branches

Latest commits

  • 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
  • 0516b4ccmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
  • 38cc11ecmd-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre