tracker
All repositories: gitoria
3.5 KB
// components/main.hl — THE SHELL: the application header (brand; top right the login: ident's "Log in with// ident" button or Log out) and the slot every page renders into. All CSS is in styles.hl. Copied from// calendar.worldapi.org's components/main.hl unchanged in shape (tracker.worldapi.org#1, rejected once for// centering the sign-in on the page instead of using the header selector).// THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in calendar/gitoria. Choosing an// identity fires `ident-login` (one-time code); /login.js hands it to the hidden input #identcode, whose `change`// goes to the face trackerLogin (server-side exchange, no reload). The element's class is `in` / `out`; /login.js// mirrors it into the selector's `loggedIn`.// LOGIN: a plain link to <ident>/login?key=&return=<public url>/login/callback (project.hl loginCallback).// After a login or logout in this tab the page is fetched again (navigate('/')).import { navigate } from 'hl:web'import { appTitle } from '../project.hl'import { identKey, selectorScript, loginHref, userIdOfSession, exchangeCode, ensureUser } from '../users.hl'import { randomBytes } from 'hl:crypto'slot = nullsession = nullloggedIn = userIdOfSession(session) != nullloggedOut = userIdOfSession(session) == nullbuttonHref = loginHrefselectorClass = loggedIn ? 'in' : 'out'selectorKey = identKeyidentScript = selectorScriptloginError = ''hasLoginError = falseView {body {applicationHeader {a { class = "brand" href = "/" appTitle }userBox { id = "userbox"identSelector { id = "selector" key = selectorKey class = selectorClass }if (loggedIn) {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 } }main { slot }script { src = identScript }script { src = "/login.js" }}}showIn = () => {loggedIn = trueloggedOut = falseselectorClass = 'in'loginError = ''hasLoginError = false}showOut = () => {loggedIn = falseloggedOut = trueselectorClass = 'out'}// the selector's code (via /login.js and the hidden input) → the server exchanges iton gotCode(e) {let code = e.target.valuee.target.value = ''if (code == null || code == '') { return null }let r = emit server trackerLogin(code)if (r == null || r.error != null) {loginError = r != null ? r.error : 'the login failed'hasLoginError = truereturn null}showIn()navigate('/')}on client trackerSignedIn(tag) {showIn()navigate('/')}on client trackerSignedOut(tag) {showOut()navigate('/')}on doLogout(e) {emit server trackerLogOut()showOut()navigate('/')}// ---- the faces (the trailing `session` is always the server's: hybriel #16) ----on server trackerLogin(code, session) {if (session == null) { return { error = 'no session — reload the page' } }let x = exchangeCode(code)if (x.error != null) { return { error = x.error } }let u = ensureUser(x.identity)if (u == null) { return { error = 'could not store the user' } }let tag = randomBytes(16)session.user = { id = u.id }session.data.tag = tagemit client trackerSignedIn(tag)return { ok = true }}on server trackerLogOut(session) {if (session == null) { return { error = 'no session' } }emit client trackerSignedOut(session.data.tag)session.user = nullreturn { ok = true }}
Branches
- mainmain branch
Latest commits
- 44b7d9f9tracker#6: /schedule — upcoming episodes of followed shows, soonest firstmre
- 91c9fc8ctracker#5: /unwatched — unwatched released episodes of followed shows, newest firstmre
- a97c0295tracker#4: show page /shows/:slug (header, seasons, episodes, watch checks) + tools/relink-episode-seasons.hlmre
- 05f407c5tracker: no border on any button except inverted ones (Log out, ident status and identities too); header brand weight 100mre
- 17375427tracker#2: tools/migrate.hl + tools/verify.hl — old MongoDB data into mpackdb with new idsmre
- 31aac936tracker#3: no border on the header and on filled buttons; inverted buttons keep theirsmre
- 2ad9d29ctracker#1: login exactly like calendar (identity selector in the header, empty homepage)mre
- 3691e176tracker#1: empty tracker with the ident login (state of 2026-09-27)mre