gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9ba01de39ba01de3notes: write the standby service out in full so the boot gate can read the main servicemre9ba01de3/components/main.hl

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

Branches

Latest commits

  • 9ba01de3notes: write the standby service out in full so the boot gate can read the main servicemre
  • 98cab40anotes: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 1fadb473notes gate: the editor table now has 1 px cell lines from the notes thememre
  • 8762115cnotes: take the components e54f83a (paste as Markdown, text typed before the editor is built is kept, Table button); table lines come from the notes thememre
  • ac23e194ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 2804f0d3Merge branch 'iw-ident-widget'mre
  • 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
  • 7a889b82notes: MdEditor with the Table button, typed pipe rows and the theme's table look (components mt-tables); a table note is named by its header words; gate checks that fail on mainmre
  • 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