tickets
All repositories: gitoria
12.9 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 · ident's selector · 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). IDENT'S SELECTOR STANDS IN THE HEADER, visible signed in// 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// 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// 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 { encode } from '../lib/util.hl'import { siteName } from '../project.hl'import { identKey, callbackUrl, selectorScript, 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 Sidebar from '../theme/shell/app-sidebar.hl'import ContentFirst from '../theme/shell/content-first.hl'import { messageLook } from '../lib/looks.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.startsWith('/login/') || 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 = identKey// 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`// (the callback takes it back there). An unknown path (first paint without a route) leaves `next` empty = the start page.selectorReturn = callbackUrl + (path == '' ? '' : '?next=' + encode(path))identScript = selectorScriptloginError = ''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 = falseStyle {pMessage = messageLook + { }// offline (mission 046): the note, and the invisible probe whose animation ticks every secondofflineNote { display = 'block' padding = '.5rem var(--layout-gutter)' color = 'var(--color-text-strong)' background = 'var(--color-surface)' }netProbe { position = 'fixed' left = '0' top = '0' width = '1px' height = '1px' opacity = '0' pointerEvents = 'none' animation = 'tickets-net-tick 1s linear infinite' }'@keyframes tickets-net-tick' = {'from' = { opacity = '0' }to = { opacity = '0' }}// the signed-in name at the top of the user menu (UserMenu's own `p.who` look)'#whoami' { marginRight = '.5rem' fontWeight = '600' color = 'var(--color-text-strong)' fontSize = '.875rem' maxWidth = '6rem' overflow = 'hidden' textOverflow = 'ellipsis' whiteSpace = 'nowrap' flex = '0 1 auto' minWidth = '0' display = 'inline-flex' alignItems = 'center' minHeight = '2.75rem' }'#logout' { flex = 'none' whiteSpace = 'nowrap' padding = '.25rem .5rem' }// ident's selector stands in the header, signed in and signed out, on the phone too (creator 2026-10-24). Its shadow DOM is in// ident's design, restyled to tickets' accent through its custom properties and parts. The pill is kept compact so brand, selector// and the user icon fit one row at 390 px; its dropdown opens under it, as wide as a phone allows.identSelector { '--ident-accent' = 'var(--color-accent)' '--ident-accent-text' = 'var(--color-accent-text)' '--ident-background' = 'var(--color-surface)' '--ident-border' = 'var(--color-surface)' '--ident-font' = '600 .9rem/1.3 system-ui, sans-serif' position = 'relative' flex = '0 1 auto' minWidth = '0' }'ident-selector::part(button)' { minHeight = '2.75rem' padding = '.25rem .6rem' whiteSpace = 'nowrap' }'ident-selector::part(status)' { minHeight = '2.75rem' padding = '.25rem .6rem' whiteSpace = 'nowrap' overflow = 'hidden' textOverflow = 'ellipsis' }'ident-selector::part(identity)' { minHeight = '2.75rem' }'ident-selector::part(panel)' { position = 'absolute' top = '100%' right = '0' zIndex = '30' width = 'min(20rem, calc(100vw - 2 * var(--layout-gutter)))' maxWidth = 'none' boxShadow = '0 .75rem 2rem ' + 'var(--color-background-sunken)' }'#loginerror' { margin = '0' padding = '.5rem var(--layout-gutter)' background = 'var(--color-background-sunken)' }// the display-name prompt of a first login: in the content column, under the headernamePrompt { display = 'block' paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))' paddingTop = '1rem' }'#nameform' { display = 'grid' gap = '.6rem' padding = '1rem' background = 'var(--color-surface)' borderRadius = 'var(--radius-large)' }}View {body {AppHeader { brand = siteNameMainMenu { items = menu current = menuSay }// ident's selector stands in the header, visible signed in AND signed out, on the phone and on the desktop (it shows the// chosen identity once signed in). /login.js mirrors its state from the class (`in` / `out`). Signed out the plain login link// stands beside it.identSelector { id = "selector" key = selectorKey return = selectorReturn class = selectorClass }// signed in, like before the theme missions: your name (it opens Account and tokens) and Log out stand beside the selectorif (loggedIn) {a { id = "whoami" href = "/you" myName }button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }}}input { id = "identcode" type = "hidden" on change(e) { emit gotCode(e) } }if (hasLoginError) { p { id = "loginerror" Style.pMessage class = "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" Style.pMessage 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
- 6372b06dTickets conductor: worker port slotmre
- 836af31cTickets conductor: token pathsmre
- b03f11b6Tickets conductor: CONDUCTOR.md (project part), short STATUS.md, old STATUS to archive/2026-10-31mre
- a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
- cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
- 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
- b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
- f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
- 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
- 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
- d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
- afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
- 48c1ba79tickets: md-paste-files gate with the file manager casesmre
- f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
- 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
- 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
- 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
- 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
- 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
- 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre