tickets
All repositories: gitoria
7.8 KB
// components/main.hl — THE SHELL: the application header (brand, All tickets, Inbox with// its live count, and TOP RIGHT the login: ident's identity selector + "Log in with ident",// or who you are + Log out), the display-name prompt of a first login, and the slot every// page renders into. All 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'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// 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 {applicationHeader {a { class = "brand" href = "/" siteName }nav {a { id = "navall" href = "/" "All tickets" }a { id = "navinbox" href = "/inbox" "Inbox"if (hasInbox) { inboxBadge { id = "inboxcount" inbox } }}}userBox { id = "userbox"identSelector { id = "selector" key = selectorKey class = selectorClass }if (loggedIn) {a { id = "whoami" href = "/you" myName }button { id = "logout" type = "button" class = "quiet" "Log out" on click(e) { emit doLogout(e) } }}if (loggedOut) {a { id = "loginbutton" class = "button" 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 }}}}main { slot }script { src = identScript }script { src = "/login.js" }// ticket #12: <md-editor> around every Markdown textarea (a page without JS keeps the plain// textarea; the script defines the element once, a re-run by webex is a no-op)script { src = "/md-editor.js" }}}// ---- 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
- mainmain branch
Latest commits
- a75e0279mission 010 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (456 lets → plain declarations; Hybriel refuses a plain declaration inside a loop on its 2nd pass). gate 249/0, connect 60/0, real-data reads identical, a 50-step write sequence (API + faces) identical to the old codemre
- e9d5c618mission 010 (code order) 2/4: one lib/ file per topic — store.hl split into projects / tickets (+ relations) / events / tickets-helpers, util.hl shared helpers (env, storage dir, URLs, sorts, Vienna time), the function routes out of project.hl into lib/api.hl (thin; auth/filters/Accept in api-helpers.hl), invite + member-removal logic out of the faces/routes into invites.hl / tickets.hl; project.hl is the map. /login/callback gets req + the session store by reference. gate 249/0, connect 60/0, real-data reads identicalmre
- 97e269b5mission 010 (code order) 1/4: .hl files out of the root — lib/ (store, users, connections, invites, migrate, markdown, mdview, import = ticketfile, util = localtime, jsoncheck, api-helpers = api), tools/import.hl, components/styles.hl; import paths only. gate 249/0, connect 60/0, real-data reads identicalmre
- 38f9d10ftickets: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gate 249/0, connect 60/0mre
- d3db6139tickets: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 249/0, connect 60/0mre
- bce182e3tickets: Hybriel master 7eea0d32 (#126 memory, #48 lambda copies its argument); migrate.hl lambdas take &logmre
- 4137be0fantcolony#40: mission references point to the moved missionsmre
- 9bfba36aantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
- c7bd2645tickets: Hybriel master 73267707 (#122 fixed); compactNow workaround removed (#110 covered)mre
- 2ab91ee9tickets: gate checks rows appear once (session sync); re-vendor to ff51cf46 stopped on hybriel#122, stays 837fe120mre
- e01c2b1dtickets#24: installable app (manifest, service worker, offline list), own icon; gate waits for the hello's pongmre
- 752fbb7fdeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
- 38bdd5e4deploy.sh: never send .git or .gitignore to Byrodinmre
- f12fa1bcState of 2026-09-27, before the move to gitoriamre