gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitac2c4e3fac2c4e3fident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mreac2c4e3f/components/main.hl

8.4 KB

  1. // components/main.hl — THE SHELL (gitoria#23): the WorldAPI theme's header and content-first shell (theme/shell/*, copied from
  2. // layouts.worldapi.org — never edited here, the way tracker.worldapi.org wears it) around the slot every page renders into, plus
  3. // the display-name prompt of a first login. All CSS is in styles.hl (the shell files carry their own Style).
  4. // THE HEADER: phone — ☰ (the sidebar overlay with the main menu) · brand · ident's selector · the user icon far right (its dropdown:
  5. // your name, Access tokens, SSH keys, Log out); signed out the selector stands alone (no second "Log in" button — creator 2026-10-24).
  6. // From 60rem: brand · main menu · selector · user icon. IDENT'S SELECTOR STANDS IN THE HEADER, visible signed in and signed out, on the
  7. // phone and on the desktop (creator 2026-10-24: the theme move hid it behind an icon — never again; the gate checks it at 390 and 1280).
  8. // The main menu is the app's top level, on the main address: Repositories. The repo's own tabs stay in the repo head of the repo layout level (repo.hl).
  9. // THE SELECTOR (gitoria#14): `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in tickets.
  10. // Choosing an identity fires `ident-login` (one-time code); /login.js hands it to the hidden input
  11. // #identcode, whose `change` goes to the face gitoriaLogin (server-side exchange, no reload). The element's
  12. // class is `in` / `out`; /login.js mirrors it into the selector's `loggedIn`. THE SAME SELECTOR STANDS ON EVERY ADDRESS: the main one and
  13. // every repo address (<repo>.<host>) — ident answers a repo address because the app's registered origins hold the wildcard origin
  14. // `https://*.<host>` (ident accepts `*.` as the first label of a registered origin). The login is the one session of the main
  15. // address and all repo addresses (the cookie's Domain, project.hl sessionDomain).
  16. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl
  17. // loginCallback); /login.js adds `?next=<this page>` at the click so the login returns here.
  18. // FIRST LOGIN: no display name yet → the name prompt; creating a repo waits for it.
  19. import { siteName } from '../project.hl'
  20. import { publicUrl } from '../lib/util.hl'
  21. import { identKey, selectorScript, infoOfSession, userOfLoginCode, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  22. import { randomBytes } from 'hl:crypto'
  23. import AppHeader from '../theme/shell/app-header.hl'
  24. import MainMenu from '../theme/shell/main-menu.hl'
  25. import UserMenu from '../theme/shell/user-menu.hl'
  26. import Sidebar from '../theme/shell/app-sidebar.hl'
  27. import ContentFirst from '../theme/shell/content-first.hl'
  28. // the main menu: the header from 60rem, the phone's sidebar below — one list (every repo address links back to the main one)
  29. // `current = true` STAYS (hybriel#197 checked, mission 010): the route marker needs the item href to be the page path, but this item links to the MAIN address (absolute) and every page of the app (/code, /pulls …) lies under it, so the route cannot tell; it is marked on all
  30. static menu = [
  31. { label = 'Repositories' href = publicUrl + '/' current = true }
  32. ]
  33. slot = null
  34. session = null
  35. me = infoOfSession(session)
  36. loggedIn = me != null
  37. loggedOut = me == null
  38. needsName = me != null && !me.named
  39. myName = me != null && me.named ? me.name : 'you'
  40. selectorClass = me != null ? 'in' : 'out'
  41. tokensHref = publicUrl + '/#tokens'
  42. keysHref = publicUrl + '/#sshkeys'
  43. selectorKey = identKey
  44. identScript = selectorScript
  45. loginError = ''
  46. hasLoginError = false
  47. nameDraft = ''
  48. nameError = ''
  49. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network; the
  50. // shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  51. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  52. // write only when it changed.
  53. offline = false
  54. cookieShared = false
  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 class = selectorClass }
  62. if (loggedIn) {
  63. UserMenu {
  64. p { id = "whoami" class = "who" myName }
  65. a { id = "tokenslink" href = tokensHref "Access tokens" }
  66. a { id = "keyslink" href = keysHref "SSH keys" }
  67. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  68. }
  69. }
  70. }
  71. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  72. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  73. if (offline) { offlineNote { id = "offline" "You are offline. Repositories and code need the network." } }
  74. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  75. if (needsName) {
  76. namePrompt {
  77. form { id = "nameform"
  78. on submit(e) {
  79. e.preventDefault()
  80. emit saveName(e)
  81. }
  82. label { "Welcome! Choose the display name others see as the owner of your repositories"
  83. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  84. }
  85. button { id = "namesave" type = "submit" "Save" }
  86. p { id = "nameerror" class = "message" nameError }
  87. }
  88. }
  89. }
  90. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  91. // page — `Sidebar` + `main { ContentFirst { slot } }`, as tracker does: the page slot must start its own line (hybriel#130)
  92. Sidebar { desktop = "false" MainMenu { items = menu } }
  93. main {
  94. ContentFirst { slot }
  95. }
  96. script { src = identScript }
  97. script { src = "/login.js" }
  98. }
  99. }
  100. showMe = (info) => {
  101. loggedIn = true
  102. loggedOut = false
  103. needsName = !info.named
  104. myName = info.named ? info.name : 'you'
  105. selectorClass = 'in'
  106. loginError = ''
  107. hasLoginError = false
  108. }
  109. showOut = () => {
  110. loggedIn = false
  111. loggedOut = true
  112. needsName = false
  113. myName = 'you'
  114. selectorClass = 'out'
  115. }
  116. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  117. on gotCode(e) {
  118. code = e.target.value
  119. e.target.value = ''
  120. if (code == null || code == '') { return null }
  121. r = emit server gitoriaLogin(code)
  122. if (r == null || r.error != null) {
  123. loginError = r != null ? r.error : 'the login failed'
  124. hasLoginError = true
  125. return null
  126. }
  127. showMe(r)
  128. }
  129. on client gitoriaSignedIn(tag, info) { showMe(info) }
  130. on client gitoriaSignedOut(tag) { showOut() }
  131. on setNameDraft(v) { nameDraft = v }
  132. on netTick(e) {
  133. down = window.navigator.onLine == false
  134. if (down != offline) { offline = down }
  135. // ONE LOGIN FOR EVERY ADDRESS: once per page view of a logged-in session the server re-issues the session cookie with the Domain
  136. // (lib/api.hl shareSession), so a login held only as a host-only cookie of the main address reaches the repo addresses too
  137. if (loggedIn && !cookieShared) {
  138. cookieShared = true
  139. window.__hlAttempt(() => { return fetch('/session/share', { cache = 'no-store' }) })
  140. }
  141. }
  142. on saveName(e) {
  143. r = emit server gitoriaSaveName(nameDraft)
  144. if (r == null || r.error != null) {
  145. nameError = r != null ? r.error : 'could not save the name'
  146. return null
  147. }
  148. nameError = ''
  149. showMe(r)
  150. }
  151. on doLogout(e) {
  152. emit server gitoriaLogOut()
  153. showOut()
  154. }
  155. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  156. on server gitoriaLogin(code, session) {
  157. if (session == null) { return { error = 'no session — reload the page' } }
  158. x = userOfLoginCode(code)
  159. if (x.error != null) { return { error = x.error } }
  160. tag = randomBytes(16)
  161. session.user = { id = x.user.id }
  162. session.data.tag = tag
  163. info = userInfo(x.user)
  164. emit client gitoriaSignedIn(tag, info)
  165. return info
  166. }
  167. on server gitoriaSaveName(name, session) {
  168. u = userOfSession(session)
  169. if (u == null) { return { error = 'log in with ident first' } }
  170. r = setUserName(u.id, name)
  171. if (r.error != null) { return { error = r.error } }
  172. info = userInfo(r.user)
  173. emit client gitoriaSignedIn(session.data.tag, info)
  174. return info
  175. }
  176. on server gitoriaLogOut(session) {
  177. if (session == null) { return { error = 'no session' } }
  178. emit client gitoriaSignedOut(session.data.tag)
  179. session.user = null
  180. return { ok = true }
  181. }

Branches

Latest commits

  • ac2c4e3fident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • b279f536theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 2b01515ctests/ticketskit: a failed start kills the tickets server (own process group); stop() kills the groupmre
  • 109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre
  • 7eb6be27sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b3911918reports/MG-mobile.md: 404 fixed, rebased gatesMG
  • 9da65b42tests/browser.mjs: 404 checks (host, no hydration wait)MG
  • 00517fafgitoria: shell 404 page for unknown paths (catch-all route, status 404, JSON 404 under /api), 390 gate checksMG
  • d9e977f0reports/MG-mobile.md, LOGMG
  • 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
  • 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
  • c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
  • 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
  • 570138cddeploy: security gate (tests/security.mjs)mre
  • da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
  • f98c981fgitoria B1: report wordingmre
  • c6364cedgitoria B1: compact Markdown blocks (one kind flag per block/span, empty and false fields omitted); same rendered HTML, page values -67%mre
  • cd99d2feWIP gitoria#22: always render the repo level's slot (missing-repo boot hang), pages render nothing without a repo; hydration diagnosis in reports/G2-hydrate.mdmre
  • e5404b9breport: commit idsmre
  • 63cfa21ereports/G2-repotabs.mdmre