notes
All repositories: gitoria
5.9 KB
// components/main.hl — THE SHELL (mission 011, phone first on the WorldAPI theme): the theme's AppHeader (brand · main menu ·// user icon), the phone's Sidebar (☰ → the main menu) and the slot every page renders into; the page chooses its shell (the// notes page ListFirst, /login/failed and the signed-out hint ContentFirst). The theme's shell files theme/shell/*.hl are never// edited here. Signed in the user icon opens the UserMenu (Log out); signed out the ident icon opens ident's selector + "Log in// with ident" (from 60rem they stand in the header). App CSS is in components/styles.hl.// THE SELECTOR: `<ident-selector key=IDENT_API_KEY>` from <ident>/selector.js, as in 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 notesLogin (server-side exchange, lib/users.hl userOfLoginCode; 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 (lib/api.hl loginCallback).// After a login or logout in this tab the page is fetched again (navigate('/')): the notes of the session show.import { navigate } from 'hl:web'import { siteName } from '../project.hl'import { identKey, selectorScript, loginHref, userIdOfSession, userOfLoginCode } 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'slot = nullsession = nullloggedIn = userIdOfSession(session) != nullloggedOut = userIdOfSession(session) == nullbuttonHref = loginHrefselectorClass = loggedIn ? 'in' : 'out'selectorKey = identKeyidentScript = selectorScriptloginError = ''hasLoginError = false// the main menu: the header from 60rem, the phone's sidebar below — one list (one page so far; the menu is the shell's place for more)// `current = true` STAYS (mission 015, hybriel#197): the menu now marks an item from the route, but only the page '/' itself (an item// with href '/' is not "above" other pages, by design) — on /note/:id and /login/failed the route marks nothing (server HTML checked in// tests/browser.mjs "server html …"; without current = true those two fail), and the one item is the whole appmenu = [ { label = 'Notes' href = '/' current = true } ]View {body {AppHeader { brand = siteNameMainMenu { items = menu }if (loggedIn) {UserMenu {p { id = "whoami" class = "who" "Signed in with ident" }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 } }// the phone's overlay with the main menu (desktop = "false": the header shows the menu from 60rem); the page (its own// shell: list-first for the notes, content-first for the rest) follows — hybriel#130: the page slot starts its own lineSidebar { desktop = "false" MainMenu { items = menu } }slotscript { 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) {code = e.target.valuee.target.value = ''if (code == null || code == '') { return null }r = emit server notesLogin(code)if (r == null || r.error != null) {loginError = r != null ? r.error : 'the login failed'hasLoginError = truereturn null}showIn()navigate('/')}on client notesSignedIn(tag) {showIn()navigate('/')}on client notesSignedOut(tag) {showOut()navigate('/')}on doLogout(e) {emit server notesLogOut()showOut()navigate('/')}// ---- the faces (the trailing `session` is always the server's: hybriel #16) ----on server notesLogin(code, session) {if (session == null) { return { error = 'no session — reload the page' } }x = userOfLoginCode(code)if (x.error != null) { return { error = x.error } }tag = randomBytes(16)session.user = { id = x.user.id }session.data.tag = tagemit client notesSignedIn(tag)return { ok = true }}on server notesLogOut(session) {if (session == null) { return { error = 'no session' } }emit client notesSignedOut(session.data.tag)session.user = nullreturn { ok = true }}
Branches
Latest commits
- 1f3198b6tests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- 39cf9fdfre-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
- db07aa84tests: short-id-switch ports from env (NOTES_SWITCH_IDENT_PORT/_PORT), defaults unchangedmre
- ef9f9feere-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
- 5485467cdocker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 86ea4a85deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- edeab20fnotes mission 015: mission, report, LOG, STATUSmre
- 542a0383notes mission 015: e2e-chrome E2E_HOST (own cookie jar in the shared Chrome)mre
- 8b30f510notes mission 015: main-menu from layouts 0bcc629, current = true kept (route marks only /), server-HTML marker checksmre
- 84b574c4notes mission 015: re-vendor plugins from hybriel f9614007 (incl. web, #117)mre
- 447da53dnotes mission 014: report — remaining gates and lisbeth E2E proofmre
- fd9f92c3notes mission 014: report (partial), LOG, STATUSmre
- b2501360notes mission 014: open() sets asking=false before flush(0) (hybriel#196)mre
- 9414ce59notes mission 014: merge theme 76f99f6, components 3794c59, strict single-press openAsk (fails on old open())mre
- c08c655anotes 013: theme re-copied from layouts 76f99f6 (menu marks the current page), current = true on the menu item, e2e marker checks, reportmre
- 21c8f65dnotes mission 012: STATUSmre
- 0bbb3dd9notes mission 012: delete section of the browser gate de-flaked (openAsk: calm wait, press again when the question closes by itself); report 012mre
- f431bdf8notes mission 011: notes on the layouts theme (ListFirst shell), styles cut, check-theme gate, E2E extended; reportmre
- 1a8603d1notes mission 011 WIP: deploy.sh gate summary also matches check-theme, browser.mjs logout via the user menumre
- dae2e508notes mission 011 WIP: theme dbe3de7, shell on AppHeader/MainMenu/UserMenu/Sidebar + ListFirst, styles cut to the app's own, check-theme gate, e2e auditmre