gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit866397a0866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre866397a0/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, from the address (a ticket's /<slug>/<n> matches no item's path, so `current` stands on the item).
  40. // The server cannot see the address; the browser sets `menuAt` at the first animation tick (netProbe) — until then none is marked.
  41. // '/' = the lists, projects and tickets (under All tickets), '/inbox'; account, settings, new project, connect: none.
  42. menuAt = ''
  43. menu = [ { label = 'All tickets' href = '/' current = menuAt == '/' } { label = 'Inbox' href = '/inbox' count = hasInbox ? inbox : null current = menuAt == '/inbox' } ]
  44. // who this session is: { name, named, creator } — never the identity id
  45. me = infoOfSession(session)
  46. loggedIn = me != null
  47. loggedOut = me == null
  48. needsName = me != null && !me.named
  49. myName = me != null && me.named ? me.name : 'you'
  50. selectorClass = me != null ? 'in' : 'out'
  51. selectorKey = identKey
  52. identScript = selectorScript
  53. buttonHref = loginHref
  54. loginError = ''
  55. hasLoginError = false
  56. nameDraft = ''
  57. nameError = ''
  58. // OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network;
  59. // the shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:
  60. // `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a
  61. // write only when it changed. (An `img` error or a socket event would race the hydration and be missed.)
  62. offline = false
  63. View {
  64. body {
  65. AppHeader { brand = siteName
  66. MainMenu { items = menu }
  67. if (loggedIn) {
  68. UserMenu {
  69. p { id = "whoami" class = "who" myName }
  70. a { id = "youlink" href = "/you" "Account and tokens" }
  71. button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }
  72. }
  73. }
  74. // signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it
  75. // is hidden (class `in`), the selector element stays: /login.js mirrors its state
  76. identMenu { class = selectorClass
  77. button { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"
  78. // the ident icon: a small i standing beside a big D lying on the floor; the D's lower face is its thickness
  79. svg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"
  80. 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" }
  81. 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" }
  82. rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }
  83. circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }
  84. }
  85. }
  86. identPanel { id = "ident-panel" popover = "auto"
  87. identSelector { id = "selector" key = selectorKey class = selectorClass }
  88. if (loggedOut) {
  89. a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }
  90. }
  91. }
  92. }
  93. }
  94. input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }
  95. if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }
  96. if (offline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }
  97. netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }
  98. if (needsName) {
  99. namePrompt {
  100. form { id = "nameform"
  101. on submit(e) {
  102. e.preventDefault()
  103. emit saveName(e)
  104. }
  105. label { "Welcome! Choose the display name others see as the author of what you write"
  106. input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }
  107. }
  108. button { id = "namesave" type = "submit" "Save" }
  109. p { id = "nameerror" class = "message" nameError }
  110. }
  111. }
  112. }
  113. // the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the
  114. // page — `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  115. Sidebar { desktop = "false" MainMenu { items = menu } }
  116. main {
  117. ContentFirst { slot }
  118. }
  119. script { src = identScript }
  120. script { src = "/login.js" }
  121. // (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old
  122. // custom element would take over its <md-editor> elements)
  123. }
  124. }
  125. // ---- the session as the page sees it ------------------------------------------------------
  126. showMe = (info) => {
  127. loggedIn = true
  128. loggedOut = false
  129. needsName = !info.named
  130. myName = info.named ? info.name : 'you'
  131. selectorClass = 'in'
  132. loginError = ''
  133. hasLoginError = false
  134. }
  135. showOut = () => {
  136. loggedIn = false
  137. loggedOut = true
  138. needsName = false
  139. myName = 'you'
  140. selectorClass = 'out'
  141. inbox = 0
  142. hasInbox = false
  143. }
  144. // the selector's code (via /login.js and the hidden input) → the server exchanges it
  145. on gotCode(e) {
  146. code = e.target.value
  147. e.target.value = ''
  148. if (code == null || code == '') { return null }
  149. r = emit server identLogin(code)
  150. if (r == null || r.error != null) {
  151. loginError = r != null ? r.error : 'the login failed'
  152. hasLoginError = true
  153. return null
  154. }
  155. showMe(r)
  156. emit refreshInbox()
  157. }
  158. on setNameDraft(v) { nameDraft = v }
  159. on netTick(e) {
  160. p = window.location.pathname
  161. at = p == '/inbox' ? '/inbox' : (p == '/you' || p == '/new-project' || p.startsWith('/connect/') || p.endsWith('/settings') ? '' : '/')
  162. if (at != menuAt) { menuAt = at }
  163. down = window.navigator.onLine == false
  164. if (down != offline) { offline = down }
  165. }
  166. on saveName(e) {
  167. r = emit server saveDisplayName(nameDraft)
  168. if (r == null || r.error != null) {
  169. nameError = r != null ? r.error : 'could not save the name'
  170. return null
  171. }
  172. nameError = ''
  173. showMe(r)
  174. }
  175. on doLogout(e) {
  176. emit server logOut()
  177. showOut()
  178. }
  179. // the inbox is personal: a ticket event asks the server how many tickets are assigned to this session now
  180. on refreshInbox() {
  181. r = emit server myInboxCount()
  182. if (r != null && r.count != null) {
  183. inbox = r.count
  184. hasInbox = r.count > 0
  185. }
  186. }
  187. on client ticketCreated(row) { emit refreshInbox() }
  188. on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }
  189. // this session's other tabs follow a login / name / logout
  190. on client signedIn(tag, info) {
  191. showMe(info)
  192. emit refreshInbox()
  193. }
  194. on client signedOut(tag) { showOut() }
  195. // ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --
  196. on server identLogin(code, session) {
  197. if (session == null) { return { error = 'no session — reload the page' } }
  198. x = exchangeCode(code)
  199. if (x.error != null) { return { error = x.error } }
  200. u = ensureUser(x.identity)
  201. if (u == null) { return { error = 'could not store the user' } }
  202. tag = randomBytes(16)
  203. session.user = { id = u.id }
  204. session.data.tag = tag
  205. info = userInfo(u)
  206. emit client signedIn(tag, info)
  207. return info
  208. }
  209. on server saveDisplayName(name, session) {
  210. u = userOfSession(session)
  211. if (u == null) { return { error = 'log in with ident first' } }
  212. r = setUserName(u.id, name)
  213. if (r.error != null) { return { error = r.error } }
  214. info = userInfo(r.user)
  215. emit client signedIn(session.data.tag, info)
  216. return info
  217. }
  218. on server myInboxCount(session) {
  219. return { count = inboxCountOf(userOfSession(session)) }
  220. }
  221. on server logOut(session) {
  222. if (session == null) { return { error = 'no session' } }
  223. // the tag stays (the push may fan out after this face returns); the next login replaces it
  224. emit client signedOut(session.data.tag)
  225. session.user = null
  226. return { ok = true }
  227. }

