gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0d18abc40d18abc4Merge branch 'f13-avatar' into mainIdent0d18abc4/components/main.hl

7.2 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 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 { 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" 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. }
  98. }
  99. // 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
  100. on shellSession(email) {
  101. shellEmail = email
  102. shellIn = email != ''
  103. }
  104. // the user menu's Sign out: the session forgets the account, the page reloads into the sign-in
  105. on shellSignOut(e) {
  106. r = emit server shellSignOutNow()
  107. navigate('/')
  108. }
  109. on server shellSignOutNow(session) {
  110. if (session != null) { session.user = null }
  111. return true
  112. }
  113. // 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
  114. // (the audience pushes `signedOutAll` to the other open pages), this browser's session too; then the sign-in form
  115. on shellSignOutAll(e) {
  116. if (!confirm('Sign out of ident on every device?')) { return null }
  117. r = emit server shellSignOutAllNow()
  118. if (r != null && r.error == null) { navigate('/') }
  119. }
  120. on server shellSignOutAllNow(session) {
  121. me = accountOfSession(&session)
  122. if (me == null) { return { error = 'you are not signed in' } }
  123. emit client signedOutAll(me.id)
  124. session.user = null
  125. return signOutEverywhere(me.id)
  126. }
  127. // the probe: no answer (or not ident's 204) = offline; the next repeat clears it again.
  128. // On `/start` (the installed app's start page, start.hl) an answer means: go on to `/`.
  129. on probe(e) {
  130. r = window.__hlAttempt(() => { return fetch('/api/online', { cache = 'no-store' }) })
  131. noNetwork = !r.ok || r.value.status != 204
  132. if (!noNetwork && route.path == '/start') {
  133. // the shell stays mounted when `/start` goes on to `/` (navigate): only now, online, it learns the account — never in `/start`'s own HTML
  134. email = emit server shellAccountNow()
  135. shellEmail = email
  136. shellIn = email != ''
  137. startPage = false
  138. accountPage = true
  139. navigate('/', replace = true)
  140. }
  141. }
  142. on server shellAccountNow(session) {
  143. me = accountOfSession(&session)
  144. return me != null ? me.email : ''
  145. }
  146. // "SIGN OUT EVERYWHERE" from another device or tab (home.hl signOutAll): the server pushes
  147. // this to every open page of the account (project.hl audience), which reloads into the
  148. // signed-out state at once — no click needed.
  149. on client signedOutAll(accountId) {
  150. // 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
  151. if (shellEmail != '') {
  152. shellEmail = ''
  153. shellIn = false
  154. navigate(route.path, replace = true)
  155. }
  156. }

Branches

Latest commits

  • 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
  • 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