gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite448e656e448e656Tickets conductor: STATUS #51mree448e656/components/main.hl

12.6 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. offlineNote {
  72. display = 'block'
  73. padding = '.5rem var(--layout-gutter)'
  74. color = 'var(--color-text-strong)'
  75. background = 'var(--color-surface)'
  76. }
  77. netProbe {
  78. position = 'fixed'
  79. left = '0'
  80. top = '0'
  81. width = '1px'
  82. height = '1px'
  83. opacity = '0'
  84. pointerEvents = 'none'
  85. animation = 'tickets-net-tick 1s linear infinite'
  86. }
  87. '@keyframes tickets-net-tick' {
  88. 'from' {
  89. opacity = '0'
  90. }
  91. to {
  92. opacity = '0'
  93. }
  94. }
  95. '#whoami' {
  96. marginRight = '.5rem'
  97. fontWeight = '600'
  98. color = 'var(--color-text-strong)'
  99. fontSize = '.875rem'
  100. maxWidth = '6rem'
  101. overflow = 'hidden'
  102. textOverflow = 'ellipsis'
  103. whiteSpace = 'nowrap'
  104. flex = '0 1 auto'
  105. minWidth = '0'
  106. display = 'inline-flex'
  107. alignItems = 'center'
  108. minHeight = '2.75rem'
  109. }
  110. '#logout' {
  111. flex = 'none'
  112. whiteSpace = 'nowrap'
  113. padding = '.25rem .5rem'
  114. }
  115. identSelector {
  116. '--ident-accent' = 'var(--color-accent)'
  117. '--ident-accent-text' = 'var(--color-accent-text)'
  118. '--ident-background' = 'var(--color-surface)'
  119. '--ident-border' = 'var(--color-surface)'
  120. '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif'
  121. position = 'relative'
  122. flex = '0 1 auto'
  123. minWidth = '0'
  124. }
  125. // Keep the whole pseudo-element selector; there is no bare form.
  126. 'ident-selector::part(button)' {
  127. minHeight = '2.75rem'
  128. padding = '.25rem .6rem'
  129. whiteSpace = 'nowrap'
  130. }
  131. // Keep the whole pseudo-element selector; there is no bare form.
  132. 'ident-selector::part(status)' {
  133. minHeight = '2.75rem'
  134. padding = '.25rem .6rem'
  135. whiteSpace = 'nowrap'
  136. overflow = 'hidden'
  137. textOverflow = 'ellipsis'
  138. }
  139. // Keep the whole pseudo-element selector; there is no bare form.
  140. 'ident-selector::part(identity)' {
  141. minHeight = '2.75rem'
  142. }
  143. // Keep the whole pseudo-element selector; there is no bare form.
  144. 'ident-selector::part(panel)' {
  145. position = 'absolute'
  146. top = '100%'
  147. right = '0'
  148. zIndex = '30'
  149. width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))'
  150. maxWidth = 'none'
  151. boxShadow = '0 .75rem 2rem ' + 'var(--color-background-sunken)'
  152. }
  153. '#loginerror' {
  154. margin = '0'
  155. padding = '.5rem var(--layout-gutter)'
  156. background = 'var(--color-background-sunken)'
  157. }
  158. namePrompt {
  159. display = 'block'
  160. paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'
  161. paddingTop = '1rem'
  162. }
  163. '#nameform' {
  164. display = 'grid'
  165. gap = '.6rem'
  166. padding = '1rem'
  167. background = 'var(--color-surface)'
  168. borderRadius = 'var(--radius-large)'
  169. }
  170. }
  171. View {
  172. body {
  173. AppHeader { brand = siteName
  174. MainMenu { items = menu current = menuSay }
  175. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (it shows the
  176. // chosen identity once signed in). /login.js mirrors its state from the class (`in` / `out`). Signed out the plain login link
  177. // stands beside it.
  178. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  179. // signed in, like before the theme missions: your name (it opens Account and tokens) and Log out stand beside the selector
  180. if (loggedIn) {
  181. a { id = "whoami" href = "/you" myName }
  182. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  183. }
  184. }
  185. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  186. if (hasLoginError) { p { id = "loginerror" Style.pMessage class = "banner" loginError } }
  187. if (offline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  188. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  189. if (needsName) {
  190. namePrompt {
  191. form { id = "nameform"
  192. on submit(e) {
  193. e.preventDefault()
  194. emit saveName(e)
  195. }
  196. label { "Welcome! Choose the display name others see as the author of what you write"
  197. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  198. }
  199. button { id = "namesave" type = "submit" "Save" }
  200. p { id = "nameerror" Style.pMessage nameError }
  201. }
  202. }
  203. }
  204. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  205. // page — `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  206. Sidebar { desktop = "false" MainMenu { items = menu current = menuSay } }
  207. main {
  208. ContentFirst { slot }
  209. }
  210. script { src = identScript }
  211. script { src = "/login.js" }
  212. // (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old
  213. // custom element would take over its <md-editor> elements)
  214. }
  215. }
  216. // ---- the session as the page sees it ------------------------------------------------------
  217. showMe = (info) => {
  218. loggedIn = true
  219. loggedOut = false
  220. needsName = !info.named
  221. myName = info.named ? info.name : 'you'
  222. selectorClass = 'in'
  223. loginError = ''
  224. hasLoginError = false
  225. }
  226. showOut = () => {
  227. loggedIn = false
  228. loggedOut = true
  229. needsName = false
  230. myName = 'you'
  231. selectorClass = 'out'
  232. inbox = 0
  233. hasInbox = false
  234. }
  235. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  236. on gotCode(e) {
  237. code = e.target.value
  238. e.target.value = ''
  239. if (code == null || code == '') { return null }
  240. r = emit server identLogin(code)
  241. if (r == null || r.error != null) {
  242. loginError = r != null ? r.error : 'the login failed'
  243. hasLoginError = true
  244. return null
  245. }
  246. showMe(r)
  247. emit refreshInbox()
  248. }
  249. on setNameDraft(v) { nameDraft = v }
  250. on netTick(e) {
  251. down = window.navigator.onLine == false
  252. if (down != offline) { offline = down }
  253. }
  254. on saveName(e) {
  255. r = emit server saveDisplayName(nameDraft)
  256. if (r == null || r.error != null) {
  257. nameError = r != null ? r.error : 'could not save the name'
  258. return null
  259. }
  260. nameError = ''
  261. showMe(r)
  262. }
  263. on doLogout(e) {
  264. emit server logOut()
  265. showOut()
  266. }
  267. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  268. on refreshInbox() {
  269. r = emit server myInboxCount()
  270. if (r != null && r.count != null) {
  271. inbox = r.count
  272. hasInbox = r.count > 0
  273. }
  274. }
  275. on client ticketCreated(row) { emit refreshInbox() }
  276. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  277. // this session's other tabs follow a login / name / logout
  278. on client signedIn(tag, info) {
  279. showMe(info)
  280. emit refreshInbox()
  281. }
  282. on client signedOut(tag) { showOut() }
  283. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  284. on server identLogin(code, session) {
  285. if (session == null) { return { error = 'no session — reload the page' } }
  286. x = exchangeCode(code)
  287. if (x.error != null) { return { error = x.error } }
  288. u = ensureUser(x.identity)
  289. if (u == null) { return { error = 'could not store the user' } }
  290. tag = randomBytes(16)
  291. session.user = { id = u.id }
  292. session.data.tag = tag
  293. info = userInfo(u)
  294. emit client signedIn(tag, info)
  295. return info
  296. }
  297. on server saveDisplayName(name, session) {
  298. u = userOfSession(session)
  299. if (u == null) { return { error = 'log in with ident first' } }
  300. r = setUserName(u.id, name)
  301. if (r.error != null) { return { error = r.error } }
  302. info = userInfo(r.user)
  303. emit client signedIn(session.data.tag, info)
  304. return info
  305. }
  306. on server myInboxCount(session) {
  307. return { count = inboxCountOf(userOfSession(session)) }
  308. }
  309. on server logOut(session) {
  310. if (session == null) { return { error = 'no session' } }
  311. // the tag stays (the push may fan out after this face returns); the next login replaces it
  312. emit client signedOut(session.data.tag)
  313. session.user = null
  314. return { ok = true }
  315. }

Branches

Latest commits

  • e448e656Tickets conductor: STATUS #51mre
  • 1c10857bTickets conductor: P51 eval, brief 027mre
  • e725969dTickets conductor: #51 directionmre
  • 1b5c63ddTickets conductor: P51 startedmre
  • 9f13fbdaTickets conductor: brief 026 prioritymre
  • acc477d9Tickets conductor: brief 026 + Vinzenz recommendationsmre
  • 9233a734Tickets conductor: brief 026 completemre
  • 5da589fdTickets conductor: brief 026 + Gitoria's answermre
  • a3cd5329Tickets conductor: tickets#51 opened, brief 026 draftmre
  • 6f6e5797Tickets conductor: STATUS wordingmre
  • 957de51fTickets conductor: T36 live, #36 review, #50 donemre
  • bc2fde32Merge branch 'main' into t36-stylemre
  • b7ca093atests: wait for the new row and normalize editor marker spacesmre
  • 41da3525Tickets conductor: flake cause, T36 deploy stepmre
  • 64c477e6Tickets conductor: deploy waits for Arachnemre
  • 467d7286Tickets conductor: T36 done, deploy questionmre
  • fed5ca81ticket_list: remove repeated selected-state coloursmre
  • 8542fc8aTickets conductor: T36 proof reviewedmre
  • 35980936inbox: preserve desktop columns after list styles were scopedmre
  • 2a5b8b91Tickets conductor: T36 cap stop, resumed for proofmre