gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3b3e451f3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre3b3e451f/components/main.hl

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

Branches

Latest commits

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