gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0f6d15920f6d1592Merge branch 'f18b-shell-session' into mainIdent0f6d1592/components/main.hl

6.6 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): the note under the header shows while the browser is offline or the server does not answer (View below)
  13. // the browser's own state (hybriel #119/#330, W215): __hlOnline follows online/offline, __hlReach is 'connecting' → 'up' | 'down'
  14. __hlOnline = true
  15. __hlReach = 'connecting'
  16. noNetwork = !__hlOnline || __hlReach == 'down'
  17. // the main menu marks the current page from the route (hybriel#197, in the server's HTML too): `route = null` is the declaration,
  18. // MainMenu reads {path, params, pattern} itself — no `current` is passed
  19. route = null
  20. session = null
  21. // `/start` (start.hl, the page the service worker keeps offline) is this same shell with the account part switched off: it must
  22. // never read or ship the account, so `startPage` keeps the session unread and the menu, bell, user menu out of it.
  23. startPage = route != null && route.path == '/start'
  24. accountPage = !startPage
  25. // The sign-in face's ack refreshes this shell's session-reading member before its caller continues.
  26. shellEmail = startPage ? '' : accountOfSession(&session) != null ? accountOfSession(&session).email : ''
  27. shellIn = shellEmail != ''
  28. // the main menu: the header from 60rem, the phone's sidebar below — one list (signed in only: every page needs the account)
  29. static menu = [ { label = 'Identities' href = '/' } { label = 'Inbox' href = '/inbox' } { label = 'Apps' href = '/apps' } { label = 'Access' href = '/access' } { label = 'Docs' href = '/docs' } ]
  30. Style {
  31. // the signed-in address at the top of the user menu
  32. '#whoami' {
  33. fontSize = '.875rem'
  34. }
  35. // offline (mission 046): the note under the header
  36. offlineNote {
  37. display = 'block'
  38. padding = '.5rem var(--layout-gutter)'
  39. color = 'var(--color-warning)'
  40. background = 'var(--color-background-sunken)'
  41. fontSize = '.875rem'
  42. fontWeight = '600'
  43. }
  44. inboxBell { display = 'block' flex = 'none'
  45. a { display = 'flex' alignItems = 'center' justifyContent = 'center' width = 'var(--layout-tap)' height = 'var(--layout-tap)' color = 'var(--color-text)'
  46. hover { color = 'var(--color-accent)' textDecoration = 'none' }
  47. svg { width = '1.5rem' height = '1.5rem' }
  48. }
  49. }
  50. }
  51. // THE SHELL (mission 012, phone first on the WorldAPI theme): ContentFirst for every page — ident has no list/detail
  52. // structure; a sign-in page is just the centred column without a sidebar. Signed in: theme AppHeader (brand · main menu ·
  53. // user menu) + the phone's Sidebar (☰ → the main menu). Signed out: the brand only (the page is the sign-in).
  54. View {
  55. body {
  56. AppHeader { brand = siteName
  57. if (shellIn) { MainMenu { items = menu } }
  58. // the inbox shortcut of the approved screens (ident#27 mockups showed a coloured bell emoji; he asked for our monochrome icon style):
  59. // the same outline as the header's other icons (24 grid, currentColor, 1.8 stroke, round caps)
  60. if (shellIn) {
  61. inboxBell {
  62. a { href = "/inbox" title = "Inbox" 'aria-label' = "Inbox"
  63. svg { viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" 'stroke-width' = "1.8" 'stroke-linecap' = "round" 'stroke-linejoin' = "round" 'aria-hidden' = "true"
  64. path { d = "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }
  65. path { d = "M10.3 21a1.94 1.94 0 0 0 3.4 0" }
  66. }
  67. }
  68. }
  69. }
  70. if (shellIn) {
  71. UserMenu {
  72. p { id = "whoami" shellEmail }
  73. button { id = "menusignout" type = "button" "Sign out" on click(e) { emit shellSignOut(e) } }
  74. button { id = "menusignoutall" type = "button" "Sign out everywhere" on click(e) { emit shellSignOutAll(e) } }
  75. }
  76. }
  77. }
  78. if (noNetwork) { offlineNote { id = "offline" "Offline — ident needs the network to sign in and to save" } }
  79. if (shellIn) { Sidebar { desktop = "false" MainMenu { items = menu } } }
  80. // `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)
  81. main {
  82. ContentFirst { slot }
  83. }
  84. }
  85. }
  86. // the user menu's Sign out: the session forgets the account, the page reloads into the sign-in
  87. on shellSignOut(e) {
  88. r = emit server shellSignOutNow()
  89. navigate('/')
  90. }
  91. on server shellSignOutNow(session) {
  92. if (session != null) { session.user = null }
  93. return true
  94. }
  95. // 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
  96. // (the audience pushes `signedOutAll` to the other open pages), this browser's session too; then the sign-in form
  97. on shellSignOutAll(e) {
  98. if (!confirm('Sign out of ident on every device?')) { return null }
  99. r = emit server shellSignOutAllNow()
  100. if (r != null && r.error == null) { navigate('/') }
  101. }
  102. on server shellSignOutAllNow(session) {
  103. me = accountOfSession(&session)
  104. if (me == null) { return { error = 'you are not signed in' } }
  105. emit client signedOutAll(me.id)
  106. session.user = null
  107. return signOutEverywhere(me.id)
  108. }
  109. // the network state is pushed by the browser (online/offline events) and by the framework (socket up/down), no probe: the note shows
  110. // while the browser is offline or the server does not answer; it clears when both are back.
  111. // On `/start` (the installed app's start page, start.hl) reaching the server means: go on to `/`.
  112. on client reachability(Hybrid r) {
  113. noNetwork = !__hlOnline || r.reach == 'down'
  114. if (r.reach == 'up' && route.path == '/start') {
  115. // the shell stays mounted when `/start` goes on to `/` (navigate): only now, online, it learns the account — never in `/start`'s own HTML
  116. email = emit server shellAccountNow()
  117. shellEmail = email
  118. shellIn = email != ''
  119. startPage = false
  120. accountPage = true
  121. navigate('/', replace = true)
  122. }
  123. }
  124. on server shellAccountNow(session) {
  125. me = accountOfSession(&session)
  126. return me != null ? me.email : ''
  127. }
  128. // "SIGN OUT EVERYWHERE" from another device or tab (home.hl signOutAll): the server pushes
  129. // this to every open page of the account (project.hl audience), which reloads into the
  130. // signed-out state at once — no click needed.
  131. on client signedOutAll(accountId) {
  132. // 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
  133. if (shellEmail != '') {
  134. shellEmail = ''
  135. shellIn = false
  136. navigate(route.path, replace = true)
  137. }
  138. }

Branches

Latest commits

  • 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
  • 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
  • 5d1b3fedMerge branch 'v61-day61' into mainIdent
  • 83faeb15|||PR ident: vendor Hybriel day61mre
  • 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