gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfd9f92c3fd9f92c3notes mission 014: report (partial), LOG, STATUSmrefd9f92c3/components/main.hl

5.6 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`: the one item is the whole app (the shell passes no path, so the menu cannot tell by itself)
  32. menu = [ { label = 'Notes' href = '/' current = true } ]
  33. View {
  34. body {
  35. AppHeader { brand = siteName
  36. MainMenu { items = menu }
  37. if (loggedIn) {
  38. UserMenu {
  39. p { id = "whoami" class = "who" "Signed in with ident" }
  40. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  41. }
  42. }
  43. // signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it
  44. // is hidden (class `in`), the selector element stays: /login.js mirrors its state
  45. identMenu { class = selectorClass
  46. button { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"
  47. // the ident icon: a small i standing beside a big D lying on the floor; the D's lower face is its thickness
  48. svg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"
  49. 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" }
  50. 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" }
  51. rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }
  52. circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }
  53. }
  54. }
  55. identPanel { id = "ident-panel" popover = "auto"
  56. identSelector { id = "selector" key = selectorKey class = selectorClass }
  57. if (loggedOut) {
  58. a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }
  59. }
  60. }
  61. }
  62. }
  63. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  64. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  65. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem); the page (its own
  66. // shell: list-first for the notes, content-first for the rest) follows — hybriel#130: the page slot starts its own line
  67. Sidebar { desktop = "false" MainMenu { items = menu } }
  68. slot
  69. script { src = identScript }
  70. script { src = "/login.js" }
  71. }
  72. }
  73. showIn = () => {
  74. loggedIn = true
  75. loggedOut = false
  76. selectorClass = 'in'
  77. loginError = ''
  78. hasLoginError = false
  79. }
  80. showOut = () => {
  81. loggedIn = false
  82. loggedOut = true
  83. selectorClass = 'out'
  84. }
  85. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  86. on gotCode(e) {
  87. code = e.target.value
  88. e.target.value = ''
  89. if (code == null || code == '') { return null }
  90. r = emit server notesLogin(code)
  91. if (r == null || r.error != null) {
  92. loginError = r != null ? r.error : 'the login failed'
  93. hasLoginError = true
  94. return null
  95. }
  96. showIn()
  97. navigate('/')
  98. }
  99. on client notesSignedIn(tag) {
  100. showIn()
  101. navigate('/')
  102. }
  103. on client notesSignedOut(tag) {
  104. showOut()
  105. navigate('/')
  106. }
  107. on doLogout(e) {
  108. emit server notesLogOut()
  109. showOut()
  110. navigate('/')
  111. }
  112. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  113. on server notesLogin(code, session) {
  114. if (session == null) { return { error = 'no session — reload the page' } }
  115. x = userOfLoginCode(code)
  116. if (x.error != null) { return { error = x.error } }
  117. tag = randomBytes(16)
  118. session.user = { id = x.user.id }
  119. session.data.tag = tag
  120. emit client notesSignedIn(tag)
  121. return { ok = true }
  122. }
  123. on server notesLogOut(session) {
  124. if (session == null) { return { error = 'no session' } }
  125. emit client notesSignedOut(session.data.tag)
  126. session.user = null
  127. return { ok = true }
  128. }

Branches

Latest commits

  • 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
  • d1cf966dre-vendor hybriel 97bcf128: offlineFiles for the editor script, 44 px taps, 390 px offline checks, mission 008mre
  • 4a610a21paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • eeaea980report 007: say which runs included the removed checkmre
  • 8a8ad9banotes mission 007: report, LOG, STATUSmre
  • 2cce9c96code order: plain declarations where never reassigned (letcount 0 never); gate: scan every IndexedDB at log-out, soft mode for old-code runs, drop a check that could not failmre
  • 7f6a4090README: offline in Hybriel (hl:web offline, continuation, known md-editor gap); gate waits report instead of crash; realdata-offline checkmre
  • 632223f2notes#4: delete notes-offline.js and sw.js (hl:web's generated worker and kept state replace them)mre
  • 52a2acadgate: offline checks on hl:web's worker/queue, Chrome offline via CDP (reload offline first), one-offline conflict, log-out forgets the kept copymre