gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitcd99d2fecd99d2feWIP 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.mdmrecd99d2fe/components/main.hl

8.8 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 · the user icon far right (its dropdown: your name,
  5. // Access tokens, SSH keys, Log out); signed out the ident icon stands there, its dropdown holds ident's selector and "Log in with
  6. // ident". From 60rem: brand · main menu · user icon; signed out the selector and the login button stand in the header themselves.
  7. // 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).
  8. // THE SELECTOR (gitoria#14): `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in tickets.
  9. // Choosing an identity fires `ident-login` (one-time code); /login.js hands it to the hidden input
  10. // #identcode, whose `change` goes to the face gitoriaLogin (server-side exchange, no reload). The element's
  11. // class is `in` / `out`; /login.js mirrors it into the selector's `loggedIn`. ident only answers a REGISTERED
  12. // origin (the main address), so on a repo address (the request's host, `host = null`, hybriel#74) the selector
  13. // carries the class `onrepo` and styles.hl hides it — the button stays there.
  14. // LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (lib/api.hl
  15. // loginCallback); /login.js adds `?next=<this page>` at the click so the login returns here.
  16. // FIRST LOGIN: no display name yet → the name prompt; creating a repo waits for it.
  17. import { siteName } from '../project.hl'
  18. import { slugOfHost, publicUrl } from '../lib/util.hl'
  19. import { identKey, selectorScript, loginHref, infoOfSession, userOfLoginCode, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  20. import { randomBytes } from 'hl:crypto'
  21. import AppHeader from '../theme/shell/app-header.hl'
  22. import MainMenu from '../theme/shell/main-menu.hl'
  23. import UserMenu from '../theme/shell/user-menu.hl'
  24. import Sidebar from '../theme/shell/app-sidebar.hl'
  25. import ContentFirst from '../theme/shell/content-first.hl'
  26. // the main menu: the header from 60rem, the phone's sidebar below — one list (every repo address links back to the main one)
  27. // `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
  28. static menu = [
  29. { label = 'Repositories' href = publicUrl + '/' current = true }
  30. ]
  31. slot = null
  32. session = null
  33. host = null
  34. me = infoOfSession(session)
  35. loggedIn = me != null
  36. loggedOut = me == null
  37. needsName = me != null && !me.named
  38. myName = me != null && me.named ? me.name : 'you'
  39. buttonHref = loginHref
  40. onRepoHost = slugOfHost(host) != ''
  41. selectorClass = (me != null ? 'in' : 'out') + (onRepoHost ? ' onrepo' : '')
  42. tokensHref = publicUrl + '/#tokens'
  43. keysHref = publicUrl + '/#sshkeys'
  44. selectorKey = identKey
  45. identScript = selectorScript
  46. loginError = ''
  47. hasLoginError = false
  48. nameDraft = ''
  49. nameError = ''
  50. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network; the
  51. // shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  52. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  53. // write only when it changed.
  54. offline = false
  55. View {
  56. body {
  57. AppHeader { brand = siteName
  58. MainMenu { items = menu }
  59. if (loggedIn) {
  60. UserMenu {
  61. p { id = "whoami" class = "who" myName }
  62. a { id = "tokenslink" href = tokensHref "Access tokens" }
  63. a { id = "keyslink" href = keysHref "SSH keys" }
  64. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  65. }
  66. }
  67. // signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it
  68. // is hidden (class `in`), the selector element stays: /login.js mirrors its state (gitoria#14)
  69. identMenu { class = selectorClass
  70. button { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"
  71. // the ident icon (as tracker's): a small i standing beside a big D lying on the floor; the D's lower face is its thickness
  72. svg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"
  73. 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" }
  74. 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" }
  75. rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }
  76. circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }
  77. }
  78. }
  79. identPanel { id = "ident-panel" popover = "auto"
  80. identSelector { id = "selector" key = selectorKey class = selectorClass }
  81. if (loggedOut) {
  82. a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }
  83. }
  84. }
  85. }
  86. }
  87. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  88. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  89. if (offline) { offlineNote { id = "offline" "You are offline. Repositories and code need the network." } }
  90. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  91. if (needsName) {
  92. namePrompt {
  93. form { id = "nameform"
  94. on submit(e) {
  95. e.preventDefault()
  96. emit saveName(e)
  97. }
  98. label { "Welcome! Choose the display name others see as the owner of your repositories"
  99. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  100. }
  101. button { id = "namesave" type = "submit" "Save" }
  102. p { id = "nameerror" class = "message" nameError }
  103. }
  104. }
  105. }
  106. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  107. // page — `Sidebar` + `main { ContentFirst { slot } }`, as tracker does: the page slot must start its own line (hybriel#130)
  108. Sidebar { desktop = "false" MainMenu { items = menu } }
  109. main {
  110. ContentFirst { slot }
  111. }
  112. script { src = identScript }
  113. script { src = "/login.js" }
  114. }
  115. }
  116. showMe = (info) => {
  117. loggedIn = true
  118. loggedOut = false
  119. needsName = !info.named
  120. myName = info.named ? info.name : 'you'
  121. selectorClass = onRepoHost ? 'in onrepo' : 'in'
  122. loginError = ''
  123. hasLoginError = false
  124. }
  125. showOut = () => {
  126. loggedIn = false
  127. loggedOut = true
  128. needsName = false
  129. myName = 'you'
  130. selectorClass = onRepoHost ? 'out onrepo' : 'out'
  131. }
  132. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  133. on gotCode(e) {
  134. code = e.target.value
  135. e.target.value = ''
  136. if (code == null || code == '') { return null }
  137. r = emit server gitoriaLogin(code)
  138. if (r == null || r.error != null) {
  139. loginError = r != null ? r.error : 'the login failed'
  140. hasLoginError = true
  141. return null
  142. }
  143. showMe(r)
  144. }
  145. on client gitoriaSignedIn(tag, info) { showMe(info) }
  146. on client gitoriaSignedOut(tag) { showOut() }
  147. on setNameDraft(v) { nameDraft = v }
  148. on netTick(e) {
  149. down = window.navigator.onLine == false
  150. if (down != offline) { offline = down }
  151. }
  152. on saveName(e) {
  153. r = emit server gitoriaSaveName(nameDraft)
  154. if (r == null || r.error != null) {
  155. nameError = r != null ? r.error : 'could not save the name'
  156. return null
  157. }
  158. nameError = ''
  159. showMe(r)
  160. }
  161. on doLogout(e) {
  162. emit server gitoriaLogOut()
  163. showOut()
  164. }
  165. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  166. on server gitoriaLogin(code, session) {
  167. if (session == null) { return { error = 'no session — reload the page' } }
  168. x = userOfLoginCode(code)
  169. if (x.error != null) { return { error = x.error } }
  170. tag = randomBytes(16)
  171. session.user = { id = x.user.id }
  172. session.data.tag = tag
  173. info = userInfo(x.user)
  174. emit client gitoriaSignedIn(tag, info)
  175. return info
  176. }
  177. on server gitoriaSaveName(name, session) {
  178. u = userOfSession(session)
  179. if (u == null) { return { error = 'log in with ident first' } }
  180. r = setUserName(u.id, name)
  181. if (r.error != null) { return { error = r.error } }
  182. info = userInfo(r.user)
  183. emit client gitoriaSignedIn(session.data.tag, info)
  184. return info
  185. }
  186. on server gitoriaLogOut(session) {
  187. if (session == null) { return { error = 'no session' } }
  188. emit client gitoriaSignedOut(session.data.tag)
  189. session.user = null
  190. return { ok = true }
  191. }

