gitoria

notes

All repositories: gitoria

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

5.9 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. Signed in the user icon opens the UserMenu (Log out); signed out the ident icon opens ident's selector + "Log in
  5. // with ident" (from 60rem they stand in the header). App CSS is in components/styles.hl.
  6. // THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in gitoria. Choosing an identity
  7. // fires `ident-login` (one-time code); /login.js hands it to the hidden input #identcode, whose `change` goes to the
  8. // face notesLogin (server-side exchange, lib/users.hl userOfLoginCode; no reload). The element's class is `in` / `out`; /login.js mirrors it into
  9. // the selector's `loggedIn`.
  10. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl loginCallback).
  11. // After a login or logout in this tab the page is fetched again (navigate('/')): the notes of the session show.
  12. import { navigate } from 'hl:web'
  13. import { siteName } from '../project.hl'
  14. import { identKey, selectorScript, loginHref, userIdOfSession, userOfLoginCode } from '../lib/users.hl'
  15. import { randomBytes } from 'hl:crypto'
  16. import AppHeader from '../theme/shell/app-header.hl'
  17. import MainMenu from '../theme/shell/main-menu.hl'
  18. import UserMenu from '../theme/shell/user-menu.hl'
  19. import Sidebar from '../theme/shell/app-sidebar.hl'
  20. slot = null
  21. session = null
  22. loggedIn = userIdOfSession(session) != null
  23. loggedOut = userIdOfSession(session) == null
  24. buttonHref = loginHref
  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. if (loggedIn) {
  40. UserMenu {
  41. p { id = "whoami" class = "who" "Signed in with ident" }
  42. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  43. }
  44. }
  45. // signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it
  46. // is hidden (class `in`), the selector element stays: /login.js mirrors its state
  47. identMenu { class = selectorClass
  48. button { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"
  49. // the ident icon: a small i standing beside a big D lying on the floor; the D's lower face is its thickness
  50. svg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"
  51. 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" }
  52. 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" }
  53. rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }
  54. circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }
  55. }
  56. }
  57. identPanel { id = "ident-panel" popover = "auto"
  58. identSelector { id = "selector" key = selectorKey class = selectorClass }
  59. if (loggedOut) {
  60. a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }
  61. }
  62. }
  63. }
  64. }
  65. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  66. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  67. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem); the page (its own
  68. // shell: list-first for the notes, content-first for the rest) follows — hybriel#130: the page slot starts its own line
  69. Sidebar { desktop = "false" MainMenu { items = menu } }
  70. slot
  71. script { src = identScript }
  72. script { src = "/login.js" }
  73. }
  74. }
  75. showIn = () => {
  76. loggedIn = true
  77. loggedOut = false
  78. selectorClass = 'in'
  79. loginError = ''
  80. hasLoginError = false
  81. }
  82. showOut = () => {
  83. loggedIn = false
  84. loggedOut = true
  85. selectorClass = 'out'
  86. }
  87. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  88. on gotCode(e) {
  89. code = e.target.value
  90. e.target.value = ''
  91. if (code == null || code == '') { return null }
  92. r = emit server notesLogin(code)
  93. if (r == null || r.error != null) {
  94. loginError = r != null ? r.error : 'the login failed'
  95. hasLoginError = true
  96. return null
  97. }
  98. showIn()
  99. navigate('/')
  100. }
  101. on client notesSignedIn(tag) {
  102. showIn()
  103. navigate('/')
  104. }
  105. on client notesSignedOut(tag) {
  106. showOut()
  107. navigate('/')
  108. }
  109. on doLogout(e) {
  110. emit server notesLogOut()
  111. showOut()
  112. navigate('/')
  113. }
  114. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  115. on server notesLogin(code, session) {
  116. if (session == null) { return { error = 'no session — reload the page' } }
  117. x = userOfLoginCode(code)
  118. if (x.error != null) { return { error = x.error } }
  119. tag = randomBytes(16)
  120. session.user = { id = x.user.id }
  121. session.data.tag = tag
  122. emit client notesSignedIn(tag)
  123. return { ok = true }
  124. }
  125. on server notesLogOut(session) {
  126. if (session == null) { return { error = 'no session' } }
  127. emit client notesSignedOut(session.data.tag)
  128. session.user = null
  129. return { ok = true }
  130. }

Branches

Latest commits

  • ef9f9feere-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
  • 5485467cdocker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 86ea4a85deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • edeab20fnotes mission 015: mission, report, LOG, STATUSmre
  • 542a0383notes mission 015: e2e-chrome E2E_HOST (own cookie jar in the shared Chrome)mre
  • 8b30f510notes mission 015: main-menu from layouts 0bcc629, current = true kept (route marks only /), server-HTML marker checksmre
  • 84b574c4notes mission 015: re-vendor plugins from hybriel f9614007 (incl. web, #117)mre
  • 447da53dnotes mission 014: report — remaining gates and lisbeth E2E proofmre
  • fd9f92c3notes mission 014: report (partial), LOG, STATUSmre
  • b2501360notes mission 014: open() sets asking=false before flush(0) (hybriel#196)mre
  • 9414ce59notes mission 014: merge theme 76f99f6, components 3794c59, strict single-press openAsk (fails on old open())mre
  • c08c655anotes 013: theme re-copied from layouts 76f99f6 (menu marks the current page), current = true on the menu item, e2e marker checks, reportmre
  • 21c8f65dnotes mission 012: STATUSmre
  • 0bbb3dd9notes mission 012: delete section of the browser gate de-flaked (openAsk: calm wait, press again when the question closes by itself); report 012mre
  • f431bdf8notes mission 011: notes on the layouts theme (ListFirst shell), styles cut, check-theme gate, E2E extended; reportmre
  • 1a8603d1notes mission 011 WIP: deploy.sh gate summary also matches check-theme, browser.mjs logout via the user menumre
  • dae2e508notes mission 011 WIP: theme dbe3de7, shell on AppHeader/MainMenu/UserMenu/Sidebar + ListFirst, styles cut to the app's own, check-theme gate, e2e auditmre
  • fd36da27notes mission 010: the note editor is the Hybriel MdEditor block (components.hybriel 1442e58, verbatim); md-editor.js, its route, script tag and offlineFiles retired; gate 66/0, realdata-offline 12/0, round-trip and Chrome E2E tests; report 010mre
  • efa92170notes tests/identkit.mjs: refuse a taken ident port, cold-wait deadline, emit, identities; mission 009 reportmre
  • f3dec0f1Merge branch 'w7'mre