ident
All repositories: gitoria
7.2 KB
// components/main.hl — THE SHELL: the application header and the slot the page renders// into. Its own look is in the Style below; components/styles.hl keeps only what is page-wide.import { navigate } from 'hl:web'import { siteName } from '../project.hl'import { accountOfSession, signOutEverywhere } from '../lib/accounts.hl'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'import ContentFirst from '../theme/shell/content-first.hl'slot = null// OFFLINE (mission 046): true while the shell's probe cannot reach ident (the note under the header says so)noNetwork = false// the main menu marks the current page from the route (hybriel#197, in the server's HTML too): `route = null` is the declaration,// MainMenu reads {path, params, pattern} itself — no `current` is passedroute = nullsession = null// `/start` (start.hl, the page the service worker keeps offline) is this same shell with the account part switched off: it must// never read or ship the account, so `startPage` keeps the session unread and the menu, bell, user menu and avatar.js out of it.startPage = route != null && route.path == '/start'accountPage = !startPageshellEmail = startPage ? '' : accountOfSession(&session) != null ? accountOfSession(&session).email : ''shellIn = shellEmail != ''// the main menu: the header from 60rem, the phone's sidebar below — one list (signed in only: every page needs the account)static menu = [ { label = 'Identities' href = '/' } { label = 'Inbox' href = '/inbox' } { label = 'Apps' href = '/apps' } { label = 'Access' href = '/access' } { label = 'Docs' href = '/docs' } ]Style {// the signed-in address at the top of the user menu'#whoami' {fontSize = '.875rem'}// offline (mission 046): the note under the headerofflineNote {display = 'block'padding = '.5rem var(--layout-gutter)'color = 'var(--color-warning)'background = 'var(--color-background-sunken)'fontSize = '.875rem'fontWeight = '600'}// the network probe's clock (below): a zero-size element whose animation starts the probenetProbe {position = 'absolute'width = '0'height = '0'overflow = 'hidden'animation = 'ident-net-probe 20s .5s infinite'}'@keyframes ident-net-probe' = {'from' = { opacity = '1' }to = { opacity = '0.99' }}inboxBell { display = 'block' flex = 'none'a { display = 'flex' alignItems = 'center' justifyContent = 'center' width = 'var(--layout-tap)' height = 'var(--layout-tap)' color = 'var(--color-text)'hover { color = 'var(--color-accent)' textDecoration = 'none' }svg { width = '1.5rem' height = '1.5rem' }}}}// THE SHELL (mission 012, phone first on the WorldAPI theme): ContentFirst for every page — ident has no list/detail// structure; a sign-in page is just the centred column without a sidebar. Signed in: theme AppHeader (brand · main menu ·// user menu) + the phone's Sidebar (☰ → the main menu). Signed out: the brand only (the page is the sign-in).View {body {AppHeader { brand = siteNameif (shellIn) { MainMenu { items = menu } }// the inbox shortcut of the approved screens (ident#27 mockups showed a coloured bell emoji; he asked for our monochrome icon style):// the same outline as the header's other icons (24 grid, currentColor, 1.8 stroke, round caps)if (shellIn) {inboxBell {a { href = "/inbox" title = "Inbox" 'aria-label' = "Inbox"svg { viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" 'stroke-width' = "1.8" 'stroke-linecap' = "round" 'stroke-linejoin' = "round" 'aria-hidden' = "true"path { d = "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }path { d = "M10.3 21a1.94 1.94 0 0 0 3.4 0" }}}}}if (shellIn) {UserMenu {p { id = "whoami" shellEmail }button { id = "menusignout" type = "button" "Sign out" on click(e) { emit shellSignOut(e) } }button { id = "menusignoutall" type = "button" "Sign out everywhere" on click(e) { emit shellSignOutAll(e) } }}}}if (noNetwork) { offlineNote { id = "offline" "Offline — ident needs the network to sign in and to save" } }// THE NETWORK PROBE: a CSS animation (`ident-net-probe` in the Style above) starts half a second// after the page is up and repeats every 20 s; each start and repeat asks /api/online.// A View has no "mounted" event, and a probe that fired before the page is hydrated// would be lost, so the delayed animation is the trigger. No JavaScript of ours.netProbe { on animationstart(e) { emit probe(e) } on animationiteration(e) { emit probe(e) } }if (shellIn) { Sidebar { desktop = "false" MainMenu { items = menu } } }// `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)main {ContentFirst { slot }}if (accountPage) { script { src = "/avatar.js" } }}}// a page's in-place sign-in (home.hl verify): its emit reaches this shell (hybriel#193), so the user menu follows at once, no reloadon shellSession(email) {shellEmail = emailshellIn = email != ''}// the user menu's Sign out: the session forgets the account, the page reloads into the sign-inon shellSignOut(e) {r = emit server shellSignOutNow()navigate('/')}on server shellSignOutNow(session) {if (session != null) { session.user = null }return true}// the user menu's Sign out everywhere (the home page has no sign-out buttons of its own any more): every device is signed out// (the audience pushes `signedOutAll` to the other open pages), this browser's session too; then the sign-in formon shellSignOutAll(e) {if (!confirm('Sign out of ident on every device?')) { return null }r = emit server shellSignOutAllNow()if (r != null && r.error == null) { navigate('/') }}on server shellSignOutAllNow(session) {me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }emit client signedOutAll(me.id)session.user = nullreturn signOutEverywhere(me.id)}// the probe: no answer (or not ident's 204) = offline; the next repeat clears it again.// On `/start` (the installed app's start page, start.hl) an answer means: go on to `/`.on probe(e) {r = window.__hlAttempt(() => { return fetch('/api/online', { cache = 'no-store' }) })noNetwork = !r.ok || r.value.status != 204if (!noNetwork && route.path == '/start') {// the shell stays mounted when `/start` goes on to `/` (navigate): only now, online, it learns the account — never in `/start`'s own HTMLemail = emit server shellAccountNow()shellEmail = emailshellIn = email != ''startPage = falseaccountPage = truenavigate('/', replace = true)}}on server shellAccountNow(session) {me = accountOfSession(&session)return me != null ? me.email : ''}// "SIGN OUT EVERYWHERE" from another device or tab (home.hl signOutAll): the server pushes// this to every open page of the account (project.hl audience), which reloads into the// signed-out state at once — no click needed.on client signedOutAll(accountId) {// the page that asked for it (the user menu's own sign-out, above) has already left for the sign-in: nothing to reload thereif (shellEmail != '') {shellEmail = ''shellIn = falsenavigate(route.path, replace = true)}}
Branches
Latest commits
- e56d8273|||PR ident#34 part 4: access and inbox fixed classesmre
- df7696dbident#34: tests: access ticks selector quoting fixmre
- 7215903eident#34: access: the unstyled classes all, app, tick, apptick, plus are dropped; the gate finds the app ticks by input[name=app]mre
- 69b0a0ceident#34: access: the pick buttons use Style.pickCard instead of class pickmre
- dc702419Merge branch 'f9-choose' into mainIdent
- 8caec771|||PR ident#34 restore .choose hookmre
- 0dbff960Merge branch 'f8-shared' into mainIdent
- d69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmre
- 3a64dc48ident#34: chipLook: radius as the same var() string (a bare token name in a static does not compile); selector gate selectormre
- eb039073ident#34: tests: signin and migration find the choice without the classmre
- 4b94a594ident#34: tests: fix selector of the identity choicemre
- bebc88e4ident#34: main.hl drops the unstyled classes inboxlink and whomre
- b4e7ad04ident#34: the identity choice link/button has no class (rule on #chooselist a)mre
- 3c33d6eaident#34: the connection link in inbox has no class (rule on #conns a)mre
- dc97ec0dident#34: the Notif. chip and the Used in link share chipLook (Style.pChip) instead of the classes chip/used/notifmre
- 378bd432ident#34: the identity picture look is a static in styles.hl (Style.pAvatar); sizes stay with each listmre
- 1cf79e7eident#34: the wide page column is a static in styles.hl (Style.pWide), not the class "wide"mre
- ddc7d135Merge branch 'f7-hooks' into mainIdent
- eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
- ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre