gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commiteae6e8c7eae6e8c7sync components.hybriel 4922f9c: comments like / Edit / Delete / 'edited' are 44 px targets; gate: 'edited' hit-area padding, thread targets check (SY)mreeae6e8c7/components/main.hl

10.5 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 · user icon), the phone's Sidebar (☰ → the main menu), the display-name prompt of a
  3. // first login, and the slot every page renders into (ContentFirst). Signed in the user icon opens the UserMenu (your name,
  4. // Account, Log out); signed out the ident icon opens ident's selector + "Log in with ident" (from 60rem they stand in the
  5. // header). The theme's shell files theme/shell/*.hl are never edited here. App CSS is in styles.hl.
  6. //
  7. // LOGIN (ticket #7, CONCEPT.md "Login via ident"; ident README "How apps use ident"):
  8. // * THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js. Choosing an
  9. // identity fires `ident-login` with a one-time code. hl:webex cannot listen to a custom DOM
  10. // event, so /login.js (plain JS) hands the code to the hidden input #identcode and fires its
  11. // `change` — the handler below sends it to the face `identLogin`, which exchanges it SERVER
  12. // SIDE and logs this session in. No reload: the face answers who you are and pushes
  13. // `signedIn` to this session's tabs (the pages show their forms).
  14. // * THE HOST TELLS THE SELECTOR: the element's class is `in` / `out` (a member); /login.js
  15. // mirrors it into the selector's `loggedIn` (the `logged-in` attribute). Log out → `out`
  16. // → the selector is reset.
  17. // * THE LOGIN BUTTON: a plain link to <ident>/login?key=&return=<TICKETS_PUBLIC_URL>/login/callback
  18. // (project.hl loginCallback). /login.js adds `?next=<this page>` to the return URL at the
  19. // click, so the user comes back to the page the login started from (ticket #10).
  20. // * /login.js RUNS AGAIN whenever this View flips between logged in / out (hl:webex
  21. // re-creates the header and the <script> elements; ticket #9): it installs itself once
  22. // per document and hands each one-time code to #identcode only once.
  23. // * FIRST LOGIN: no display name yet → the name prompt below; writing waits for it.
  24. import { inboxCountOf } from '../lib/tickets.hl'
  25. import { siteName } from '../project.hl'
  26. import { identKey, selectorScript, loginHref, infoOfSession, exchangeCode, ensureUser, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  27. import { randomBytes } from 'hl:crypto'
  28. import AppHeader from '../theme/shell/app-header.hl'
  29. import MainMenu from '../theme/shell/main-menu.hl'
  30. import UserMenu from '../theme/shell/user-menu.hl'
  31. import Sidebar from '../theme/shell/app-sidebar.hl'
  32. import ContentFirst from '../theme/shell/content-first.hl'
  33. slot = null
  34. session = null
  35. // the inbox is PERSONAL (ticket #20): the tickets assigned to this session's user in pending and review
  36. inbox = inboxCountOf(userOfSession(session))
  37. hasInbox = inbox > 0
  38. // the main menu: the header from 60rem, the phone's sidebar below — one list. The Inbox's live count is its badge (`count`)
  39. // which menu entry the page belongs to: MainMenu takes it from the route (hybriel#197: `route = null` below, in the server's HTML
  40. // 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,
  41. // so the shell says '/' for them (All tickets); /inbox marks Inbox by itself; account, settings, new project, connect: none.
  42. route = null
  43. path = route == null ? '' : route.path
  44. menuSay = path == '/inbox' || path == '/you' || path == '/new-project' || path.startsWith('/connect/') || path.endsWith('/settings') ? '' : '/'
  45. menu = [ { label = 'All tickets' href = '/' } { label = 'Inbox' href = '/inbox' count = hasInbox ? inbox : null } ]
  46. // who this session is: { name, named, creator } — never the identity id
  47. me = infoOfSession(session)
  48. loggedIn = me != null
  49. loggedOut = me == null
  50. needsName = me != null && !me.named
  51. myName = me != null && me.named ? me.name : 'you'
  52. selectorClass = me != null ? 'in' : 'out'
  53. selectorKey = identKey
  54. identScript = selectorScript
  55. buttonHref = loginHref
  56. loginError = ''
  57. hasLoginError = false
  58. nameDraft = ''
  59. nameError = ''
  60. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network;
  61. // the shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  62. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  63. // write only when it changed. (An `img` error or a socket event would race the hydration and be missed.)
  64. offline = false
  65. View {
  66. body {
  67. AppHeader { brand = siteName
  68. MainMenu { items = menu current = menuSay }
  69. if (loggedIn) {
  70. UserMenu {
  71. p { id = "whoami" class = "who" myName }
  72. a { id = "youlink" href = "/you" "Account and tokens" }
  73. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  74. }
  75. }
  76. // signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it
  77. // is hidden (class `in`), the selector element stays: /login.js mirrors its state
  78. identMenu { class = selectorClass
  79. button { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"
  80. // the ident icon: a small i standing beside a big D lying on the floor; the D's lower face is its thickness
  81. svg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"
  82. path { class = "ident-d-side" d = "M5 22.6 L7.8 14.2 C15.1 14.2 19 16.6 19.6 18.4 C20.2 20.2 16.2 22.6 5 22.6 Z" }
  83. path { class = "ident-d" "fill-rule" = "evenodd" d = "M5 21 L7.8 12.6 C15.1 12.6 19 15 19.6 16.8 C20.2 18.6 16.2 21 5 21 Z M10.7 14.4 C13.6 14.4 15.4 15.3 15.6 16.8 C15.8 18.3 13.7 19.2 10 19.2 Z" }
  84. rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }
  85. circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }
  86. }
  87. }
  88. identPanel { id = "ident-panel" popover = "auto"
  89. identSelector { id = "selector" key = selectorKey class = selectorClass }
  90. if (loggedOut) {
  91. a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }
  92. }
  93. }
  94. }
  95. }
  96. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  97. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  98. if (offline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  99. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  100. if (needsName) {
  101. namePrompt {
  102. form { id = "nameform"
  103. on submit(e) {
  104. e.preventDefault()
  105. emit saveName(e)
  106. }
  107. label { "Welcome! Choose the display name others see as the author of what you write"
  108. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  109. }
  110. button { id = "namesave" type = "submit" "Save" }
  111. p { id = "nameerror" class = "message" nameError }
  112. }
  113. }
  114. }
  115. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  116. // page — `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  117. Sidebar { desktop = "false" MainMenu { items = menu current = menuSay } }
  118. main {
  119. ContentFirst { slot }
  120. }
  121. script { src = identScript }
  122. script { src = "/login.js" }
  123. // (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old
  124. // custom element would take over its <md-editor> elements)
  125. }
  126. }
  127. // ---- the session as the page sees it ------------------------------------------------------
  128. showMe = (info) => {
  129. loggedIn = true
  130. loggedOut = false
  131. needsName = !info.named
  132. myName = info.named ? info.name : 'you'
  133. selectorClass = 'in'
  134. loginError = ''
  135. hasLoginError = false
  136. }
  137. showOut = () => {
  138. loggedIn = false
  139. loggedOut = true
  140. needsName = false
  141. myName = 'you'
  142. selectorClass = 'out'
  143. inbox = 0
  144. hasInbox = false
  145. }
  146. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  147. on gotCode(e) {
  148. code = e.target.value
  149. e.target.value = ''
  150. if (code == null || code == '') { return null }
  151. r = emit server identLogin(code)
  152. if (r == null || r.error != null) {
  153. loginError = r != null ? r.error : 'the login failed'
  154. hasLoginError = true
  155. return null
  156. }
  157. showMe(r)
  158. emit refreshInbox()
  159. }
  160. on setNameDraft(v) { nameDraft = v }
  161. on netTick(e) {
  162. down = window.navigator.onLine == false
  163. if (down != offline) { offline = down }
  164. }
  165. on saveName(e) {
  166. r = emit server saveDisplayName(nameDraft)
  167. if (r == null || r.error != null) {
  168. nameError = r != null ? r.error : 'could not save the name'
  169. return null
  170. }
  171. nameError = ''
  172. showMe(r)
  173. }
  174. on doLogout(e) {
  175. emit server logOut()
  176. showOut()
  177. }
  178. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  179. on refreshInbox() {
  180. r = emit server myInboxCount()
  181. if (r != null && r.count != null) {
  182. inbox = r.count
  183. hasInbox = r.count > 0
  184. }
  185. }
  186. on client ticketCreated(row) { emit refreshInbox() }
  187. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  188. // this session's other tabs follow a login / name / logout
  189. on client signedIn(tag, info) {
  190. showMe(info)
  191. emit refreshInbox()
  192. }
  193. on client signedOut(tag) { showOut() }
  194. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  195. on server identLogin(code, session) {
  196. if (session == null) { return { error = 'no session — reload the page' } }
  197. x = exchangeCode(code)
  198. if (x.error != null) { return { error = x.error } }
  199. u = ensureUser(x.identity)
  200. if (u == null) { return { error = 'could not store the user' } }
  201. tag = randomBytes(16)
  202. session.user = { id = u.id }
  203. session.data.tag = tag
  204. info = userInfo(u)
  205. emit client signedIn(tag, info)
  206. return info
  207. }
  208. on server saveDisplayName(name, session) {
  209. u = userOfSession(session)
  210. if (u == null) { return { error = 'log in with ident first' } }
  211. r = setUserName(u.id, name)
  212. if (r.error != null) { return { error = r.error } }
  213. info = userInfo(r.user)
  214. emit client signedIn(session.data.tag, info)
  215. return info
  216. }
  217. on server myInboxCount(session) {
  218. return { count = inboxCountOf(userOfSession(session)) }
  219. }
  220. on server logOut(session) {
  221. if (session == null) { return { error = 'no session' } }
  222. // the tag stays (the push may fan out after this face returns); the next login replaces it
  223. emit client signedOut(session.data.tag)
  224. session.user = null
  225. return { ok = true }
  226. }

Branches

Latest commits

  • eae6e8c7sync components.hybriel 4922f9c: comments like / Edit / Delete / 'edited' are 44 px targets; gate: 'edited' hit-area padding, thread targets check (SY)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
  • c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
  • 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
  • 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre