gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfb7111fafb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmrefb7111fa/components/inbox.hl

6.0 KB

  1. // components/inbox.hl — `/inbox`: THE NOTIFICATIONS INBOX (piece 4 of 6, ticket ident#6;
  2. // CONCEPT.md "Notifications": "The user reads them in ident's notifications inbox").
  3. // Every notification of every identity of the signed-in account, newest first: identity,
  4. // app, name, text, icon, action link, time; read / unread (a button per notification).
  5. // Below: the apps the account's identities are registered in — each links to its per-app
  6. // page (`/inbox/<connection id>`, components/appsettings.hl).
  7. //
  8. // Faces are named `inbox…` (a face is found by its EVENT NAME across all files).
  9. parent './main.hl'
  10. import { accountOfSession } from '../lib/accounts.hl'
  11. import { inboxRows, markRead, connectionRows } from '../lib/notify.hl'
  12. import { unreadCount } from '../lib/notify-helpers.hl'
  13. import { siteName } from '../project.hl'
  14. session = null
  15. me = accountOfSession(&session)
  16. signedIn = me != null
  17. signedOut = me == null
  18. meEmail = me != null ? me.email : ''
  19. items = me != null ? inboxRows(me.id) : []
  20. hasItems = items.length > 0
  21. noItems = items.length == 0
  22. unread = unreadCount(items)
  23. unreadText = unread == 1 ? '1 unread' : unread + ' unread'
  24. conns = me != null ? connectionRows(me.id) : []
  25. hasConns = conns.length > 0
  26. noConns = conns.length == 0
  27. __title = siteName + ' | inbox'
  28. message = ''
  29. Style {
  30. unreadTotal {
  31. color = 'var(--color-accent)'
  32. fontSize = '.875rem'
  33. fontWeight = '600'
  34. }
  35. // the rows (the list and its rows are the page-wide pattern in styles.hl); a notification is top-aligned, its icon beside the text
  36. '#inbox' {
  37. li {
  38. flexWrap = 'nowrap'
  39. alignItems = 'flex-start'
  40. justifyContent = 'flex-start'
  41. gap = '.7rem'
  42. }
  43. img {
  44. flex = '0 0 auto'
  45. width = '40px'
  46. height = '40px'
  47. objectFit = 'cover'
  48. borderRadius = 'var(--radius-small)'
  49. background = 'var(--color-background-sunken)'
  50. }
  51. }
  52. // the row's state is the notification's own value (class = n.state, 'read' | 'unread'): quoted
  53. '#inbox li.read' {
  54. opacity = '.75'
  55. }
  56. noteMain {
  57. flex = '1 1 auto'
  58. display = 'grid'
  59. gap = '.25rem'
  60. minWidth = '0'
  61. }
  62. noteHead {
  63. display = 'flex'
  64. flexWrap = 'wrap'
  65. alignItems = 'baseline'
  66. gap = '.2rem .5rem'
  67. }
  68. noteName {
  69. fontWeight = '700'
  70. color = 'var(--color-text-strong)'
  71. overflowWrap = 'anywhere'
  72. }
  73. urgentBadge {
  74. padding = '0 .5rem'
  75. fontSize = '.875rem'
  76. fontWeight = '700'
  77. color = 'var(--color-accent-text)'
  78. background = 'var(--color-danger)'
  79. borderRadius = 'var(--radius-small)'
  80. }
  81. unreadBadge {
  82. padding = '0 .5rem'
  83. fontSize = '.875rem'
  84. fontWeight = '700'
  85. color = 'var(--color-accent-text)'
  86. background = 'var(--color-accent)'
  87. borderRadius = 'var(--radius-small)'
  88. }
  89. noteFrom {
  90. color = 'var(--color-text-muted)'
  91. fontSize = '.875rem'
  92. overflowWrap = 'anywhere'
  93. }
  94. noteText {
  95. whiteSpace = 'pre-wrap'
  96. overflowWrap = 'anywhere'
  97. }
  98. noteFoot {
  99. display = 'flex'
  100. flexWrap = 'wrap'
  101. alignItems = 'center'
  102. gap = '.2rem .8rem'
  103. color = 'var(--color-text-muted)'
  104. fontSize = '.875rem'
  105. a {
  106. display = 'inline-flex'
  107. alignItems = 'center'
  108. minHeight = 'var(--layout-tap)'
  109. }
  110. button {
  111. marginLeft = 'auto'
  112. }
  113. }
  114. '#connsection' {
  115. marginTop = '.6rem'
  116. }
  117. '#conns a.conn' {
  118. fontWeight = '700'
  119. overflowWrap = 'anywhere'
  120. }
  121. connDetails {
  122. color = 'var(--color-text-muted)'
  123. fontSize = '.875rem'
  124. overflowWrap = 'anywhere'
  125. }
  126. }
  127. View {
  128. identCard { class = "wide"
  129. if (signedOut) {
  130. h1 { "Inbox" }
  131. p { id = "signinfirst" class = "lead" "Sign in to ident first: " a { href = "/" "sign in" } "." }
  132. }
  133. if (signedIn) {
  134. accountBar {
  135. userEmail { id = "meemail" meEmail }
  136. unreadTotal { id = "unreadcount" unreadText }
  137. }
  138. section { id = "inboxsection"
  139. h1 { "Inbox" }
  140. if (noItems) { p { id = "noitems" class = "lead" "No notifications yet. Apps you signed in to with ident can send you some; they show up here." } }
  141. ul { id = "inbox"
  142. for (n of items) {
  143. li { class = n.state
  144. if (n.hasIcon) { img { src = n.icon alt = "" width = "40" height = "40" loading = "lazy" referrerpolicy = "no-referrer" } }
  145. noteMain {
  146. noteHead {
  147. noteName { n.name }
  148. if (n.urgent) { urgentBadge { "urgent" } }
  149. if (n.unread) { unreadBadge { "new" } }
  150. }
  151. noteFrom { n.app " · " n.identity }
  152. noteText { n.text }
  153. noteFoot {
  154. time { n.time }
  155. if (n.hasLink) { a { class = "action" href = n.link target = "_blank" rel = "noopener noreferrer" "Open" } }
  156. button { type = "button" class = "quiet small" value = n.id n.toggleText on click(e) { emit toggle(e.target.value) } }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. section { id = "connsection"
  164. h2 { "Notification settings per app" }
  165. if (noConns) { p { id = "noconns" class = "lead" "None of your identities is registered in an app yet." } }
  166. ul { id = "conns"
  167. for (c of conns) {
  168. li {
  169. a { class = "conn" href = c.href c.app }
  170. connDetails { c.identity " · since " c.since }
  171. }
  172. }
  173. }
  174. }
  175. }
  176. p { id = "message" class = "message" message }
  177. }
  178. }
  179. rowOf = (id) => {
  180. for (n of items) { if ('' + n.id == '' + id) { return n } }
  181. return null
  182. }
  183. setItems = (list) => {
  184. items = list
  185. hasItems = list.length > 0
  186. noItems = list.length == 0
  187. let u = 0
  188. for (n of list) { if (n.unread) { u = u + 1 } }
  189. unread = u
  190. unreadText = u == 1 ? '1 unread' : u + ' unread'
  191. return null
  192. }
  193. on toggle(id) {
  194. message = ''
  195. row = rowOf(id)
  196. if (row == null) { return null }
  197. r = emit server inboxMark('' + id, !row.read)
  198. if (r == null) {
  199. message = 'the server did not answer — try again'
  200. return null
  201. }
  202. if (r.error != null) {
  203. message = r.error
  204. return null
  205. }
  206. setItems(r.items)
  207. }
  208. // ---- the faces ------------------------------------------------------------------------
  209. // The LAST parameter is the session; accountOfSession only accepts the framework's own
  210. // Session (hl:web never takes it from the peer, hybriel#16/#31).
  211. on server inboxMark(id, read, session) {
  212. let me = accountOfSession(&session)
  213. if (me == null) { return { error = 'you are not signed in' } }
  214. r = markRead(me.id, id, read)
  215. if (r.error != null) { return r }
  216. return { items = inboxRows(me.id) }
  217. }

Branches

Latest commits

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