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
- 4fb35a0enotes mobile: Delete note and the delete row exactly on the editor's edges; gate asserts 1 pxmre
- 91736270MN report and logmre
- 15667425notes: delete confirmation buttons at most 12rem wide on the desktopmre
- 8f7a6a95gate: MN phone checks (list header gutter, back gap, delete question)mre
- 90c73ed3notes mobile: back link gapmre
- 72bd4f83notes mobile: list header on the gutter, delete confirmation as a question + two equal buttons, Delete note under the editor edgemre
- ba1e73f8notes: a sent edit is done once the server's version is not older, so a second writer's text shows in the first tab; gate: two writers both waysmre
- c69ef9ebsync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
- 2eb783f5sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
- 4dd46dadsync-components: copy icons/icons.hl + README (F4); testsmre
- c92e4a0ftests/e2e-outside.mjs: real-Chrome E2E, a note pushed from another device while open, then typingmre
- 0516b4ccmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
- 38cc11ecmd-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- 3e7e79f5reports/H1-hydrate.mdmre
- d98775e8tests/browser.mjs: wait for hydration before the clicks after a goto('/') (tables new note, phone sidebar)mre
- 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