gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit090ee809090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre090ee809/components/main.hl

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

Branches

Latest commits

  • 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
  • d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
  • afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
  • 48c1ba79tickets: md-paste-files gate with the file manager casesmre
  • f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
  • 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
  • 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
  • 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
  • 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 0398145ctickets: the table grid rule is marked functional for check-thememre
  • 40fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre
  • c1b77d61tickets#35: text typed before the editor is built is taken in once by the build (the input handler no longer writes it to the field first, which doubled the first letters); the gate failure shows the surfacemre
  • 32bf1873tickets#35: the gate types right after the load with the CPU slowed, no waitingmre
  • 64ea9ca2tickets#35: text typed into the reply editor before the page has finished starting is kept; the gate types right after loadmre
  • ccd3a327tickets: the security gate expects frame-src to be exactly the ident address (the sign-in frame), still no wildcard or selfmre
  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre