gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchk40-lists9af8e780|||PR Use keyed list mutations for live ticket updatesmrek40-lists/components/main.hl

11.7 KB

  1. import { login } from '../lib/users.hl'
  2. // components/main.hl — THE SHELL (mission 022, phone first on the WorldAPI theme): the theme's AppHeader (brand · main menu
  3. // All tickets / Inbox with its live count · ident's selector · user icon), the phone's Sidebar (☰ → the main menu), the display-name
  4. // prompt of a first login, and the slot every page renders into (ContentFirst). IDENT'S SELECTOR STANDS IN THE HEADER, visible signed in
  5. // 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
  6. // 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
  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 { encode } from '../lib/util.hl'
  28. import { siteName } from '../project.hl'
  29. import { identKey, callbackUrl, selectorScript, infoOfSession, exchangeCode, ensureUser, userInfo, setUserName, userOfSession } from '../lib/users.hl'
  30. import { randomBytes } from 'hl:crypto'
  31. import AppHeader from '../theme/shell/app-header.hl'
  32. import MainMenu from '../theme/shell/main-menu.hl'
  33. import Sidebar from '../theme/shell/app-sidebar.hl'
  34. import ContentFirst from '../theme/shell/content-first.hl'
  35. import { messageLook } from '../lib/looks.hl'
  36. slot = null
  37. session = null
  38. // the inbox is PERSONAL (ticket #20): the tickets assigned to this session's user in pending and review
  39. inbox = inboxCountOf(userOfSession(session))
  40. hasInbox = inbox > 0
  41. // the main menu: the header from 60rem, the phone's sidebar below — one list. The Inbox's live count is its badge (`count`)
  42. // which menu entry the page belongs to: MainMenu takes it from the route (hybriel#197: `route = null` below, in the server's HTML
  43. // 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,
  44. // so the shell says '/' for them (All tickets); /inbox marks Inbox by itself; account, settings, new project, connect: none.
  45. route = null
  46. path = route == null ? '' : route.path
  47. menuSay = path == '/inbox' || path == '/you' || path == '/new-project' || path.startsWith('/connect/') || path.startsWith('/login/') || path.endsWith('/settings') ? '' : '/'
  48. menu = [ { label = 'All tickets' href = '/' } { label = 'Inbox' href = '/inbox' count = hasInbox ? inbox : null } ]
  49. // who this session is: { name, named, creator } — never the identity id
  50. me = infoOfSession(session)
  51. loggedIn = me != null
  52. loggedOut = me == null
  53. needsName = me != null && !me.named
  54. myName = me != null && me.named ? me.name : 'you'
  55. selectorClass = me != null ? 'in' : 'out'
  56. selectorKey = identKey
  57. // 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`
  58. // (the callback takes it back there). An unknown path (first paint without a route) leaves `next` empty = the start page.
  59. selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encode(path))
  60. identScript = selectorScript
  61. loginError = ''
  62. hasLoginError = false
  63. nameDraft = ''
  64. nameError = ''
  65. // hl:web updates this shell member at boot and on browser connection changes.
  66. __hlOnline = true
  67. Style {
  68. pMessage = messageLook + { }
  69. offlineNote {
  70. display = 'block'
  71. padding = '.5rem var(--layout-gutter)'
  72. color = 'var(--color-text-strong)'
  73. background = 'var(--color-surface)'
  74. }
  75. '#whoami' {
  76. marginRight = '.5rem'
  77. fontWeight = '600'
  78. color = 'var(--color-text-strong)'
  79. fontSize = '.875rem'
  80. maxWidth = '6rem'
  81. overflow = 'hidden'
  82. textOverflow = 'ellipsis'
  83. whiteSpace = 'nowrap'
  84. flex = '0 1 auto'
  85. minWidth = '0'
  86. display = 'inline-flex'
  87. alignItems = 'center'
  88. minHeight = '2.75rem'
  89. }
  90. '#logout' {
  91. flex = 'none'
  92. whiteSpace = 'nowrap'
  93. padding = '.25rem .5rem'
  94. }
  95. identSelector {
  96. '--ident-accent' = 'var(--color-accent)'
  97. '--ident-accent-text' = 'var(--color-accent-text)'
  98. '--ident-background' = 'var(--color-surface)'
  99. '--ident-border' = 'var(--color-surface)'
  100. '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif'
  101. position = 'relative'
  102. flex = '0 1 auto'
  103. minWidth = '0'
  104. }
  105. // Keep the whole pseudo-element selector; there is no bare form.
  106. 'ident-selector::part(button)' {
  107. minHeight = '2.75rem'
  108. padding = '.25rem .6rem'
  109. whiteSpace = 'nowrap'
  110. }
  111. // Keep the whole pseudo-element selector; there is no bare form.
  112. 'ident-selector::part(status)' {
  113. minHeight = '2.75rem'
  114. padding = '.25rem .6rem'
  115. whiteSpace = 'nowrap'
  116. overflow = 'hidden'
  117. textOverflow = 'ellipsis'
  118. }
  119. // Keep the whole pseudo-element selector; there is no bare form.
  120. 'ident-selector::part(identity)' {
  121. minHeight = '2.75rem'
  122. }
  123. // Keep the whole pseudo-element selector; there is no bare form.
  124. 'ident-selector::part(panel)' {
  125. position = 'absolute'
  126. top = '100%'
  127. right = '0'
  128. zIndex = '30'
  129. width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))'
  130. maxWidth = 'none'
  131. boxShadow = '0 .75rem 2rem ' + 'var(--color-background-sunken)'
  132. }
  133. '#loginerror' {
  134. margin = '0'
  135. padding = '.5rem var(--layout-gutter)'
  136. background = 'var(--color-background-sunken)'
  137. }
  138. namePrompt {
  139. display = 'block'
  140. paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'
  141. paddingTop = '1rem'
  142. }
  143. '#nameform' {
  144. display = 'grid'
  145. gap = '.6rem'
  146. padding = '1rem'
  147. background = 'var(--color-surface)'
  148. borderRadius = 'var(--radius-large)'
  149. }
  150. }
  151. View {
  152. body {
  153. AppHeader { brand = siteName
  154. MainMenu { items = menu current = menuSay }
  155. // ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (it shows the
  156. // chosen identity once signed in). /login.js mirrors its state from the class (`in` / `out`). Signed out the plain login link
  157. // stands beside it.
  158. identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }
  159. // signed in, like before the theme missions: your name (it opens Account and tokens) and Log out stand beside the selector
  160. if (loggedIn) {
  161. a { id = "whoami" href = "/you" myName }
  162. button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }
  163. }
  164. }
  165. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  166. if (hasLoginError) { p { id = "loginerror" Style.pMessage class = "banner" loginError } }
  167. if (!__hlOnline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  168. if (needsName) {
  169. namePrompt {
  170. form { id = "nameform"
  171. on submit(e) {
  172. e.preventDefault()
  173. emit saveName(e)
  174. }
  175. label { "Welcome! Choose the display name others see as the author of what you write"
  176. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  177. }
  178. button { id = "namesave" type = "submit" "Save" }
  179. p { id = "nameerror" Style.pMessage nameError }
  180. }
  181. }
  182. }
  183. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  184. // page — `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  185. Sidebar { desktop = "false" MainMenu { items = menu current = menuSay } }
  186. main {
  187. ContentFirst { slot }
  188. }
  189. script { src = identScript }
  190. script { src = "/login.js" }
  191. // (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old
  192. // custom element would take over its <md-editor> elements)
  193. }
  194. }
  195. // ---- the session as the page sees it ------------------------------------------------------
  196. showMe = (info) => {
  197. loggedIn = true
  198. loggedOut = false
  199. needsName = !info.named
  200. myName = info.named ? info.name : 'you'
  201. selectorClass = 'in'
  202. loginError = ''
  203. hasLoginError = false
  204. }
  205. showOut = () => {
  206. loggedIn = false
  207. loggedOut = true
  208. needsName = false
  209. myName = 'you'
  210. selectorClass = 'out'
  211. inbox = 0
  212. hasInbox = false
  213. }
  214. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  215. on gotCode(e) {
  216. code = e.target.value
  217. e.target.value = ''
  218. if (code == null || code == '') { return null }
  219. r = emit server identLogin(code)
  220. if (r == null || r.error != null) {
  221. loginError = r != null ? r.error : 'the login failed'
  222. hasLoginError = true
  223. return null
  224. }
  225. showMe(r)
  226. emit refreshInbox()
  227. }
  228. on setNameDraft(v) { nameDraft = v }
  229. on saveName(e) {
  230. r = emit server saveDisplayName(nameDraft)
  231. if (r == null || r.error != null) {
  232. nameError = r != null ? r.error : 'could not save the name'
  233. return null
  234. }
  235. nameError = ''
  236. showMe(r)
  237. }
  238. on doLogout(e) {
  239. emit server logOut()
  240. showOut()
  241. }
  242. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  243. on refreshInbox() {
  244. r = emit server myInboxCount()
  245. if (r != null && r.count != null) {
  246. inbox = r.count
  247. hasInbox = r.count > 0
  248. }
  249. }
  250. on client ticketCreated(row) { emit refreshInbox() }
  251. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  252. // this session's other tabs follow a login / name / logout
  253. on client signedIn(tag, info) {
  254. showMe(info)
  255. emit refreshInbox()
  256. }
  257. on client signedOut(tag) { showOut() }
  258. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  259. on server identLogin(code, session) {
  260. if (session == null) { return { error = 'no session — reload the page' } }
  261. r = login(code, null, &session, null)
  262. if (r.error != null) { return { error = r.error } }
  263. emit client signedIn(r.tag, r.info)
  264. return r.info
  265. }
  266. on server saveDisplayName(name, session) {
  267. u = userOfSession(session)
  268. if (u == null) { return { error = 'log in with ident first' } }
  269. r = setUserName(u.id, name)
  270. if (r.error != null) { return { error = r.error } }
  271. info = userInfo(r.user)
  272. emit client signedIn(session.data.tag, info)
  273. return info
  274. }
  275. on server myInboxCount(session) {
  276. return { count = inboxCountOf(userOfSession(session)) }
  277. }
  278. on server logOut(session) {
  279. if (session == null) { return { error = 'no session' } }
  280. // the tag stays (the push may fan out after this face returns); the next login replaces it
  281. emit client signedOut(session.data.tag)
  282. session.user = null
  283. return { ok = true }
  284. }

Branches

Latest commits

  • 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
  • 610d8e8aMerge branch 'records-t39' into mainTickets
  • 32bcdf24|||PR records: GO P39 K40mre
  • 4123c6d1Merge branch 'records-t38' into mainTickets
  • cd3641a1|||PR records: day72 deploy live, tickets closedmre
  • 7d44d852Merge branch 'records-t37' into mainTickets
  • 926f7061|||PR records: merges, D36 deploymre
  • bf58534eMerge branch 'l33-final' into mainTickets
  • 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
  • 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
  • 5822cb3aMerge branch 'o34-clean' into mainTickets
  • 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
  • 14cf96b4Merge branch 'records-t36' into mainTickets
  • 07749fa1|||PR records: day72 + #40 mergedmre
  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre