gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9eff66279eff6627Merge branch 'f2-api-bugs' into mainGitoria9eff6627/components/main.hl

10.6 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. The shell owns its Style block (the theme shells 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, callbackUrl, selectorScript, infoOfSession, login, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  22. import AppHeader from '../theme/shell/app-header.hl'
  23. import MainMenu from '../theme/shell/main-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. // an INSTANCE property, not `static` (gitoria#23 reopened): a static is evaluated again in the browser after an in-page navigation, where `publicUrl` (hl:proc env) has no value — the link became a 404. The instance property is filled by the server.
  28. // `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
  29. menu = [
  30. { label = 'Repositories' href = publicUrl + '/' current = true }
  31. ]
  32. slot = null
  33. session = 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. selectorClass = me != null ? 'in' : 'out'
  40. tokensHref = publicUrl + '/#tokens'
  41. keysHref = publicUrl + '/#sshkeys'
  42. selectorKey = identKey
  43. // 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`
  44. // (the callback takes it back there). No route known (first paint) = no `next` = the start page.
  45. route = null
  46. path = route == null ? '' : route.path
  47. selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encodeURIComponent(path))
  48. identScript = selectorScript
  49. identCode = ''
  50. loginError = ''
  51. hasLoginError = false
  52. nameDraft = ''
  53. nameError = ''
  54. // OFFLINE (mission 046): the service worker opens `/` from its cache without a network; the shell says so. hl:web keeps
  55. // `__hlOnline` in step with the browser's connection, in this shell too (hybriel#330).
  56. __hlOnline = true
  57. offline = !__hlOnline
  58. View {
  59. body {
  60. AppHeader { brand = siteName
  61. MainMenu { items = menu }
  62. // 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
  63. // 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).
  64. // Runtime login-state classes are consumed by the ident bridge, not a Style rule.
  65. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  66. // signed in, like before the theme missions: your name and Log out stand beside the selector (Access tokens and SSH keys are on the account pages)
  67. if (loggedIn) {
  68. span { id = "whoami" myName }
  69. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  70. }
  71. }
  72. input { id = "identcode" type = "hidden" value = identCode on change(e) { identCode = e.target.value emit gotCode(e) } }
  73. if (hasLoginError) { p { id = "loginerror" class = "banner" loginError } }
  74. if (offline) { offlineNote { id = "offline" "You are offline. Repositories and code need the network." } }
  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" 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 = identCode
  119. identCode = ''
  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 saveName(e) {
  133. r = emit server gitoriaSaveName(nameDraft)
  134. if (r == null || r.error != null) {
  135. nameError = r != null ? r.error : 'could not save the name'
  136. return null
  137. }
  138. nameError = ''
  139. showMe(r)
  140. }
  141. on doLogout(e) {
  142. emit server gitoriaLogOut()
  143. showOut()
  144. }
  145. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  146. on server gitoriaLogin(code, session) {
  147. if (session == null) { return { error = 'no session — reload the page' } }
  148. x = login(code, session, null)
  149. if (x.error != null) { return { error = x.error } }
  150. emit client gitoriaSignedIn(x.tag, x.info)
  151. return x.info
  152. }
  153. on server gitoriaSaveName(name, session) {
  154. u = userOfSession(session)
  155. if (u == null) { return { error = 'log in with ident first' } }
  156. r = setUserName(u.id, name)
  157. if (r.error != null) { return { error = r.error } }
  158. info = userInfo(r.user)
  159. emit client gitoriaSignedIn(session.data.tag, info)
  160. return info
  161. }
  162. on server gitoriaLogOut(session) {
  163. if (session == null) { return { error = 'no session' } }
  164. emit client gitoriaSignedOut(session.data.tag)
  165. session.user = null
  166. return { ok = true }
  167. }
  168. Style {
  169. #whoami {
  170. marginRight = '.5rem'
  171. fontWeight = '600'
  172. color = 'var(--color-text-strong)'
  173. fontSize = '.875rem'
  174. maxWidth = '6rem'
  175. overflow = 'hidden'
  176. textOverflow = 'ellipsis'
  177. whiteSpace = 'nowrap'
  178. flex = '0 1 auto'
  179. minWidth = '0'
  180. display = 'inline-flex'
  181. alignItems = 'center'
  182. minHeight = '2.75rem'
  183. }
  184. #logout {
  185. flex = 'none'
  186. whiteSpace = 'nowrap'
  187. padding = '.25rem .5rem'
  188. }
  189. identSelector {
  190. '--ident-accent' = 'var(--color-accent)'
  191. '--ident-accent-text' = 'var(--color-accent-text)'
  192. '--ident-background' = 'var(--color-surface)'
  193. '--ident-border' = 'var(--color-surface)'
  194. '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif'
  195. position = 'relative'
  196. flex = '0 1 auto'
  197. minWidth = '0'
  198. }
  199. // Pseudo-elements and parts have no bare language form.
  200. 'ident-selector::part(button)' {
  201. minHeight = '2.75rem'
  202. padding = '.25rem .6rem'
  203. border = 'none'
  204. whiteSpace = 'nowrap'
  205. }
  206. // Pseudo-elements and parts have no bare language form.
  207. 'ident-selector::part(status)' {
  208. minHeight = '2.75rem'
  209. padding = '.25rem .6rem'
  210. border = 'none'
  211. whiteSpace = 'nowrap'
  212. overflow = 'hidden'
  213. textOverflow = 'ellipsis'
  214. }
  215. // Pseudo-elements and parts have no bare language form.
  216. 'ident-selector::part(identity)' {
  217. minHeight = '2.75rem'
  218. border = 'none'
  219. }
  220. // Pseudo-elements and parts have no bare language form.
  221. 'ident-selector::part(panel)' {
  222. position = 'absolute'
  223. top = '100%'
  224. right = '0'
  225. zIndex = '30'
  226. width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))'
  227. maxWidth = 'none'
  228. border = 'none'
  229. boxShadow = '0 .75rem 2rem ' + 'var(--color-background-sunken)'
  230. }
  231. #loginerror {
  232. color = 'var(--color-danger)'
  233. empty { display = 'none' }
  234. margin = '0'
  235. padding = '.5rem var(--layout-gutter)'
  236. background = 'var(--color-background-sunken)'
  237. }
  238. namePrompt {
  239. display = 'block'
  240. paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'
  241. paddingTop = '1rem'
  242. }
  243. offlineNote {
  244. display = 'block'
  245. padding = '.5rem var(--layout-gutter)'
  246. color = 'var(--color-text-strong)'
  247. background = 'var(--color-surface)'
  248. }
  249. #nameerror {
  250. margin = '0'
  251. color = 'var(--color-danger)'
  252. empty { display = 'none' }
  253. }
  254. #nameform {
  255. display = 'grid'
  256. gap = '.6rem'
  257. padding = '1rem'
  258. background = 'var(--color-surface)'
  259. borderRadius = 'var(--radius-large)'
  260. // Direct-child and sibling combinators have no bare language form.
  261. '> *' {
  262. margin = '0'
  263. }
  264. }
  265. }

Branches

Latest commits

  • 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria
  • 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
  • f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
  • 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
  • 16a3530fMerge branch 'heap-revert' into mainGitoria
  • 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
  • 13f0c342Merge branch 'hl25-records' into mainGitoria
  • a002ecb7|||PR records: HL25 report, heap helper, logmre
  • 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
  • fefaedd2log: tracker PR-only, HL25 startedmre
  • 21aa57calog: parkmre
  • e9f950a8reports: G25c soakmre
  • a7783686log: deploy 9f41ffcmre
  • 9f41ffc1log: W30b mergedmre
  • bef635c1Merge branch 'w30b'mre
  • 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
  • c4f6d9e3reports: G25c growth huntmre
  • b88e39f1log: privacy cleanup donemre