gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9b94aa6a9b94aa6aMerge branch 'f1b-cleanup' into mainIdent9b94aa6a/components/main.hl

5.8 KB

  1. // components/main.hl — THE SHELL: the application header and the slot the page renders
  2. // into. All CSS is in components/styles.hl.
  3. import { navigate } from 'hl:web'
  4. import { siteName } from '../project.hl'
  5. import { accountOfSession, signOutEverywhere } from '../lib/accounts.hl'
  6. import AppHeader from '../theme/shell/app-header.hl'
  7. import MainMenu from '../theme/shell/main-menu.hl'
  8. import UserMenu from '../theme/shell/user-menu.hl'
  9. import Sidebar from '../theme/shell/app-sidebar.hl'
  10. import ContentFirst from '../theme/shell/content-first.hl'
  11. slot = null
  12. // OFFLINE (mission 046): true while the shell's probe cannot reach ident (the note under the header says so)
  13. noNetwork = false
  14. // the main menu marks the current page from the route (hybriel#197, in the server's HTML too): `route = null` is the declaration,
  15. // MainMenu reads {path, params, pattern} itself — no `current` is passed
  16. route = null
  17. session = null
  18. shellEmail = accountOfSession(&session) != null ? accountOfSession(&session).email : ''
  19. shellIn = shellEmail != ''
  20. // the main menu: the header from 60rem, the phone's sidebar below — one list (signed in only: every page needs the account)
  21. static menu = [ { label = 'Identities' href = '/' } { label = 'Inbox' href = '/inbox' } { label = 'Apps' href = '/apps' } { label = 'Access' href = '/access' } { label = 'Docs' href = '/docs' } ]
  22. Style {
  23. inboxBell { display = 'block' flex = 'none'
  24. a { display = 'flex' alignItems = 'center' justifyContent = 'center' width = 'var(--layout-tap)' height = 'var(--layout-tap)' color = 'var(--color-text)'
  25. hover { color = 'var(--color-accent)' textDecoration = 'none' }
  26. svg { width = '1.5rem' height = '1.5rem' }
  27. }
  28. }
  29. }
  30. // THE SHELL (mission 012, phone first on the WorldAPI theme): ContentFirst for every page — ident has no list/detail
  31. // structure; a sign-in page is just the centred column without a sidebar. Signed in: theme AppHeader (brand · main menu ·
  32. // user menu) + the phone's Sidebar (☰ → the main menu). Signed out: the brand only (the page is the sign-in).
  33. View {
  34. body {
  35. AppHeader { brand = siteName
  36. if (shellIn) { MainMenu { items = menu } }
  37. // the inbox shortcut of the approved screens (ident#27 mockups showed a coloured bell emoji; he asked for our monochrome icon style):
  38. // the same outline as the header's other icons (24 grid, currentColor, 1.8 stroke, round caps)
  39. if (shellIn) {
  40. inboxBell {
  41. a { class = "inboxlink" href = "/inbox" title = "Inbox" 'aria-label' = "Inbox"
  42. svg { viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" 'stroke-width' = "1.8" 'stroke-linecap' = "round" 'stroke-linejoin' = "round" 'aria-hidden' = "true"
  43. path { d = "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }
  44. path { d = "M10.3 21a1.94 1.94 0 0 0 3.4 0" }
  45. }
  46. }
  47. }
  48. }
  49. if (shellIn) {
  50. UserMenu {
  51. p { id = "whoami" class = "who" shellEmail }
  52. button { id = "menusignout" type = "button" "Sign out" on click(e) { emit shellSignOut(e) } }
  53. button { id = "menusignoutall" type = "button" "Sign out everywhere" on click(e) { emit shellSignOutAll(e) } }
  54. }
  55. }
  56. }
  57. if (noNetwork) { offlineNote { id = "offline" "Offline — ident needs the network to sign in and to save" } }
  58. // THE NETWORK PROBE: a CSS animation (components/styles.hl `ident-net-probe`) starts half a second
  59. // after the page is up and repeats every 20 s; each start and repeat asks /api/online.
  60. // A View has no "mounted" event, and a probe that fired before the page is hydrated
  61. // would be lost, so the delayed animation is the trigger. No JavaScript of ours.
  62. netProbe { on animationstart(e) { emit probe(e) } on animationiteration(e) { emit probe(e) } }
  63. if (shellIn) { Sidebar { desktop = "false" MainMenu { items = menu } } }
  64. // `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  65. main {
  66. ContentFirst { slot }
  67. }
  68. script { src = "/avatar.js" }
  69. }
  70. }
  71. // 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 reload
  72. on shellSession(email) {
  73. shellEmail = email
  74. shellIn = email != ''
  75. }
  76. // the user menu's Sign out: the session forgets the account, the page reloads into the sign-in
  77. on shellSignOut(e) {
  78. r = emit server shellSignOutNow()
  79. navigate('/')
  80. }
  81. on server shellSignOutNow(session) {
  82. if (session != null) { session.user = null }
  83. return true
  84. }
  85. // 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
  86. // (the audience pushes `signedOutAll` to the other open pages), this browser's session too; then the sign-in form
  87. on shellSignOutAll(e) {
  88. if (!confirm('Sign out of ident on every device?')) { return null }
  89. r = emit server shellSignOutAllNow()
  90. if (r != null && r.error == null) { navigate('/') }
  91. }
  92. on server shellSignOutAllNow(session) {
  93. me = accountOfSession(&session)
  94. if (me == null) { return { error = 'you are not signed in' } }
  95. emit client signedOutAll(me.id)
  96. session.user = null
  97. return signOutEverywhere(me.id)
  98. }
  99. // the probe: no answer (or not ident's 204) = offline; the next repeat clears it again.
  100. // On `/start` (the installed app's start page, start.hl) an answer means: go on to `/`.
  101. on probe(e) {
  102. r = window.__hlAttempt(() => { return fetch('/api/online', { cache = 'no-store' }) })
  103. noNetwork = !r.ok || r.value.status != 204
  104. if (!noNetwork && route.path == '/start') { navigate('/', replace = true) }
  105. }
  106. // "SIGN OUT EVERYWHERE" from another device or tab (home.hl signOutAll): the server pushes
  107. // this to every open page of the account (project.hl audience), which reloads into the
  108. // signed-out state at once — no click needed.
  109. on client signedOutAll(accountId) {
  110. // the page that asked for it (the user menu's own sign-out, above) has already left for the sign-in: nothing to reload there
  111. if (shellEmail != '') {
  112. shellEmail = ''
  113. shellIn = false
  114. navigate(route.path, replace = true)
  115. }
  116. }

Branches

Latest commits

  • 9b94aa6aMerge branch 'f1b-cleanup' into mainIdent
  • edcfce3f|||PR ident#41 ident#43 ident#44 login error page as a component (same status codes and text, pixel-identical), declarations and route wiring cleaned upmre
  • 3ac85995ident#43 ident#44: plain declarations for never-reassigned lets, one envString helper, named route functions and audience rule out of project.hlmre
  • c7eef14aMerge branch 'nv1-navigate' into mainIdent
  • 644f9775|||PR ident#36 navigate() instead of window.location in the shell, start shell and homemre
  • 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
  • 23971fb7ident#49: media queries in the language's @media formmre
  • 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
  • aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
  • ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
  • dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
  • d277633cident#27: README: identity access and the introspect endpointmre
  • e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
  • 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
  • a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
  • d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
  • ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
  • 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
  • c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
  • 80965c08ident#28: README says the deploy goes through the standbymre