ident
All repositories: gitoria
6.1 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' {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 { 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 { 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
- 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
- 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