gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commiteee0b513eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmreeee0b513/components/inbox.hl

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

Branches

Latest commits

  • eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
  • ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
  • 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
  • 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
  • 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
  • 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
  • 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
  • e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
  • 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