gitoria

ident

All repositories: gitoria

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

Branches

Latest commits

  • 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
  • 3c33d6eaident#34: the connection link in inbox has no class (rule on #conns a)mre
  • dc97ec0dident#34: the Notif. chip and the Used in link share chipLook (Style.pChip) instead of the classes chip/used/notifmre
  • 378bd432ident#34: the identity picture look is a static in styles.hl (Style.pAvatar); sizes stay with each listmre