gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb554cd5fb554cd5flogmreb554cd5f/components/main.hl

10.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. 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, 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 Sidebar from '../theme/shell/app-sidebar.hl'
  26. import ContentFirst from '../theme/shell/content-first.hl'
  27. // the main menu: the header from 60rem, the phone's sidebar below — one list (every repo address links back to the main one)
  28. // 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.
  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. 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. // 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`
  45. // (the callback takes it back there). No route known (first paint) = no `next` = the start page.
  46. route = null
  47. path = route == null ? '' : route.path
  48. selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encodeURIComponent(path))
  49. identScript = selectorScript
  50. loginError = ''
  51. hasLoginError = false
  52. nameDraft = ''
  53. nameError = ''
  54. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network; the
  55. // shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  56. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  57. // write only when it changed.
  58. offline = false
  59. View {
  60. body {
  61. AppHeader { brand = siteName
  62. MainMenu { items = menu }
  63. // 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
  64. // 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).
  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" on change(e) { emit gotCode(e) } }
  73. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  74. if (offline) { offlineNote { id = "offline" "You are offline. Repositories and code need the network." } }
  75. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  76. if (needsName) {
  77. namePrompt {
  78. form { id = "nameform"
  79. on submit(e) {
  80. e.preventDefault()
  81. emit saveName(e)
  82. }
  83. label { "Welcome! Choose the display name others see as the owner of your repositories"
  84. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  85. }
  86. button { id = "namesave" type = "submit" "Save" }
  87. p { id = "nameerror" class = "message" nameError }
  88. }
  89. }
  90. }
  91. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  92. // page — `Sidebar` + `main { ContentFirst { slot } }`, as tracker does: the page slot must start its own line (hybriel#130)
  93. Sidebar { desktop = "false" MainMenu { items = menu } }
  94. main {
  95. ContentFirst { slot }
  96. }
  97. script { src = identScript }
  98. script { src = "/login.js" }
  99. }
  100. }
  101. showMe = (info) => {
  102. loggedIn = true
  103. loggedOut = false
  104. needsName = !info.named
  105. myName = info.named ? info.name : 'you'
  106. selectorClass = 'in'
  107. loginError = ''
  108. hasLoginError = false
  109. }
  110. showOut = () => {
  111. loggedIn = false
  112. loggedOut = true
  113. needsName = false
  114. myName = 'you'
  115. selectorClass = 'out'
  116. }
  117. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  118. on gotCode(e) {
  119. code = e.target.value
  120. e.target.value = ''
  121. if (code == null || code == '') { return null }
  122. r = emit server gitoriaLogin(code)
  123. if (r == null || r.error != null) {
  124. loginError = r != null ? r.error : 'the login failed'
  125. hasLoginError = true
  126. return null
  127. }
  128. showMe(r)
  129. }
  130. on client gitoriaSignedIn(tag, info) { showMe(info) }
  131. on client gitoriaSignedOut(tag) { showOut() }
  132. on setNameDraft(v) { nameDraft = v }
  133. on netTick(e) {
  134. down = window.navigator.onLine == false
  135. if (down != offline) { offline = down }
  136. }
  137. on saveName(e) {
  138. r = emit server gitoriaSaveName(nameDraft)
  139. if (r == null || r.error != null) {
  140. nameError = r != null ? r.error : 'could not save the name'
  141. return null
  142. }
  143. nameError = ''
  144. showMe(r)
  145. }
  146. on doLogout(e) {
  147. emit server gitoriaLogOut()
  148. showOut()
  149. }
  150. // ---- the faces (the trailing `session` is always the server's: hybriel #16) ----
  151. on server gitoriaLogin(code, session) {
  152. if (session == null) { return { error = 'no session — reload the page' } }
  153. x = userOfLoginCode(code)
  154. if (x.error != null) { return { error = x.error } }
  155. tag = randomBytes(16)
  156. session.user = { id = x.user.id }
  157. session.data.tag = tag
  158. info = userInfo(x.user)
  159. emit client gitoriaSignedIn(tag, info)
  160. return info
  161. }
  162. on server gitoriaSaveName(name, session) {
  163. u = userOfSession(session)
  164. if (u == null) { return { error = 'log in with ident first' } }
  165. r = setUserName(u.id, name)
  166. if (r.error != null) { return { error = r.error } }
  167. info = userInfo(r.user)
  168. emit client gitoriaSignedIn(session.data.tag, info)
  169. return info
  170. }
  171. on server gitoriaLogOut(session) {
  172. if (session == null) { return { error = 'no session' } }
  173. emit client gitoriaSignedOut(session.data.tag)
  174. session.user = null
  175. return { ok = true }
  176. }
  177. Style {
  178. #whoami {
  179. marginRight = '.5rem'
  180. fontWeight = '600'
  181. color = 'var(--color-text-strong)'
  182. fontSize = '.875rem'
  183. maxWidth = '6rem'
  184. overflow = 'hidden'
  185. textOverflow = 'ellipsis'
  186. whiteSpace = 'nowrap'
  187. flex = '0 1 auto'
  188. minWidth = '0'
  189. display = 'inline-flex'
  190. alignItems = 'center'
  191. minHeight = '2.75rem'
  192. }
  193. #logout {
  194. flex = 'none'
  195. whiteSpace = 'nowrap'
  196. padding = '.25rem .5rem'
  197. }
  198. identSelector {
  199. '--ident-accent' = 'var(--color-accent)'
  200. '--ident-accent-text' = 'var(--color-accent-text)'
  201. '--ident-background' = 'var(--color-surface)'
  202. '--ident-border' = 'var(--color-surface)'
  203. '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif'
  204. position = 'relative'
  205. flex = '0 1 auto'
  206. minWidth = '0'
  207. }
  208. 'ident-selector::part(button)' {
  209. minHeight = '2.75rem'
  210. padding = '.25rem .6rem'
  211. border = 'none'
  212. whiteSpace = 'nowrap'
  213. }
  214. 'ident-selector::part(status)' {
  215. minHeight = '2.75rem'
  216. padding = '.25rem .6rem'
  217. border = 'none'
  218. whiteSpace = 'nowrap'
  219. overflow = 'hidden'
  220. textOverflow = 'ellipsis'
  221. }
  222. 'ident-selector::part(identity)' {
  223. minHeight = '2.75rem'
  224. border = 'none'
  225. }
  226. 'ident-selector::part(panel)' {
  227. position = 'absolute'
  228. top = '100%'
  229. right = '0'
  230. zIndex = '30'
  231. width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))'
  232. maxWidth = 'none'
  233. border = 'none'
  234. boxShadow = '0 .75rem 2rem ' + 'var(--color-background-sunken)'
  235. }
  236. #loginerror {
  237. margin = '0'
  238. padding = '.5rem var(--layout-gutter)'
  239. background = 'var(--color-background-sunken)'
  240. }
  241. namePrompt {
  242. display = 'block'
  243. paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'
  244. paddingTop = '1rem'
  245. form {
  246. display = 'grid'
  247. gap = '.6rem'
  248. padding = '1rem'
  249. background = 'var(--color-surface)'
  250. borderRadius = 'var(--radius-large)'
  251. '> *' {
  252. margin = '0'
  253. }
  254. }
  255. }
  256. offlineNote {
  257. display = 'block'
  258. padding = '.5rem var(--layout-gutter)'
  259. color = 'var(--color-text-strong)'
  260. background = 'var(--color-surface)'
  261. }
  262. netProbe {
  263. position = 'fixed'
  264. left = '0'
  265. top = '0'
  266. width = '1px'
  267. height = '1px'
  268. opacity = '0'
  269. pointerEvents = 'none'
  270. animation = 'gitoria-net-tick 1s linear infinite'
  271. }
  272. '@keyframes gitoria-net-tick' {
  273. 'from' {
  274. opacity = '0'
  275. }
  276. to {
  277. opacity = '0'
  278. }
  279. }
  280. }

