gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commiteb51864feb51864f|||PR Back/Forward via navigate, server drafts, Hybriel day61Atlaseb51864f/components/main.hl

7.3 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. Its own CSS (the header's selector, the login error, Log out) is its Style block; components/styles.hl keeps only the theme inherit, the accent and the message colour.
  5. // IDENT'S SELECTOR STANDS IN THE HEADER, visible signed in and signed out, on the phone and on the desktop (creator 2026-10-24: the
  6. // theme move hid it behind an icon and replaced it by the user menu — never again; the gate checks it at 390 and 1280). Signed in the
  7. // user icon beside it opens the UserMenu (Log out). Nothing else stands beside the selector: no second "Log in" button (creator 2026-10-24).
  8. // THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in gitoria. Choosing an identity
  9. // fires `ident-login` (one-time code); /login.js hands it to the hidden input #identcode, whose `change` goes to the
  10. // face notesLogin (server-side exchange, lib/users.hl userOfLoginCode; no reload). The element's class is `in` / `out`; /login.js mirrors it into
  11. // the selector's `loggedIn`.
  12. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl loginCallback).
  13. // After a login or logout in this tab the page is fetched again (navigate('/')): the notes of the session show.
  14. import { navigate } from 'hl:web'
  15. import { siteName } from '../project.hl'
  16. import { identKey, callbackUrl, selectorScript, userIdOfSession, userOfLoginCode } from '../lib/users.hl'
  17. import { randomBytes } from 'hl:crypto'
  18. import { messageLook } from '../lib/looks.hl'
  19. import AppHeader from '../theme/shell/app-header.hl'
  20. import MainMenu from '../theme/shell/main-menu.hl'
  21. import Sidebar from '../theme/shell/app-sidebar.hl'
  22. slot = null
  23. session = null
  24. loggedIn = userIdOfSession(session) != null
  25. loggedOut = userIdOfSession(session) == null
  26. selectorClass = loggedIn ? 'in' : 'out'
  27. selectorKey = identKey
  28. // where the selector's sign-in panel (ident#31) sends the browser: the login button's callback, with the page the user is on as `next`
  29. // (the callback takes it back there). No route known (first paint) = no `next` = the start page.
  30. route = null
  31. path = route == null ? '' : route.path
  32. selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encodeURIComponent(path))
  33. identScript = selectorScript
  34. loginError = ''
  35. hasLoginError = false
  36. // 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)
  37. // `current = true` STAYS (mission 015, hybriel#197): the menu now marks an item from the route, but only the page '/' itself (an item
  38. // with href '/' is not "above" other pages, by design) — on /note/:id and /login/failed the route marks nothing (server HTML checked in
  39. // tests/browser.mjs "server html …"; without current = true those two fail), and the one item is the whole app
  40. menu = [ { label = 'Notes' href = '/' current = true } ]
  41. Style {
  42. pMessage = messageLook + { }
  43. // ---- ident's selector in the header (creator 2026-10-24, "you removed the ident widget from all sites"): it stands top right, signed in AND
  44. // signed out, on the phone and on the desktop — never behind an icon or a popover. Its shadow DOM is in ident's design, restyled to the accent
  45. // through its custom properties and parts; the pill is kept compact so brand, selector and the user icon fit one row at 390 px. Its dropdown opens
  46. // under it, as wide as a phone allows.
  47. '#loginerror' { margin = '0' padding = '.5rem var(--layout-gutter)' background = 'var(--color-background-sunken)' }
  48. identSelector { '--ident-accent' = 'var(--color-accent)' '--ident-accent-text' = 'var(--color-accent-text)' '--ident-background' = 'var(--color-surface)' '--ident-border' = 'var(--color-surface)' '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif' position = 'relative' flex = '0 1 auto' minWidth = '0' }
  49. 'ident-selector::part(button)' { minHeight = 'var(--layout-tap)' padding = '.25rem .6rem' whiteSpace = 'nowrap' }
  50. 'ident-selector::part(status)' { minHeight = 'var(--layout-tap)' padding = '.25rem .6rem' whiteSpace = 'nowrap' overflow = 'hidden' textOverflow = 'ellipsis' }
  51. 'ident-selector::part(identity)' { minHeight = 'var(--layout-tap)' }
  52. 'ident-selector::part(panel)' { position = 'absolute' top = '100%' right = '0' zIndex = '30' width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))' maxWidth = 'none' boxShadow = '0 .75rem 2rem var(--color-background-sunken)' }
  53. '#logout' { flex = 'none' whiteSpace = 'nowrap' padding = '.25rem .5rem' }
  54. }
  55. View {
  56. body {
  57. AppHeader { brand = siteName
  58. MainMenu { items = menu }
  59. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (signed in it shows the
  60. // chosen identity). /login.js mirrors its state from the class (`in` / `out`). Nothing else stands beside it: no second "Log in" button (creator 2026-10-24).
  61. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  62. // signed in, like before the theme missions: Log out stands beside the selector
  63. if (loggedIn) {
  64. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  65. }
  66. }
  67. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  68. if (hasLoginError) { p { id = "loginerror" Style.pMessage class = "banner" loginError } }
  69. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem); the page (its own
  70. // shell: list-first for the notes, content-first for the rest) follows — hybriel#130: the page slot starts its own line
  71. Sidebar { desktop = "false" MainMenu { items = menu } }
  72. slot
  73. script { src = identScript }
  74. script { src = "/login.js" }
  75. }
  76. }
  77. showIn = () => {
  78. loggedIn = true
  79. loggedOut = false
  80. selectorClass = 'in'
  81. loginError = ''
  82. hasLoginError = false
  83. }
  84. showOut = () => {
  85. loggedIn = false
  86. loggedOut = true
  87. selectorClass = 'out'
  88. }
  89. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  90. on gotCode(Hybrid e) {
  91. code = e.target.value
  92. e.target.value = ''
  93. if (code == null || code == '') { return null }
  94. r = emit server notesLogin(code)
  95. if (r == null || r.error != null) {
  96. loginError = r != null ? r.error : 'the login failed'
  97. hasLoginError = true
  98. return null
  99. }
  100. showIn()
  101. navigate('/')
  102. }
  103. on client notesSignedIn(String tag) {
  104. showIn()
  105. navigate('/')
  106. }
  107. on client notesSignedOut(String tag) {
  108. showOut()
  109. navigate('/')
  110. }
  111. on doLogout(Hybrid e) {
  112. emit server notesLogOut()
  113. showOut()
  114. navigate('/')
  115. }
  116. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  117. on server notesLogin(code, session) {
  118. if (session == null) { return { error = 'no session — reload the page' } }
  119. x = userOfLoginCode(code)
  120. if (x.error != null) { return { error = x.error } }
  121. tag = randomBytes(16)
  122. session.user = { id = x.user.id }
  123. session.data.tag = tag
  124. emit client notesSignedIn(tag)
  125. return { ok = true }
  126. }
  127. on server notesLogOut(session) {
  128. if (session == null) { return { error = 'no session' } }
  129. emit client notesSignedOut(session.data.tag)
  130. session.user = null
  131. session.data.tag = null
  132. return { ok = true }
  133. }

Branches

Latest commits

  • eb51864f|||PR Back/Forward via navigate, server drafts, Hybriel day61Atlas
  • 3537cf7eMerge branch 'vendor-day59' into mainAtlas
  • c13d188b|||PR Vendor Hybriel day59Atlas
  • 24c95433Merge branch 'notes17-ghost-note' into mainAtlas
  • ae1075b2Preserve rejected drafts during note ID adoptionAtlas
  • 383cce23|||PR Prevent saved local edits from restoring deleted notesAtlas
  • 99ca1cf6Merge branch 'vendor-day56' into mainAtlas
  • 649cef37|||PR Vendor Hybriel day56Atlas
  • aadd0abcMerge branch 'hl-standard-2' into mainAtlas
  • 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
  • 617ee8c0Merge branch 'hl-standard' into mainAtlas
  • 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
  • 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre
  • 5d7cc700Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre
  • d7366702Check session cookie flags after login and assert anonymous GET stays cookielessmre
  • 16bc8fd8Re-vendor Hybriel day38b with the mpackdb store-open race fixmre
  • d860dc2dnotes#12: the markup names its own rules instead of hand-written class strings: the selected row is `aria-current="page"` (the list-first theme rule styles it, no class), the delete question is `Style.pAsk` and follows its own `open` attribute (bound to `asking`), the error line is `Style.pMessage` (body once in lib/looks.hl, rule in notes.hl, main.hl and loginfailed.hl). The CSS declarations are the same, only selectors changed (.ask -> p.ask, .ask.open -> p.ask[open], .message -> p.message); the pages look the same (AE 0 at 4 sizes). main.hl's selectorClass in/out stays (login.js reads it).mre
  • 2e7f8664notes#13: the list and back links pass the note key from the loop (emit pick(e, r.key)) instead of writing data-note into the View and reading it back with getAttribute; the two window.history.replaceState calls and the identcode e.target.value read stay (hl:web has no replace-navigation, a bound hidden input is not adopted on a script's change event), see NO13 reportmre
  • 4dc98282notes#15: a deleted note made in this tab leaves the list at once (the delete now removes this tab's edit under every key the row has: local id, server id); gate: browser.mjs notes#15 section, red on the old codemre