gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5b4541fc5b4541fcident#33: the selector sign-in frame's rules move into embed.hl's Stylemre5b4541fc/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

  • 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
  • 2249945cident#33: the inbox and connection list rules move into inbox.hl's Stylemre
  • f2d9f79fident#33: the apps list and the secret box move into apps.hl's Stylemre
  • 8370b748ident#33: the app request box moves into home.hl's Stylemre
  • 40bf3b97ident#33: the 404 page's home link rule moves into notfound.hlmre
  • 40627a89ident#33: the time zone section's spacing moves into timezone.hlmre
  • d389db08ident#33: the identity page's rules and the Notif. chip move into identity.hl's Stylemre
  • ddda0b5bident#33: the identity row's parts move into identitylist.hl's Stylemre
  • 47e516afident#33 ident#34: the identity form's avatar rules move into identityform.hl; the preview and Remove button are hidden with the hidden attribute instead of built class strings (avatarPreviewClass, avatarRemoveClass gone)mre
  • 5cb5cf0eident#33: the code field's look moves into codestep.hl's Stylemre
  • f421cd60ident#33: the shell's own rules (user menu address, offline note, network probe) move into main.hl's Stylemre
  • c512fb96Merge branch 'f4-homesplit' into mainIdent
  • 07d1717c|||PR ident#40 home.hl is split into components, one per area: email step, identity form, identity list, app identity choice, time zone; each moves its faces with it, the email step is shared with embed.hl (#40.3, rest of #40.2)mre
  • 59e8fcc1ident#40.3: the app's identity choice is one component (components/chooseidentity.hl); its face chooseIdentity moves with itmre
  • e23efdfcident#40.3: the identity list is one component (components/identitylist.hl); its delete and face dropIdentity move with itmre
  • e24b59a6ident#40.3: the time zone is one component (components/timezone.hl); its face changeTimeZone moves with itmre
  • 8cbc5717ident#40.3: the email step is one component (components/emailstep.hl) placed by home.hl and embed.hlmre
  • 6fad3bd2Merge branch 'f3-codestep' into mainIdent
  • 51e387f2|||PR ident#40 the code step is one component (components/codestep.hl) placed by home.hl and embed.hl; its verify face, setCode, browserZone and verify call exist once (#40.2)mre