ident
All repositories: gitoria
6.2 KB
// components/inbox.hl — `/inbox`: THE NOTIFICATIONS INBOX (piece 4 of 6, ticket ident#6;// CONCEPT.md "Notifications": "The user reads them in ident's notifications inbox").// Every notification of every identity of the signed-in account, newest first: identity,// app, name, text, icon, action link, time; read / unread (a button per notification).// Below: the apps the account's identities are registered in — each links to its per-app// page (`/inbox/<connection id>`, components/appsettings.hl).//// Faces are named `inbox…` (a face is found by its EVENT NAME across all files).parent './main.hl'import { accountOfSession } from '../lib/accounts.hl'import { inboxRows, markRead, connectionRows } from '../lib/notify.hl'import { unreadCount } from '../lib/notify-helpers.hl'import { siteName } from '../project.hl'import { leadLook, messageLook, wideLook } from './styles.hl'session = nullme = accountOfSession(&session)signedIn = me != nullsignedOut = me == nullmeEmail = me != null ? me.email : ''items = me != null ? inboxRows(me.id) : []hasItems = items.length > 0noItems = items.length == 0unread = unreadCount(items)unreadText = unread == 1 ? '1 unread' : unread + ' unread'conns = me != null ? connectionRows(me.id) : []hasConns = conns.length > 0noConns = conns.length == 0__title = siteName + ' | inbox'message = ''Style {pLead = leadLookpWide = wideLookpMessage = messageLookunreadTotal {color = 'var(--color-accent)'fontSize = '.875rem'fontWeight = '600'}// 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'#inbox' {li {flexWrap = 'nowrap'alignItems = 'flex-start'justifyContent = 'flex-start'gap = '.7rem'}img {flex = '0 0 auto'width = '40px'height = '40px'objectFit = 'cover'borderRadius = 'var(--radius-small)'background = 'var(--color-background-sunken)'}}// the row's state is the notification's own value (class = n.state, 'read' | 'unread'): quoted'#inbox li.read' {opacity = '.75'}noteMain {flex = '1 1 auto'display = 'grid'gap = '.25rem'minWidth = '0'}noteHead {display = 'flex'flexWrap = 'wrap'alignItems = 'baseline'gap = '.2rem .5rem'}noteName {fontWeight = '700'color = 'var(--color-text-strong)'overflowWrap = 'anywhere'}urgentBadge {padding = '0 .5rem'fontSize = '.875rem'fontWeight = '700'color = 'var(--color-accent-text)'background = 'var(--color-danger)'borderRadius = 'var(--radius-small)'}unreadBadge {padding = '0 .5rem'fontSize = '.875rem'fontWeight = '700'color = 'var(--color-accent-text)'background = 'var(--color-accent)'borderRadius = 'var(--radius-small)'}noteFrom {color = 'var(--color-text-muted)'fontSize = '.875rem'overflowWrap = 'anywhere'}noteText {whiteSpace = 'pre-wrap'overflowWrap = 'anywhere'}noteFoot {display = 'flex'flexWrap = 'wrap'alignItems = 'center'gap = '.2rem .8rem'color = 'var(--color-text-muted)'fontSize = '.875rem'a {display = 'inline-flex'alignItems = 'center'minHeight = 'var(--layout-tap)'}button {marginLeft = 'auto'}}'#connsection' {marginTop = '.6rem'}'#conns a.conn' {fontWeight = '700'overflowWrap = 'anywhere'}connDetails {color = 'var(--color-text-muted)'fontSize = '.875rem'overflowWrap = 'anywhere'}}View {identCard { Style.pWideif (signedOut) {h1 { "Inbox" }p { id = "signinfirst" Style.pLead "Sign in to ident first: " a { href = "/" "sign in" } "." }}if (signedIn) {accountBar {userEmail { id = "meemail" meEmail }unreadTotal { id = "unreadcount" unreadText }}section { id = "inboxsection"h1 { "Inbox" }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." } }ul { id = "inbox"for (n of items) {li { class = n.stateif (n.hasIcon) { img { src = n.icon alt = "" width = "40" height = "40" loading = "lazy" referrerpolicy = "no-referrer" } }noteMain {noteHead {noteName { n.name }if (n.urgent) { urgentBadge { "urgent" } }if (n.unread) { unreadBadge { "new" } }}noteFrom { n.app " · " n.identity }noteText { n.text }noteFoot {time { n.time }if (n.hasLink) { a { class = "action" href = n.link target = "_blank" rel = "noopener noreferrer" "Open" } }button { type = "button" class = "quiet small" value = n.id n.toggleText on click(e) { emit toggle(e.target.value) } }}}}}}}section { id = "connsection"h2 { "Notification settings per app" }if (noConns) { p { id = "noconns" Style.pLead "None of your identities is registered in an app yet." } }ul { id = "conns"for (c of conns) {li {a { class = "conn" href = c.href c.app }connDetails { c.identity " · since " c.since }}}}}}p { id = "message" Style.pMessage message }}}rowOf = (id) => {for (n of items) { if ('' + n.id == '' + id) { return n } }return null}setItems = (list) => {items = listhasItems = list.length > 0noItems = list.length == 0let u = 0for (n of list) { if (n.unread) { u = u + 1 } }unread = uunreadText = u == 1 ? '1 unread' : u + ' unread'return null}on toggle(id) {message = ''row = rowOf(id)if (row == null) { return null }r = emit server inboxMark('' + id, !row.read)if (r == null) {message = 'the server did not answer — try again'return null}if (r.error != null) {message = r.errorreturn null}setItems(r.items)}// ---- the faces ------------------------------------------------------------------------// The LAST parameter is the session; accountOfSession only accepts the framework's own// Session (hl:web never takes it from the peer, hybriel#16/#31).on server inboxMark(id, read, session) {let me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }r = markRead(me.id, id, read)if (r.error != null) { return r }return { items = inboxRows(me.id) }}
Branches
Latest commits
- 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
- 1cf79e7eident#34: the wide page column is a static in styles.hl (Style.pWide), not the class "wide"mre
- ddc7d135Merge branch 'f7-hooks' into mainIdent
- 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