gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfd36da27fd36da27notes 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 010mrefd36da27/components/main.hl

3.3 KB

  1. // components/main.hl — THE SHELL: the application header (brand; top right the login: ident's "Log in with
  2. // ident" button or Log out) and the slot every page renders into. All CSS is in components/styles.hl.
  3. // THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in gitoria. Choosing an identity
  4. // fires `ident-login` (one-time code); /login.js hands it to the hidden input #identcode, whose `change` goes to the
  5. // face notesLogin (server-side exchange, lib/users.hl userOfLoginCode; no reload). The element's class is `in` / `out`; /login.js mirrors it into
  6. // the selector's `loggedIn`.
  7. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl loginCallback).
  8. // After a login or logout in this tab the page is fetched again (navigate('/')): the notes of the session show.
  9. import { navigate } from 'hl:web'
  10. import { siteName } from '../project.hl'
  11. import { identKey, selectorScript, loginHref, userIdOfSession, userOfLoginCode } from '../lib/users.hl'
  12. import { randomBytes } from 'hl:crypto'
  13. slot = null
  14. session = null
  15. loggedIn = userIdOfSession(session) != null
  16. loggedOut = userIdOfSession(session) == null
  17. buttonHref = loginHref
  18. selectorClass = loggedIn ? 'in' : 'out'
  19. selectorKey = identKey
  20. identScript = selectorScript
  21. loginError = ''
  22. hasLoginError = false
  23. View {
  24. body {
  25. applicationHeader {
  26. a { class = "brand" href = "/" siteName }
  27. userBox { id = "userbox"
  28. identSelector { id = "selector" key = selectorKey class = selectorClass }
  29. if (loggedIn) {
  30. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  31. }
  32. if (loggedOut) {
  33. a { id = "loginbutton" class = "button" href = buttonHref "Log in with ident" }
  34. }
  35. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  36. }
  37. }
  38. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  39. main { slot }
  40. script { src = identScript }
  41. script { src = "/login.js" }
  42. }
  43. }
  44. showIn = () => {
  45. loggedIn = true
  46. loggedOut = false
  47. selectorClass = 'in'
  48. loginError = ''
  49. hasLoginError = false
  50. }
  51. showOut = () => {
  52. loggedIn = false
  53. loggedOut = true
  54. selectorClass = 'out'
  55. }
  56. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  57. on gotCode(e) {
  58. code = e.target.value
  59. e.target.value = ''
  60. if (code == null || code == '') { return null }
  61. r = emit server notesLogin(code)
  62. if (r == null || r.error != null) {
  63. loginError = r != null ? r.error : 'the login failed'
  64. hasLoginError = true
  65. return null
  66. }
  67. showIn()
  68. navigate('/')
  69. }
  70. on client notesSignedIn(tag) {
  71. showIn()
  72. navigate('/')
  73. }
  74. on client notesSignedOut(tag) {
  75. showOut()
  76. navigate('/')
  77. }
  78. on doLogout(e) {
  79. emit server notesLogOut()
  80. showOut()
  81. navigate('/')
  82. }
  83. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  84. on server notesLogin(code, session) {
  85. if (session == null) { return { error = 'no session — reload the page' } }
  86. x = userOfLoginCode(code)
  87. if (x.error != null) { return { error = x.error } }
  88. tag = randomBytes(16)
  89. session.user = { id = x.user.id }
  90. session.data.tag = tag
  91. emit client notesSignedIn(tag)
  92. return { ok = true }
  93. }
  94. on server notesLogOut(session) {
  95. if (session == null) { return { error = 'no session' } }
  96. emit client notesSignedOut(session.data.tag)
  97. session.user = null
  98. return { ok = true }
  99. }

Branches

Latest commits

  • 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
  • e5785b03notes#4: the notes page in Hybriel — hl:web offline = [Notes], queued faces notesPut/notesDrop, push notesChanged, value-form notesPull on a tick; notes-offline.js/sw.js no longer loaded or routedmre
  • 510aff75notes#4: server continues a run of saves of one login (by + since), loser keeps writing into its copy; notesFor listmre
  • 0176c4b5mission brief 007mre
  • 06cfa870notes mission 006: re-vendor hybriel 0f396652 (static), reportmre
  • 6c07bd91mission brief w6mre
  • cf64d3d5notes mission 005: stopped at a Hybriel gap (for list repainted during hl:web boot throws, rowKidless); report, LOG, STATUSmre
  • a43b5d2dmission brief 005mre
  • 04a625edmission 004: re-vendor hybriel a832f73b (native bin + plugins as tickets), compose HL_CACHE_DIR volume + tmpfs /tmp, deploy URL wait 120 s, tests wait 120 s per start; gate 57/0 old and new; real-data same output. Not deployed.mre
  • aefb9d44mission brief w4mre