Branches

Latest commits

  • b554cd5flogmre
  • f4c9440ddeploy.sh: tar --hard-dereference for the live data backupmre
  • 1a687b15Merge branch 'w48-member-merge'mre
  • 166c775fW48 report, logmre
  • 1b4623f0Members merge pull requests: API route, button on /pulls and /pulls/N, one shared merge pathmre
  • 1075c38cW48 mission, logmre
  • 17bdd0d6V37/V39 missions, logmre
  • 146de5f8Re-vendor gitoria to Hybriel set-day39 (51e921d7)mre
  • e874e44dtests/status-keyed: app token lives 60 s so it outlives the gate's two restartsmre
  • 270b8d61deploy.sh: DEPLOY_STOP_START=1 stops, waits for the old pid, then starts (mpackdb freeze, replaces the standby swap)mre
  • 3f9235b8project.hl: drop the dummy /pulls/:n component route (hybriel#294 is fixed in day37)mre
  • c90daf19Re-vendor gitoria to Hybriel set-day37 (f6b3d45b)mre
  • 03b5bb08W39 report to reports/, drop scratch repro, mission + logmre
  • 154d333fMerge w39-create-api: POST /api/repos with a user token (#39)mre
  • 149dd512Rewrite W39 reportmre
  • e5385075Expect 401 for POST /api/repos without a tokenmre
  • 1a76055cDocument repository creation APImre
  • 4d779b3bAdd create-api gatemre
  • 88563122Add POST /api/repos for user tokensmre
  • b00860e3Create repositories with member checks in createRepoInmre