gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit41da352541da3525Tickets conductor: flake cause, T36 deploy stepmre41da3525/components/main.hl

12.9 KB

  1. // components/main.hl — THE SHELL (mission 022, phone first on the WorldAPI theme): the theme's AppHeader (brand · main menu
  2. // All tickets / Inbox with its live count · ident's selector · user icon), the phone's Sidebar (☰ → the main menu), the display-name
  3. // prompt of a first login, and the slot every page renders into (ContentFirst). IDENT'S SELECTOR STANDS IN THE HEADER, visible signed in
  4. // and signed out, on the phone and on the desktop (creator 2026-10-24: it was hidden behind an icon / replaced by the user menu in
  5. // missions 022 — never again; the gate checks it at 390 and 1280). Signed in your name (it opens Account and tokens) and Log out stand beside it, as before the theme missions (no user icon). Nothing else stands beside the selector: no second "Log in" button (creator 2026-10-24). The theme's shell files theme/shell/*.hl are never
  6. // edited here. App CSS is in styles.hl.
  7. //
  8. // LOGIN (ticket #7, CONCEPT.md "Login via ident"; ident README "How apps use ident"):
  9. // * THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js. Choosing an
  10. // identity fires `ident-login` with a one-time code. hl:webex cannot listen to a custom DOM
  11. // event, so /login.js (plain JS) hands the code to the hidden input #identcode and fires its
  12. // `change` — the handler below sends it to the face `identLogin`, which exchanges it SERVER
  13. // SIDE and logs this session in. No reload: the face answers who you are and pushes
  14. // `signedIn` to this session's tabs (the pages show their forms).
  15. // * THE HOST TELLS THE SELECTOR: the element's class is `in` / `out` (a member); /login.js
  16. // mirrors it into the selector's `loggedIn` (the `logged-in` attribute). Log out → `out`
  17. // → the selector is reset.
  18. // * THE LOGIN BUTTON: a plain link to <ident>/login?key=&return=<TICKETS_PUBLIC_URL>/login/callback
  19. // (project.hl loginCallback). /login.js adds `?next=<this page>` to the return URL at the
  20. // click, so the user comes back to the page the login started from (ticket #10).
  21. // * /login.js RUNS AGAIN whenever this View flips between logged in / out (hl:webex
  22. // re-creates the header and the <script> elements; ticket #9): it installs itself once
  23. // per document and hands each one-time code to #identcode only once.
  24. // * FIRST LOGIN: no display name yet → the name prompt below; writing waits for it.
  25. import { inboxCountOf } from '../lib/tickets.hl'
  26. import { encode } from '../lib/util.hl'
  27. import { siteName } from '../project.hl'
  28. import { identKey, callbackUrl, selectorScript, infoOfSession, exchangeCode, ensureUser, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  29. import { randomBytes } from 'hl:crypto'
  30. import AppHeader from '../theme/shell/app-header.hl'
  31. import MainMenu from '../theme/shell/main-menu.hl'
  32. import Sidebar from '../theme/shell/app-sidebar.hl'
  33. import ContentFirst from '../theme/shell/content-first.hl'
  34. import { messageLook } from '../lib/looks.hl'
  35. slot = null
  36. session = null
  37. // the inbox is PERSONAL (ticket #20): the tickets assigned to this session's user in pending and review
  38. inbox = inboxCountOf(userOfSession(session))
  39. hasInbox = inbox > 0
  40. // the main menu: the header from 60rem, the phone's sidebar below — one list. The Inbox's live count is its badge (`count`)
  41. // which menu entry the page belongs to: MainMenu takes it from the route (hybriel#197: `route = null` below, in the server's HTML
  42. // too, so the marker is in the first paint). A ticket's /<slug>/<n>, a project's /<slug> and the state filters match no item's path,
  43. // so the shell says '/' for them (All tickets); /inbox marks Inbox by itself; account, settings, new project, connect: none.
  44. route = null
  45. path = route == null ? '' : route.path
  46. menuSay = path == '/inbox' || path == '/you' || path == '/new-project' || path.startsWith('/connect/') || path.startsWith('/login/') || path.endsWith('/settings') ? '' : '/'
  47. menu = [ { label = 'All tickets' href = '/' } { label = 'Inbox' href = '/inbox' count = hasInbox ? inbox : null } ]
  48. // who this session is: { name, named, creator } — never the identity id
  49. me = infoOfSession(session)
  50. loggedIn = me != null
  51. loggedOut = me == null
  52. needsName = me != null && !me.named
  53. myName = me != null && me.named ? me.name : 'you'
  54. selectorClass = me != null ? 'in' : 'out'
  55. selectorKey = identKey
  56. // 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`
  57. // (the callback takes it back there). An unknown path (first paint without a route) leaves `next` empty = the start page.
  58. selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encode(path))
  59. identScript = selectorScript
  60. loginError = ''
  61. hasLoginError = false
  62. nameDraft = ''
  63. nameError = ''
  64. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network;
  65. // the shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  66. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  67. // write only when it changed. (An `img` error or a socket event would race the hydration and be missed.)
  68. offline = false
  69. Style {
  70. pMessage = messageLook + { }
  71. // offline (mission 046): the note, and the invisible probe whose animation ticks every second
  72. offlineNote { display = 'block' padding = '.5rem var(--layout-gutter)' color = 'var(--color-text-strong)' background = 'var(--color-surface)' }
  73. netProbe { position = 'fixed' left = '0' top = '0' width = '1px' height = '1px' opacity = '0' pointerEvents = 'none' animation = 'tickets-net-tick 1s linear infinite' }
  74. '@keyframes tickets-net-tick' = {
  75. 'from' = { opacity = '0' }
  76. to = { opacity = '0' }
  77. }
  78. // the signed-in name at the top of the user menu (UserMenu's own `p.who` look)
  79. '#whoami' { marginRight = '.5rem' fontWeight = '600' color = 'var(--color-text-strong)' fontSize = '.875rem' maxWidth = '6rem' overflow = 'hidden' textOverflow = 'ellipsis' whiteSpace = 'nowrap' flex = '0 1 auto' minWidth = '0' display = 'inline-flex' alignItems = 'center' minHeight = '2.75rem' }
  80. '#logout' { flex = 'none' whiteSpace = 'nowrap' padding = '.25rem .5rem' }
  81. // ident's selector stands in the header, signed in and signed out, on the phone too (creator 2026-10-24). Its shadow DOM is in
  82. // ident's design, restyled to tickets' accent through its custom properties and parts. The pill is kept compact so brand, selector
  83. // and the user icon fit one row at 390 px; its dropdown opens under it, as wide as a phone allows.
  84. 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' }
  85. 'ident-selector::part(button)' { minHeight = '2.75rem' padding = '.25rem .6rem' whiteSpace = 'nowrap' }
  86. 'ident-selector::part(status)' { minHeight = '2.75rem' padding = '.25rem .6rem' whiteSpace = 'nowrap' overflow = 'hidden' textOverflow = 'ellipsis' }
  87. 'ident-selector::part(identity)' { minHeight = '2.75rem' }
  88. '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)' }
  89. '#loginerror' { margin = '0' padding = '.5rem var(--layout-gutter)' background = 'var(--color-background-sunken)' }
  90. // the display-name prompt of a first login: in the content column, under the header
  91. namePrompt { display = 'block' paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))' paddingTop = '1rem' }
  92. '#nameform' { display = 'grid' gap = '.6rem' padding = '1rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }
  93. }
  94. View {
  95. body {
  96. AppHeader { brand = siteName
  97. MainMenu { items = menu current = menuSay }
  98. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (it shows the
  99. // chosen identity once signed in). /login.js mirrors its state from the class (`in` / `out`). Signed out the plain login link
  100. // stands beside it.
  101. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  102. // signed in, like before the theme missions: your name (it opens Account and tokens) and Log out stand beside the selector
  103. if (loggedIn) {
  104. a { id = "whoami" href = "/you" myName }
  105. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  106. }
  107. }
  108. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  109. if (hasLoginError) { p { id = "loginerror" Style.pMessage class = "banner" loginError } }
  110. if (offline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  111. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  112. if (needsName) {
  113. namePrompt {
  114. form { id = "nameform"
  115. on submit(e) {
  116. e.preventDefault()
  117. emit saveName(e)
  118. }
  119. label { "Welcome! Choose the display name others see as the author of what you write"
  120. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  121. }
  122. button { id = "namesave" type = "submit" "Save" }
  123. p { id = "nameerror" Style.pMessage nameError }
  124. }
  125. }
  126. }
  127. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  128. // page — `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  129. Sidebar { desktop = "false" MainMenu { items = menu current = menuSay } }
  130. main {
  131. ContentFirst { slot }
  132. }
  133. script { src = identScript }
  134. script { src = "/login.js" }
  135. // (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old
  136. // custom element would take over its <md-editor> elements)
  137. }
  138. }
  139. // ---- the session as the page sees it ------------------------------------------------------
  140. showMe = (info) => {
  141. loggedIn = true
  142. loggedOut = false
  143. needsName = !info.named
  144. myName = info.named ? info.name : 'you'
  145. selectorClass = 'in'
  146. loginError = ''
  147. hasLoginError = false
  148. }
  149. showOut = () => {
  150. loggedIn = false
  151. loggedOut = true
  152. needsName = false
  153. myName = 'you'
  154. selectorClass = 'out'
  155. inbox = 0
  156. hasInbox = false
  157. }
  158. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  159. on gotCode(e) {
  160. code = e.target.value
  161. e.target.value = ''
  162. if (code == null || code == '') { return null }
  163. r = emit server identLogin(code)
  164. if (r == null || r.error != null) {
  165. loginError = r != null ? r.error : 'the login failed'
  166. hasLoginError = true
  167. return null
  168. }
  169. showMe(r)
  170. emit refreshInbox()
  171. }
  172. on setNameDraft(v) { nameDraft = v }
  173. on netTick(e) {
  174. down = window.navigator.onLine == false
  175. if (down != offline) { offline = down }
  176. }
  177. on saveName(e) {
  178. r = emit server saveDisplayName(nameDraft)
  179. if (r == null || r.error != null) {
  180. nameError = r != null ? r.error : 'could not save the name'
  181. return null
  182. }
  183. nameError = ''
  184. showMe(r)
  185. }
  186. on doLogout(e) {
  187. emit server logOut()
  188. showOut()
  189. }
  190. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  191. on refreshInbox() {
  192. r = emit server myInboxCount()
  193. if (r != null && r.count != null) {
  194. inbox = r.count
  195. hasInbox = r.count > 0
  196. }
  197. }
  198. on client ticketCreated(row) { emit refreshInbox() }
  199. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  200. // this session's other tabs follow a login / name / logout
  201. on client signedIn(tag, info) {
  202. showMe(info)
  203. emit refreshInbox()
  204. }
  205. on client signedOut(tag) { showOut() }
  206. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  207. on server identLogin(code, session) {
  208. if (session == null) { return { error = 'no session — reload the page' } }
  209. x = exchangeCode(code)
  210. if (x.error != null) { return { error = x.error } }
  211. u = ensureUser(x.identity)
  212. if (u == null) { return { error = 'could not store the user' } }
  213. tag = randomBytes(16)
  214. session.user = { id = u.id }
  215. session.data.tag = tag
  216. info = userInfo(u)
  217. emit client signedIn(tag, info)
  218. return info
  219. }
  220. on server saveDisplayName(name, session) {
  221. u = userOfSession(session)
  222. if (u == null) { return { error = 'log in with ident first' } }
  223. r = setUserName(u.id, name)
  224. if (r.error != null) { return { error = r.error } }
  225. info = userInfo(r.user)
  226. emit client signedIn(session.data.tag, info)
  227. return info
  228. }
  229. on server myInboxCount(session) {
  230. return { count = inboxCountOf(userOfSession(session)) }
  231. }
  232. on server logOut(session) {
  233. if (session == null) { return { error = 'no session' } }
  234. // the tag stays (the push may fan out after this face returns); the next login replaces it
  235. emit client signedOut(session.data.tag)
  236. session.user = null
  237. return { ok = true }
  238. }

Branches

Latest commits

  • 41da3525Tickets conductor: flake cause, T36 deploy stepmre
  • 64c477e6Tickets conductor: deploy waits for Arachnemre
  • 467d7286Tickets conductor: T36 done, deploy questionmre
  • 8542fc8aTickets conductor: T36 proof reviewedmre
  • 2a5b8b91Tickets conductor: T36 cap stop, resumed for proofmre
  • 6a82097fTickets conductor: Arachne W228 on day35 flakemre
  • 0ee5a6f2Tickets conductor: T36 resumedmre
  • 9149c165Tickets conductor: T36 diagnosismre
  • 91713313Tickets conductor: T36 report 1mre
  • 756315d2Tickets conductor: T36 startedmre
  • 0814ce6bTickets conductor: brief 025 tickets#36 style formmre
  • 1b6916c4Tickets conductor: Atlas handover tickets#36mre
  • aab95226Tickets conductor: worldapi-conductor paths, deploy blocker = read-only diskmre
  • 6372b06dTickets conductor: worker port slotmre
  • 836af31cTickets conductor: token pathsmre
  • b03f11b6Tickets conductor: CONDUCTOR.md (project part), short STATUS.md, old STATUS to archive/2026-10-31mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre