gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf3dec0f1f3dec0f1Merge branch 'w7'mref3dec0f1/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. script { src = "/md-editor.js" }
  43. }
  44. }
  45. showIn = () => {
  46. loggedIn = true
  47. loggedOut = false
  48. selectorClass = 'in'
  49. loginError = ''
  50. hasLoginError = false
  51. }
  52. showOut = () => {
  53. loggedIn = false
  54. loggedOut = true
  55. selectorClass = 'out'
  56. }
  57. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  58. on gotCode(e) {
  59. code = e.target.value
  60. e.target.value = ''
  61. if (code == null || code == '') { return null }
  62. r = emit server notesLogin(code)
  63. if (r == null || r.error != null) {
  64. loginError = r != null ? r.error : 'the login failed'
  65. hasLoginError = true
  66. return null
  67. }
  68. showIn()
  69. navigate('/')
  70. }
  71. on client notesSignedIn(tag) {
  72. showIn()
  73. navigate('/')
  74. }
  75. on client notesSignedOut(tag) {
  76. showOut()
  77. navigate('/')
  78. }
  79. on doLogout(e) {
  80. emit server notesLogOut()
  81. showOut()
  82. navigate('/')
  83. }
  84. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  85. on server notesLogin(code, session) {
  86. if (session == null) { return { error = 'no session — reload the page' } }
  87. x = userOfLoginCode(code)
  88. if (x.error != null) { return { error = x.error } }
  89. tag = randomBytes(16)
  90. session.user = { id = x.user.id }
  91. session.data.tag = tag
  92. emit client notesSignedIn(tag)
  93. return { ok = true }
  94. }
  95. on server notesLogOut(session) {
  96. if (session == null) { return { error = 'no session' } }
  97. emit client notesSignedOut(session.data.tag)
  98. session.user = null
  99. return { ok = true }
  100. }

Branches

Latest commits

  • 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
  • 202098b3docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 304f6a9dnotes mission 003 (#5): report, STATUS, LOGmre