tickets
All repositories: gitoria
10.5 KB
// components/main.hl — THE SHELL (mission 022, phone first on the WorldAPI theme): the theme's AppHeader (brand · main menu// All tickets / Inbox with its live count · user icon), the phone's Sidebar (☰ → the main menu), the display-name prompt of a// first login, and the slot every page renders into (ContentFirst). Signed in the user icon opens the UserMenu (your name,// Account, Log out); signed out the ident icon opens ident's selector + "Log in with ident" (from 60rem they stand in the// header). The theme's shell files theme/shell/*.hl are never edited here. App CSS is in styles.hl.//// LOGIN (ticket #7, CONCEPT.md "Login via ident"; ident README "How apps use ident"):// * THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js. Choosing an// identity fires `ident-login` with a one-time code. hl:webex cannot listen to a custom DOM// event, so /login.js (plain JS) hands the code to the hidden input #identcode and fires its// `change` — the handler below sends it to the face `identLogin`, which exchanges it SERVER// SIDE and logs this session in. No reload: the face answers who you are and pushes// `signedIn` to this session's tabs (the pages show their forms).// * THE HOST TELLS THE SELECTOR: the element's class is `in` / `out` (a member); /login.js// mirrors it into the selector's `loggedIn` (the `logged-in` attribute). Log out → `out`// → the selector is reset.// * THE LOGIN BUTTON: a plain link to <ident>/login?key=&return=<TICKETS_PUBLIC_URL>/login/callback// (project.hl loginCallback). /login.js adds `?next=<this page>` to the return URL at the// click, so the user comes back to the page the login started from (ticket #10).// * /login.js RUNS AGAIN whenever this View flips between logged in / out (hl:webex// re-creates the header and the <script> elements; ticket #9): it installs itself once// per document and hands each one-time code to #identcode only once.// * FIRST LOGIN: no display name yet → the name prompt below; writing waits for it.import { inboxCountOf } from '../lib/tickets.hl'import { siteName } from '../project.hl'import { identKey, selectorScript, loginHref, infoOfSession, exchangeCode, ensureUser, userInfo, setUserName, userOfSession } from '../lib/users.hl'import { randomBytes } from 'hl:crypto'import AppHeader from '../theme/shell/app-header.hl'import MainMenu from '../theme/shell/main-menu.hl'import UserMenu from '../theme/shell/user-menu.hl'import Sidebar from '../theme/shell/app-sidebar.hl'import ContentFirst from '../theme/shell/content-first.hl'slot = nullsession = null// the inbox is PERSONAL (ticket #20): the tickets assigned to this session's user in pending and reviewinbox = inboxCountOf(userOfSession(session))hasInbox = inbox > 0// the main menu: the header from 60rem, the phone's sidebar below — one list. The Inbox's live count is its badge (`count`)// which menu entry the page belongs to: MainMenu takes it from the route (hybriel#197: `route = null` below, in the server's HTML// 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,// so the shell says '/' for them (All tickets); /inbox marks Inbox by itself; account, settings, new project, connect: none.route = nullpath = route == null ? '' : route.pathmenuSay = path == '/inbox' || path == '/you' || path == '/new-project' || path.startsWith('/connect/') || path.endsWith('/settings') ? '' : '/'menu = [ { label = 'All tickets' href = '/' } { label = 'Inbox' href = '/inbox' count = hasInbox ? inbox : null } ]// who this session is: { name, named, creator } — never the identity idme = infoOfSession(session)loggedIn = me != nullloggedOut = me == nullneedsName = me != null && !me.namedmyName = me != null && me.named ? me.name : 'you'selectorClass = me != null ? 'in' : 'out'selectorKey = identKeyidentScript = selectorScriptbuttonHref = loginHrefloginError = ''hasLoginError = falsenameDraft = ''nameError = ''// OFFLINE (mission 046, as tracker.worldapi.org#10): the service worker opens `/` from its cache without a network;// the shell then says so. hl:web gives a page no connection state and no "mounted" hook, so a tick asks the browser:// `netProbe` runs an endless 1 s CSS animation (styles.hl), and each `animationiteration` reads navigator.onLine — a// write only when it changed. (An `img` error or a socket event would race the hydration and be missed.)offline = falseView {body {AppHeader { brand = siteNameMainMenu { items = menu current = menuSay }if (loggedIn) {UserMenu {p { id = "whoami" class = "who" myName }a { id = "youlink" href = "/you" "Account and tokens" }button { id = "logout" type = "button" "Log out" on click(e) { emit doLogout(e) } }}}// signed out: the ident icon (phone) and its dropdown — from 60rem the dropdown stands open in the header. Signed in it// is hidden (class `in`), the selector element stays: /login.js mirrors its stateidentMenu { class = selectorClassbutton { type = "button" class = "ident-toggle" popovertarget = "ident-panel" title = "Log in with ident" "aria-label" = "Log in with ident"// the ident icon: a small i standing beside a big D lying on the floor; the D's lower face is its thicknesssvg { class = "ident-icon" viewBox = "1 10 20 13.2" "aria-hidden" = "true"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" }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" }rect { class = "ident-i" x = "1.6" y = "14.2" width = "1.9" height = "6.8" rx = ".5" }circle { class = "ident-i" cx = "2.55" cy = "11.6" r = "1.15" }}}identPanel { id = "ident-panel" popover = "auto"identSelector { id = "selector" key = selectorKey class = selectorClass }if (loggedOut) {a { id = "loginbutton" class = "button primary" href = buttonHref "Log in with ident" }}}}}input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }if (hasLoginError) { p { id = "loginerror" class = "message banner" loginError } }if (offline) { offlineNote { id = "offline" "You are offline. The list is the one last loaded here; tickets and changes need the network." } }netProbe { "aria-hidden" = "true" on animationiteration(e) { emit netTick(e) } }if (needsName) {namePrompt {form { id = "nameform"on submit(e) {e.preventDefault()emit saveName(e)}label { "Welcome! Choose the display name others see as the author of what you write"input { id = "displayname" name = "displayname" required = "required" maxlength = "60" value = nameDraft on input(e) { emit setNameDraft(e.target.value) } }}button { id = "namesave" type = "submit" "Save" }p { id = "nameerror" class = "message" nameError }}}}// the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem), then the shell with the// page — `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)Sidebar { desktop = "false" MainMenu { items = menu current = menuSay } }main {ContentFirst { slot }}script { src = identScript }script { src = "/login.js" }// (mission 016: no /md-editor.js any more — the pages use the Hybriel MdEditor, components/md-editor/; the old// custom element would take over its <md-editor> elements)}}// ---- the session as the page sees it ------------------------------------------------------showMe = (info) => {loggedIn = trueloggedOut = falseneedsName = !info.namedmyName = info.named ? info.name : 'you'selectorClass = 'in'loginError = ''hasLoginError = false}showOut = () => {loggedIn = falseloggedOut = trueneedsName = falsemyName = 'you'selectorClass = 'out'inbox = 0hasInbox = false}// the selector's code (via /login.js and the hidden input) → the server exchanges iton gotCode(e) {code = e.target.valuee.target.value = ''if (code == null || code == '') { return null }r = emit server identLogin(code)if (r == null || r.error != null) {loginError = r != null ? r.error : 'the login failed'hasLoginError = truereturn null}showMe(r)emit refreshInbox()}on setNameDraft(v) { nameDraft = v }on netTick(e) {down = window.navigator.onLine == falseif (down != offline) { offline = down }}on saveName(e) {r = emit server saveDisplayName(nameDraft)if (r == null || r.error != null) {nameError = r != null ? r.error : 'could not save the name'return null}nameError = ''showMe(r)}on doLogout(e) {emit server logOut()showOut()}// the inbox is personal: a ticket event asks the server how many tickets are assigned to this session nowon refreshInbox() {r = emit server myInboxCount()if (r != null && r.count != null) {inbox = r.counthasInbox = r.count > 0}}on client ticketCreated(row) { emit refreshInbox() }on client ticketEvent(ticketId, ev, row) { emit refreshInbox() }// this session's other tabs follow a login / name / logouton client signedIn(tag, info) {showMe(info)emit refreshInbox()}on client signedOut(tag) { showOut() }// ---- the faces (#31: hl:web fills `session` itself and refuses a trailing argument, hybriel#16) --on server identLogin(code, session) {if (session == null) { return { error = 'no session — reload the page' } }x = exchangeCode(code)if (x.error != null) { return { error = x.error } }u = ensureUser(x.identity)if (u == null) { return { error = 'could not store the user' } }tag = randomBytes(16)session.user = { id = u.id }session.data.tag = taginfo = userInfo(u)emit client signedIn(tag, info)return info}on server saveDisplayName(name, session) {u = userOfSession(session)if (u == null) { return { error = 'log in with ident first' } }r = setUserName(u.id, name)if (r.error != null) { return { error = r.error } }info = userInfo(r.user)emit client signedIn(session.data.tag, info)return info}on server myInboxCount(session) {return { count = inboxCountOf(userOfSession(session)) }}on server logOut(session) {if (session == null) { return { error = 'no session' } }// the tag stays (the push may fan out after this face returns); the next login replaces itemit client signedOut(session.data.tag)session.user = nullreturn { ok = true }}
Branches
Latest commits
- 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
- 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- f6764bedreports/H1-hydrate.mdmre
- 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre
- 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- e17e2855re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- 81e036b7docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 5d8d2cf6deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- 58e8c02cmission 024: report, LOG, STATUS, e2e fixmre
- 50778073tests/e2e-route-marker.mjs: first paint marker, comments post/edit redrawmre