Branches

Latest commits

  • 866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre
  • 7ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre
  • bf9064a3mission 022: tickets on the layouts theme (step 1): shell, styles, gates, audit, E2E; reportmre
  • f3d61711mission 022 WIP: tickets on the layouts theme (dbe3de7): AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst shell, styles reduced to the app's own, check-theme in the gates, 390 audit + real-Chrome walk scriptmre
  • 31cabfccmission 021: E2E script, report, LOG, STATUSmre
  • 6aea8683editor look: .empty rule only for p.empty, files off where tickets has no upload, state note one line, events test scrolls the editor into view; synced md-editor (components d702d76+6f27ad3); gate 377/0, events 52/0mre
  • dce6ffa6Merge branch 'w28-deflake'mre
  • 536092a1tickets (mission 019): de-flake the m016 comment clicks (B: unliked) — calmClick waits until the button stops moving; test only, no app changemre
  • 9c5fd42amission 020: attachments E2E proof (lisbeth Chrome, real-data copy), reportmre
  • 1206404fREADME attachments, report 018, LOG/STATUSmre
  • 3d9e7f3ctests: m017 gate fixes (list count, waits before delete clicks); gate 373/0mre
  • dd41d5bcre-sync components 15be2ac; mission 018mre
  • 420ad1bbtickets (mission 017 WIP, tickets#27): comment attachments — lib/attachments.hl (storage/attachments, limits, type by content, members-only GET /api/attachments/:id, delete drops, edit keeps), multipart POST …/comments (lib/multipart.hl), Respond block in FilesUpload (blocks verbatim from components w27c 1f8d79d), gate m017 checks written (not yet run); report, LOG, STATUSmre
  • a7a1380dmission brief 017mre
  • f83d9c0dtickets (mission 016): report reports/016-comments-block.md, LOG, STATUS, README gate countmre
  • eef80f55tickets (mission 016): comments through the shared Comments block (layouts#2) — edit (author, earlier versions kept), delete (author, asks; leaves one line in the history), like (members, toggle) on the server (lib/comments.hl, append-only tables), faces + API …/comments/:comment/{edit,delete,like}, push commentChanged; every run of comments is a block in place in the history; Markdown fields on the Hybriel MdEditor (shared/md-editor.js retired: it took over the block's <md-editor>); blocks copied verbatim from components.hybriel 9db927d (tools/sync-components.sh); gates browser 351/0 (old 326/0), events 52/0 (old 52/0)mre
  • eb7aeeb9mission brief 016mre
  • e4c34759paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 26efb23freport w6-events (events test)mre
  • c6bfab04mission 015: re-vendor Hybriel 0f396652 (static build), reportmre