ident
All repositories: gitoria
6.7 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): the note under the header shows while the browser is offline or the server does not answer (View below)// the browser's own state (hybriel #119/#330, W215): __hlOnline follows online/offline, __hlReach is 'connecting' → 'up' | 'down'__hlOnline = true__hlReach = 'connecting'noNetwork = !__hlOnline || __hlReach == 'down'// 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 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'}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" } }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 }}}}// 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 network state is pushed by the browser (online/offline events) and by the framework (socket up/down), no probe: the note shows// while the browser is offline or the server does not answer; it clears when both are back.// On `/start` (the installed app's start page, start.hl) reaching the server means: go on to `/`.on client reachability(Hybrid r) {noNetwork = !__hlOnline || r.reach == 'down'if (r.reach == 'up' && 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
- b2572b34Merge branch 'v59-day59' into mainIdent
- 67cf016d|||PR ident: vendor Hybriel day59mre
- 600c043dMerge branch 'v58-day58' into mainIdent
- 365f8c80|||PR ident: vendor Hybriel day58mre
- 585126e5Merge branch 'f16-setf' into mainIdent
- 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
- a1419d9cMerge branch 'f15-navigate' into mainIdent
- 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
- e36f4516Merge branch 'f14-online' into mainIdent
- 2c5eac91|||PR ident#38 online state without probe timermre
- bf1980f2Merge branch 'v56-day56' into mainIdent
- 62ae0adf|||PR ident: vendor Hybriel day56mre
- 0d18abc4Merge branch 'f13-avatar' into mainIdent
- 2a99730a|||PR ident#37 avatar in hlmre
- fa4ed25bMerge branch 'f11-upsert' into mainIdent
- 8f3d9bc9|||PR ident#42 keyed upsert and removemre
- 675493b1ident#42: editing an identity upserts the one edited row (face editIdentity answers { identity, row }); a create or delete keeps the whole list because the rows' position-dependent parts (default, Delete, Identity n) changemre
- 45e55303ident#42: an app write patches one row: upsert on create, edit and new secret, one-argument remove on delete; the faces answer the changed app (or the deleted id), not the whole listmre
- 991641d4Merge branch 'f10-access' into mainIdent
- e56d8273|||PR ident#34 part 4: access and inbox fixed classesmre