gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit81f10e4e81f10e4eident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre81f10e4e/components/main.hl

9.7 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 the user icon beside it opens the UserMenu (your name,
  6. // Account, Log out). 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
  7. // edited here. App CSS is in styles.hl.
  8. //
  9. // LOGIN (ticket #7, CONCEPT.md "Login via ident"; ident README "How apps use ident"):
  10. // * THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js. Choosing an
  11. // identity fires `ident-login` with a one-time code. hl:webex cannot listen to a custom DOM
  12. // event, so /login.js (plain JS) hands the code to the hidden input #identcode and fires its
  13. // `change` — the handler below sends it to the face `identLogin`, which exchanges it SERVER
  14. // SIDE and logs this session in. No reload: the face answers who you are and pushes
  15. // `signedIn` to this session's tabs (the pages show their forms).
  16. // * THE HOST TELLS THE SELECTOR: the element's class is `in` / `out` (a member); /login.js
  17. // mirrors it into the selector's `loggedIn` (the `logged-in` attribute). Log out → `out`
  18. // → the selector is reset.
  19. // * THE LOGIN BUTTON: a plain link to <ident>/login?key=&return=<TICKETS_PUBLIC_URL>/login/callback
  20. // (project.hl loginCallback). /login.js adds `?next=<this page>` to the return URL at the
  21. // click, so the user comes back to the page the login started from (ticket #10).
  22. // * /login.js RUNS AGAIN whenever this View flips between logged in / out (hl:webex
  23. // re-creates the header and the <script> elements; ticket #9): it installs itself once
  24. // per document and hands each one-time code to #identcode only once.
  25. // * FIRST LOGIN: no display name yet → the name prompt below; writing waits for it.
  26. import { inboxCountOf } from '../lib/tickets.hl'
  27. import { siteName } from '../project.hl'
  28. import { identKey, 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 UserMenu from '../theme/shell/user-menu.hl'
  33. import Sidebar from '../theme/shell/app-sidebar.hl'
  34. import ContentFirst from '../theme/shell/content-first.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.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. identScript = selectorScript
  57. loginError = ''
  58. hasLoginError = false
  59. nameDraft = ''
  60. nameError = ''
  61. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network;
  62. // the shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  63. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  64. // write only when it changed. (An `img` error or a socket event would race the hydration and be missed.)
  65. offline = false
  66. View {
  67. body {
  68. AppHeader { brand = siteName
  69. MainMenu { items = menu current = menuSay }
  70. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (it shows the
  71. // chosen identity once signed in). /login.js mirrors its state from the class (`in` / `out`). Signed out the plain login link
  72. // stands beside it.
  73. identSelector { id = "selector" key = selectorKey class = selectorClass }
  74. if (loggedIn) {
  75. UserMenu {
  76. p { id = "whoami" class = "who" myName }
  77. a { id = "youlink" href = "/you" "Account and tokens" }
  78. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  79. }
  80. }
  81. }
  82. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  83. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  84. if (offline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  85. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  86. if (needsName) {
  87. namePrompt {
  88. form { id = "nameform"
  89. on submit(e) {
  90. e.preventDefault()
  91. emit saveName(e)
  92. }
  93. label { "Welcome! Choose the display name others see as the author of what you write"
  94. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  95. }
  96. button { id = "namesave" type = "submit" "Save" }
  97. p { id = "nameerror" class = "message" nameError }
  98. }
  99. }
  100. }
  101. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  102. // page — `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  103. Sidebar { desktop = "false" MainMenu { items = menu current = menuSay } }
  104. main {
  105. ContentFirst { slot }
  106. }
  107. script { src = identScript }
  108. script { src = "/login.js" }
  109. // (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old
  110. // custom element would take over its <md-editor> elements)
  111. }
  112. }
  113. // ---- the session as the page sees it ------------------------------------------------------
  114. showMe = (info) => {
  115. loggedIn = true
  116. loggedOut = false
  117. needsName = !info.named
  118. myName = info.named ? info.name : 'you'
  119. selectorClass = 'in'
  120. loginError = ''
  121. hasLoginError = false
  122. }
  123. showOut = () => {
  124. loggedIn = false
  125. loggedOut = true
  126. needsName = false
  127. myName = 'you'
  128. selectorClass = 'out'
  129. inbox = 0
  130. hasInbox = false
  131. }
  132. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  133. on gotCode(e) {
  134. code = e.target.value
  135. e.target.value = ''
  136. if (code == null || code == '') { return null }
  137. r = emit server identLogin(code)
  138. if (r == null || r.error != null) {
  139. loginError = r != null ? r.error : 'the login failed'
  140. hasLoginError = true
  141. return null
  142. }
  143. showMe(r)
  144. emit refreshInbox()
  145. }
  146. on setNameDraft(v) { nameDraft = v }
  147. on netTick(e) {
  148. down = window.navigator.onLine == false
  149. if (down != offline) { offline = down }
  150. }
  151. on saveName(e) {
  152. r = emit server saveDisplayName(nameDraft)
  153. if (r == null || r.error != null) {
  154. nameError = r != null ? r.error : 'could not save the name'
  155. return null
  156. }
  157. nameError = ''
  158. showMe(r)
  159. }
  160. on doLogout(e) {
  161. emit server logOut()
  162. showOut()
  163. }
  164. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  165. on refreshInbox() {
  166. r = emit server myInboxCount()
  167. if (r != null && r.count != null) {
  168. inbox = r.count
  169. hasInbox = r.count > 0
  170. }
  171. }
  172. on client ticketCreated(row) { emit refreshInbox() }
  173. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  174. // this session's other tabs follow a login / name / logout
  175. on client signedIn(tag, info) {
  176. showMe(info)
  177. emit refreshInbox()
  178. }
  179. on client signedOut(tag) { showOut() }
  180. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  181. on server identLogin(code, session) {
  182. if (session == null) { return { error = 'no session — reload the page' } }
  183. x = exchangeCode(code)
  184. if (x.error != null) { return { error = x.error } }
  185. u = ensureUser(x.identity)
  186. if (u == null) { return { error = 'could not store the user' } }
  187. tag = randomBytes(16)
  188. session.user = { id = u.id }
  189. session.data.tag = tag
  190. info = userInfo(u)
  191. emit client signedIn(tag, info)
  192. return info
  193. }
  194. on server saveDisplayName(name, session) {
  195. u = userOfSession(session)
  196. if (u == null) { return { error = 'log in with ident first' } }
  197. r = setUserName(u.id, name)
  198. if (r.error != null) { return { error = r.error } }
  199. info = userInfo(r.user)
  200. emit client signedIn(session.data.tag, info)
  201. return info
  202. }
  203. on server myInboxCount(session) {
  204. return { count = inboxCountOf(userOfSession(session)) }
  205. }
  206. on server logOut(session) {
  207. if (session == null) { return { error = 'no session' } }
  208. // the tag stays (the push may fan out after this face returns); the next login replaces it
  209. emit client signedOut(session.data.tag)
  210. session.user = null
  211. return { ok = true }
  212. }

Branches

Latest commits

  • 81f10e4eident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • f51029abMerge branch 'sy-sync'mre
  • eae6e8c7sync components.hybriel 4922f9c: comments like / Edit / Delete / 'edited' are 44 px targets; gate: 'edited' hit-area padding, thread targets check (SY)mre
  • 0de4750btheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 4eeb7bfeST2 report wordingmre
  • 2558f56cst2-sec: keep the hlsid session cookie name (no one is signed out), Secure flag only; gate: a cookie issued by main stays signed in; ident stub serves selector.js; security.mjs in deploy GATESmre
  • ea2e440esecurity audit (ST): JSON body cap, relation rights, login session rotation, __Host- Secure cookie, API security headers, CSP+referrer meta, /connect cap, one-line subjects, tests/security.mjs, reportmre
  • 7c8c2282sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b6277497report MT-mobile, LOGmre
  • 6709398blist paging: the newest rows come first (the sorted array was not used); filter rows hide their scrollbar; gate checks the ordermre
  • 31736a80gate: member-name check fails on the old row layout toomre
  • e03ae537gate: the phone checks run on without the Show more button (so old code reports every failed check)mre
  • adf7f132gate: 390 px checks for the mobile audit fixes (row number, filters, field widths, Edit, member names, relation taps, paging)mre
  • 28e9c938ticket list: draw the newest 50 rows and a Show more button (500 rows were a 2-4 s first paint, 740 KB, a 90 000 px phone page)mre
  • ccebb0c7mobile: ticket number stays on one line, filter chips one scrolling row, fields full width under their caption, Edit/action buttons, member names whole, 44 px relation linksmre
  • f2dc7741gate: the phone toolbar is two even rows (E2)mre
  • 20f7c33async components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
  • d74a5482sync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
  • 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
  • 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre