gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit1cf79e7e1cf79e7eident#34: the wide page column is a static in styles.hl (Style.pWide), not the class "wide"mre1cf79e7e/components/main.hl

7.3 KB

  1. // components/main.hl — THE SHELL: the application header and the slot the page renders
  2. // into. Its own look is in the Style below; components/styles.hl keeps only what is page-wide.
  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. // `/start` (start.hl, the page the service worker keeps offline) is this same shell with the account part switched off: it must
  19. // never read or ship the account, so `startPage` keeps the session unread and the menu, bell, user menu and avatar.js out of it.
  20. startPage = route != null && route.path == '/start'
  21. accountPage = !startPage
  22. shellEmail = startPage ? '' : accountOfSession(&session) != null ? accountOfSession(&session).email : ''
  23. shellIn = shellEmail != ''
  24. // the main menu: the header from 60rem, the phone's sidebar below — one list (signed in only: every page needs the account)
  25. static menu = [ { label = 'Identities' href = '/' } { label = 'Inbox' href = '/inbox' } { label = 'Apps' href = '/apps' } { label = 'Access' href = '/access' } { label = 'Docs' href = '/docs' } ]
  26. Style {
  27. // the signed-in address at the top of the user menu
  28. '#whoami' {
  29. fontSize = '.875rem'
  30. }
  31. // offline (mission 046): the note under the header
  32. offlineNote {
  33. display = 'block'
  34. padding = '.5rem var(--layout-gutter)'
  35. color = 'var(--color-warning)'
  36. background = 'var(--color-background-sunken)'
  37. fontSize = '.875rem'
  38. fontWeight = '600'
  39. }
  40. // the network probe's clock (below): a zero-size element whose animation starts the probe
  41. netProbe {
  42. position = 'absolute'
  43. width = '0'
  44. height = '0'
  45. overflow = 'hidden'
  46. animation = 'ident-net-probe 20s .5s infinite'
  47. }
  48. '@keyframes ident-net-probe' = {
  49. 'from' = { opacity = '1' }
  50. to = { opacity = '0.99' }
  51. }
  52. inboxBell { display = 'block' flex = 'none'
  53. a { display = 'flex' alignItems = 'center' justifyContent = 'center' width = 'var(--layout-tap)' height = 'var(--layout-tap)' color = 'var(--color-text)'
  54. hover { color = 'var(--color-accent)' textDecoration = 'none' }
  55. svg { width = '1.5rem' height = '1.5rem' }
  56. }
  57. }
  58. }
  59. // THE SHELL (mission 012, phone first on the WorldAPI theme): ContentFirst for every page — ident has no list/detail
  60. // structure; a sign-in page is just the centred column without a sidebar. Signed in: theme AppHeader (brand · main menu ·
  61. // user menu) + the phone's Sidebar (☰ → the main menu). Signed out: the brand only (the page is the sign-in).
  62. View {
  63. body {
  64. AppHeader { brand = siteName
  65. if (shellIn) { MainMenu { items = menu } }
  66. // the inbox shortcut of the approved screens (ident#27 mockups showed a coloured bell emoji; he asked for our monochrome icon style):
  67. // the same outline as the header's other icons (24 grid, currentColor, 1.8 stroke, round caps)
  68. if (shellIn) {
  69. inboxBell {
  70. a { class = "inboxlink" href = "/inbox" title = "Inbox" 'aria-label' = "Inbox"
  71. svg { viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" 'stroke-width' = "1.8" 'stroke-linecap' = "round" 'stroke-linejoin' = "round" 'aria-hidden' = "true"
  72. path { d = "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }
  73. path { d = "M10.3 21a1.94 1.94 0 0 0 3.4 0" }
  74. }
  75. }
  76. }
  77. }
  78. if (shellIn) {
  79. UserMenu {
  80. p { id = "whoami" class = "who" shellEmail }
  81. button { id = "menusignout" type = "button" "Sign out" on click(e) { emit shellSignOut(e) } }
  82. button { id = "menusignoutall" type = "button" "Sign out everywhere" on click(e) { emit shellSignOutAll(e) } }
  83. }
  84. }
  85. }
  86. if (noNetwork) { offlineNote { id = "offline" "Offline — ident needs the network to sign in and to save" } }
  87. // THE NETWORK PROBE: a CSS animation (`ident-net-probe` in the Style above) starts half a second
  88. // after the page is up and repeats every 20 s; each start and repeat asks /api/online.
  89. // A View has no "mounted" event, and a probe that fired before the page is hydrated
  90. // would be lost, so the delayed animation is the trigger. No JavaScript of ours.
  91. netProbe { on animationstart(e) { emit probe(e) } on animationiteration(e) { emit probe(e) } }
  92. if (shellIn) { Sidebar { desktop = "false" MainMenu { items = menu } } }
  93. // `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  94. main {
  95. ContentFirst { slot }
  96. }
  97. if (accountPage) { script { src = "/avatar.js" } }
  98. }
  99. }
  100. // 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
  101. on shellSession(email) {
  102. shellEmail = email
  103. shellIn = email != ''
  104. }
  105. // the user menu's Sign out: the session forgets the account, the page reloads into the sign-in
  106. on shellSignOut(e) {
  107. r = emit server shellSignOutNow()
  108. navigate('/')
  109. }
  110. on server shellSignOutNow(session) {
  111. if (session != null) { session.user = null }
  112. return true
  113. }
  114. // 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
  115. // (the audience pushes `signedOutAll` to the other open pages), this browser's session too; then the sign-in form
  116. on shellSignOutAll(e) {
  117. if (!confirm('Sign out of ident on every device?')) { return null }
  118. r = emit server shellSignOutAllNow()
  119. if (r != null && r.error == null) { navigate('/') }
  120. }
  121. on server shellSignOutAllNow(session) {
  122. me = accountOfSession(&session)
  123. if (me == null) { return { error = 'you are not signed in' } }
  124. emit client signedOutAll(me.id)
  125. session.user = null
  126. return signOutEverywhere(me.id)
  127. }
  128. // the probe: no answer (or not ident's 204) = offline; the next repeat clears it again.
  129. // On `/start` (the installed app's start page, start.hl) an answer means: go on to `/`.
  130. on probe(e) {
  131. r = window.__hlAttempt(() => { return fetch('/api/online', { cache = 'no-store' }) })
  132. noNetwork = !r.ok || r.value.status != 204
  133. if (!noNetwork && route.path == '/start') {
  134. // the shell stays mounted when `/start` goes on to `/` (navigate): only now, online, it learns the account — never in `/start`'s own HTML
  135. email = emit server shellAccountNow()
  136. shellEmail = email
  137. shellIn = email != ''
  138. startPage = false
  139. accountPage = true
  140. navigate('/', replace = true)
  141. }
  142. }
  143. on server shellAccountNow(session) {
  144. me = accountOfSession(&session)
  145. return me != null ? me.email : ''
  146. }
  147. // "SIGN OUT EVERYWHERE" from another device or tab (home.hl signOutAll): the server pushes
  148. // this to every open page of the account (project.hl audience), which reloads into the
  149. // signed-out state at once — no click needed.
  150. on client signedOutAll(accountId) {
  151. // 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
  152. if (shellEmail != '') {
  153. shellEmail = ''
  154. shellIn = false
  155. navigate(route.path, replace = true)
  156. }
  157. }

Branches

Latest commits

  • 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
  • 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
  • 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
  • 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
  • 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
  • 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
  • e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
  • fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre
  • 9f2ad803ident#34: notification switches: push/email by name=..., locked by aria-disabled, the switch look is the role=switch button (no switch/push/email/locked classes)mre
  • e0f0ddaaident#34: inbox: the Mark read/unread button is styled as the button of its note-foot, the icon is found as the row's img (no toggle/icon classes)mre
  • 16b49756ident#34: unused row classes (choice, usedrow, kind, shortid) droppedmre
  • f9d6fb38ident#34: apps and identity rows: the Edit/New secret/Delete buttons carry name=..., the API key is found by its element; unused row classes (app, identity, shortid) droppedmre
  • b323265aMerge branch 'f5-styles' into mainIdent
  • 9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mre
  • f28333e4ident#33 ident#35: styles.hl keeps only the accent, the page column and the shared patterns; the account bar is written phone first (base rule + one min-width: 60rem block) instead of a max-width overridemre
  • 5b4541fcident#33: the selector sign-in frame's rules move into embed.hl's Stylemre
  • 00235f21ident#33: the per-app notification switches move into appsettings.hl's Stylemre