Branches

Latest commits

  • 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
  • 9b0516fdgitoria#22: mark the tab underline functional (check-theme), chain E2E: serve/measure split, bring the lisbeth tab to frontmre
  • 19bc1df8gitoria#22: all repo pages under ONE layout level (components/repo.hl, hl:web D-CHAIN): a tab click replaces only the page in the slot; head and tab nav stay the same DOM nodesmre
  • 40658417tests/browser.mjs: wait for the page to be live (hydrated) before clicking Merge — a click on the server-rendered button before the client mounted was lost (flaky 'Clashing change' under load)mre
  • 48a6154bre-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
  • e972e8d7tests: short-id-switch (GITORIA_SWITCH_IDENT_PORT/_PORT) and ssh tunnel (GITORIA_GATE_TUNNEL_PORT) ports from env, defaults unchangedmre
  • f06f5349re-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
  • c7d3cc87docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • f0e7ff8cdeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • fe5f707cgitoria 010: report, mission, comment on why current = true staysmre
  • 9705ca86gitoria 010: gate: menu marker in the server HTMLmre
  • 8cff663agitoria 010: main-menu.hl from layouts 0bcc629 (route marker)mre
  • 359c79f7gitoria 010: re-vendor Hybriel master f9614007 (plugins whole, bin/ git-ignored)mre
  • 6bd7fb3cgitoria 009: theme re-copied from layouts 76f99f6 (menu marks the current page), current = true on the menu item, e2e marker checks, reportmre
  • 44de915cidentkit: refuse a taken ident port, cold-start deadline, abort on dead ident, clear no-code error (as notes)mre
  • 2bf5343egitoria 007: theme re-copied from layouts dbe3de7 (44 px taps), redundant tap overrides dropped, crumbs class, real-browser walk test, reportmre
  • 18843648deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail) — print check-theme's summary, as layouts doesmre
  • e6dff0cbgitoria#23: report 005, STATUS, LOGmre