gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc37488b1c37488b1MN report: alignment updatemrec37488b1/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

  • 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
  • 90c73ed3notes mobile: back link gapmre
  • 72bd4f83notes mobile: list header on the gutter, delete confirmation as a question + two equal buttons, Delete note under the editor edgemre
  • ba1e73f8notes: a sent edit is done once the server's version is not older, so a second writer's text shows in the first tab; gate: two writers both waysmre
  • c69ef9ebsync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
  • 2eb783f5sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
  • 4dd46dadsync-components: copy icons/icons.hl + README (F4); testsmre
  • c92e4a0ftests/e2e-outside.mjs: real-Chrome E2E, a note pushed from another device while open, then typingmre
  • 0516b4ccmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
  • 38cc11ecmd-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
  • 3e7e79f5reports/H1-hydrate.mdmre
  • d98775e8tests/browser.mjs: wait for hydration before the clicks after a goto('/') (tables new note, phone sidebar)mre
  • 1f3198b6tests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
  • 39cf9fdfre-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • db07aa84tests: short-id-switch ports from env (NOTES_SWITCH_IDENT_PORT/_PORT), defaults unchangedmre
  • 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