@soffits/dsh-notify-inbox 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -3,86 +3,104 @@
3
3
  * unread count), its page, turning Web Push on for this browser, and the
4
4
  * buttons on each notification.
5
5
  *
6
- * Plain JavaScript in DSH's Client module format (no build step); React comes
7
- * from the page's module table. Everything the page shows comes from the
8
- * plugin's /api/notify-inbox routes, which decide per request who is asking.
9
- * A link with ?notify-inbox=<id> opens the page on that notification.
6
+ * Plain JavaScript in DSH's Client module format (no build step). The page is
7
+ * built from DSH's own controls (@deepseek-ai/dsh-client-ui-primitives, from
8
+ * the page's module table), the shared pieces DSH doesn't have from
9
+ * @soffits/dsh-ui-kit (ctx.uiKit) and the buttons from @soffits/dsh-ui-actions
10
+ * (ctx.uiActions); the little CSS of its own is in docs/ui.md, with why.
11
+ * Everything the page shows comes from the plugin's /api/notify-inbox routes,
12
+ * which decide per request who is asking. A link with ?notify-inbox=<id>
13
+ * opens the page on that notification. Counts follow the plugin's events
14
+ * stream (the inbox files' own changes), never a timer.
15
+ *
16
+ * An ask (a notification that waits on the person's answer, or an open ask
17
+ * from their list) shows its points and, when it names the session that
18
+ * asked, a reply box: the reply goes into that session as the person, through
19
+ * the UI actions' `start`, with the ask quoted in.
10
20
  */
11
21
  window.__ModuleLoader__.load({
12
22
  id: '@soffits/dsh-notify-inbox',
13
23
  factory(require) {
14
24
  const React = require('react')
25
+ const { Button, Pill, Menu, Tooltip, StateDot, IconCheckCircleOutlineRegular, IconEllipsisOutlineRegular, IconSendOutlineRegular } = require('@deepseek-ai/dsh-client-ui-primitives')
15
26
  const h = React.createElement
16
27
  const { useState, useEffect, useCallback, useRef, useSyncExternalStore } = React
17
28
 
18
29
  const NS = 'dsh-notify-inbox'
19
30
  const PANEL = 'dsh-notify-inbox'
31
+ const OWNER = '@soffits/dsh-notify-inbox'
20
32
  const LINK_PARAM = 'notify-inbox'
21
33
  const STYLE_ID = 'dsh-notify-inbox-style'
22
34
  const PENDING_MS = 2 * 60 * 1000
35
+ const GROUPS = ['urgent', 'needs-you', 'live', 'handled', 'info']
36
+ /** The colour an item's tile takes from what it needs, unless its domain names one. */
37
+ const GROUP_TONE = { urgent: 'bad', 'needs-you': 'accent', live: 'accent', handled: 'ok', info: 'muted' }
38
+ const GROUP_ICON = { urgent: 'triangle-alert', 'needs-you': 'circle-help', live: 'activity', handled: 'circle-check', info: 'info' }
23
39
  const api = path => new URL(`api/notify-inbox/${path}`, document.baseURI).href
24
40
 
41
+ // Only what DSH's components don't cover: the page frame and row layout mirror DSH's own pages
42
+ // (ui-schedule TaskManagerPage, plugin manager groups), since their CSS modules are private.
25
43
  const CSS = `
26
- .nib-page{width:100%;min-width:0;height:100%;min-height:0;display:flex;flex-direction:column;overflow:hidden;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);font-size:14px;line-height:1.6}
27
- .nib-scroll{flex:1;min-height:0;overflow:auto;scrollbar-gutter:stable}
28
- .nib-content{max-width:820px;margin:0 auto;padding:0 clamp(16px,4vw,48px) 48px}
29
- .nib-head{display:flex;align-items:center;flex-wrap:wrap;gap:8px 12px;padding-top:28px;margin-bottom:16px}
30
- [data-platform=darwin] .nib-head{padding-top:calc(28px + var(--dsh-frame-top-clearance,0px))}
31
- .nib-head h1{margin:0;font-size:20px;font-weight:500;line-height:28px;flex:1 0 auto;max-width:100%}
32
- .nib-count{color:var(--dsw-alias-label-tertiary);font-size:13px;margin-left:8px;font-weight:400}
33
- .nib-tabs{display:inline-flex;gap:2px;padding:2px;border-radius:10px;background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-interactive-bg-hover))}
34
- .nib-tab{border:none;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:13px;padding:2px 12px;border-radius:8px;cursor:pointer}
35
- .nib-tab[aria-pressed=true]{background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);box-shadow:0 0 0 .5px var(--dsw-alias-border-l3)}
36
- .nib-btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:4px;height:28px;padding:0 10px;border:none;border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;line-height:18px;cursor:pointer;box-shadow:inset 0 0 0 var(--dsh-hairline-width,.5px) var(--dsh-button-outline-color,var(--dsw-alias-border-l3));text-decoration:none;white-space:nowrap}
37
- .nib-btn:disabled{cursor:not-allowed;opacity:.4}
38
- @media (hover:hover){.nib-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}.nib-item:hover{background:var(--dsw-alias-interactive-bg-hover)}}
39
- .nib-primary{background:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-label-on-color,#fff);box-shadow:none}
40
- .nib-push{display:flex;align-items:center;flex-wrap:wrap;gap:8px;padding:10px 12px;margin-bottom:16px;border-radius:12px;box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l3);color:var(--dsw-alias-label-secondary);font-size:13px}
41
- .nib-push strong{font-weight:500;color:var(--dsw-alias-label-primary)}
42
- .nib-push .nib-grow{flex:1;min-width:120px}
43
- .nib-hint{width:100%;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
44
+ .nib-page{display:flex;flex-direction:column;width:100%;height:100%;min-width:0;min-height:0;overflow:hidden;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);font-size:14px;line-height:1.6}
45
+ .nib-page :focus-visible{outline:2px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
46
+ .nib-scroll{flex:1;min-height:0;overflow:auto;scrollbar-gutter:stable;--dsh-scrollbar-width:9px;--dsh-scrollbar-thumb-border:2px}
47
+ .nib-content{max-width:960px;margin:0 auto;padding:0 clamp(24px,4vw,48px) 48px}
48
+ .nib-heading{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px 16px;padding-top:28px;margin-bottom:4px}
49
+ [data-platform=darwin] .nib-heading{padding-top:calc(28px + var(--dsh-frame-top-clearance,0px))}
50
+ .nib-heading h1{flex:0 1 auto;min-width:0;margin:0;font-size:20px;line-height:28px;font-weight:500}
51
+ .nib-tools{display:flex;align-items:center;gap:8px}
52
+ .nib-said{margin:0;font-size:15px;line-height:24px;overflow-wrap:anywhere}
53
+ .nib-status{display:flex;flex-wrap:wrap;align-items:center;gap:0 16px;min-width:0;margin:2px 0 16px;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:21px}
54
+ .nib-counts>*+*::before{content:'·';padding:0 6px}
55
+ .nib-counts b{font-weight:500;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
56
+ .nib-counts b[data-group=needs-you]{color:var(--dsw-alias-state-business-primary)}
57
+ .nib-counts b[data-group=urgent]{color:var(--dsw-alias-state-error-primary)}
58
+ .nib-filters{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:20px}
59
+ .nib-n{font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-tertiary)}
60
+ .nib-group{display:flex;flex-direction:column;gap:4px;margin-bottom:24px}
61
+ .nib-groupHead{display:flex;align-items:baseline;gap:8px;padding:0 8px}
62
+ .nib-groupHead h2{margin:0;font-size:14px;line-height:22px;font-weight:500}
44
63
  .nib-list{display:flex;flex-direction:column;gap:2px;margin:0;padding:0;list-style:none}
45
- .nib-item{border-radius:12px;padding:10px 12px;position:relative}
46
- .nib-item.nib-open{background:var(--dsw-alias-bg-layer-1,var(--dsw-alias-interactive-bg-hover))}
47
- .nib-line{display:flex;align-items:flex-start;gap:4px}
48
- .nib-mark{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;margin:-3px -6px -3px 0;border:none;border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}
49
- @media (hover:hover){.nib-mark:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}}
50
- .nib-row{display:flex;gap:10px;align-items:flex-start;width:100%;border:none;background:transparent;color:inherit;font:inherit;text-align:left;padding:0;cursor:pointer}
51
- .nib-dot{flex:none;width:8px;height:8px;border-radius:50%;margin-top:8px;background:transparent}
52
- .nib-unread .nib-dot{background:var(--dsw-alias-state-business-primary)}
53
- .nib-unread.nib-urgent .nib-dot{background:var(--dsw-alias-state-error-primary)}
64
+ .nib-item{border-radius:12px;padding:8px}
65
+ .nib-item.nib-open{background:var(--dsw-alias-bg-layer-1)}
66
+ @media (hover:hover){.nib-item:not(.nib-open):hover{background:var(--dsw-alias-interactive-bg-hover)}}
67
+ .nib-line{display:flex;gap:12px;align-items:flex-start}
54
68
  .nib-main{flex:1;min-width:0}
55
- .nib-titleLine{display:flex;align-items:baseline;gap:8px;min-width:0}
56
- .nib-title{flex:1;min-width:0;font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-secondary)}
57
- .nib-unread .nib-title{font-weight:600;color:var(--dsw-alias-label-primary)}
58
- .nib-open .nib-title{white-space:normal;overflow-wrap:anywhere}
59
- .nib-time{flex:none;color:var(--dsw-alias-label-caption);font-size:12px}
60
- .nib-spoken{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:20px;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow-wrap:anywhere}
61
- .nib-chip{display:inline-block;flex:none;padding:0 6px;border-radius:6px;font-size:11px;line-height:18px;font-weight:500;color:var(--dsw-alias-state-error-primary);box-shadow:inset 0 0 0 .5px currentColor}
62
- .nib-chip.nib-muted{color:var(--dsw-alias-label-tertiary);font-weight:400;max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
63
- .nib-body{margin:8px 0 0 18px;display:flex;flex-direction:column;gap:10px}
64
- .nib-text{white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px;line-height:22px}
69
+ .nib-head{display:block;width:100%;padding:0;border:0;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer}
70
+ .nib-titleLine{display:flex;align-items:flex-start;gap:8px;min-width:0;padding-top:4px}
71
+ .nib-titleLine>.uk-newDot{margin-top:8px}
72
+ .nib-title{flex:1;min-width:0;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;line-height:23px;overflow-wrap:anywhere;color:var(--dsw-alias-label-secondary)}
73
+ .nib-unread .nib-title,.nib-group[data-group=urgent] .nib-title,.nib-group[data-group=needs-you] .nib-title,.nib-group[data-group=live] .nib-title{font-weight:500;color:var(--dsw-alias-label-primary)}
74
+ .nib-points{flex:none;align-self:center;padding:0 6px;border-radius:9px;font-size:12px;line-height:18px;font-weight:500;font-variant-numeric:tabular-nums;color:var(--dsw-alias-state-business-primary);background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 12%,transparent)}
75
+ .nib-reply{display:flex;flex-direction:column;gap:6px;max-width:640px}
76
+ .nib-reply textarea{box-sizing:border-box;width:100%;min-height:64px;padding:8px 10px;border:1px solid var(--dsw-alias-border-primary,var(--dsw-alias-label-quaternary));border-radius:10px;background:var(--dsw-alias-bg-base);color:inherit;font:inherit;resize:vertical}
77
+ .nib-replyBar{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
78
+ .nib-open .nib-title{-webkit-line-clamp:unset}
79
+ .nib-when{flex:none;display:inline-flex;align-items:center;gap:6px;font-size:12px;line-height:23px;color:var(--dsw-alias-label-caption)}
80
+ .nib-sub{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-size:13px;line-height:21px;color:var(--dsw-alias-label-tertiary);overflow-wrap:anywhere}
81
+ .nib-done{display:flex;gap:6px;align-items:flex-start;font-size:13px;line-height:21px;color:var(--dsw-alias-label-tertiary);overflow-wrap:anywhere}
82
+ .nib-done svg{flex:none;margin-top:3px;color:var(--dsw-alias-state-success-primary)}
83
+ .nib-progress{margin-top:8px;max-width:560px}
84
+ .nib-body{display:flex;flex-direction:column;gap:12px;margin-top:10px}
85
+ .nib-text{white-space:pre-wrap;overflow-wrap:anywhere;line-height:22px}
65
86
  .nib-links{display:flex;flex-direction:column;gap:2px;font-size:13px}
66
- .nib-links a{color:var(--dsw-alias-state-business-primary);overflow-wrap:anywhere}
67
- .nib-meta{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
68
- .nib-route{display:inline-flex;gap:3px;margin-right:10px}
87
+ .nib-links a{color:var(--dsw-alias-link,var(--dsw-alias-state-business-primary));overflow-wrap:anywhere}
88
+ .nib-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
89
+ .nib-meta{font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
69
90
  .nib-ok{color:var(--dsw-alias-state-success-primary)}
70
91
  .nib-bad{color:var(--dsw-alias-state-error-primary)}
71
- .nib-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
72
- .nib-actions .nib-btn{height:32px;padding:0 12px}
73
- .nib-status{color:var(--dsw-alias-label-tertiary);font-size:12px}
74
- .nib-empty{color:var(--dsw-alias-label-tertiary);padding:24px 12px}
75
- .nib-error{color:var(--dsw-alias-state-error-primary);padding:12px}
76
- .nib-more{margin:12px auto 0;display:flex}
77
- .nib-icon{position:relative;display:inline-flex}
92
+ .nib-empty{padding:48px 20px;text-align:center;color:var(--dsw-alias-label-tertiary)}
93
+ .nib-error{color:var(--dsw-alias-state-error-primary)}
94
+ .nib-more{display:flex;justify-content:center}
78
95
  .nib-badge{position:absolute;top:-5px;right:-8px;min-width:14px;height:14px;padding:0 3px;box-sizing:border-box;border-radius:7px;background:var(--dsw-alias-state-error-primary);color:#fff;font-size:9px;font-weight:600;line-height:14px;text-align:center;pointer-events:none}
79
- @media (width<=640px),(pointer:coarse){.nib-btn,.nib-tab,.nib-page .ua-btn{min-height:40px;min-width:40px}.nib-mark{width:40px;height:40px;margin:-10px -8px -10px 0}.nib-tab{padding-inline:14px}.nib-tabs{border-radius:12px}}
80
- @media (width<=640px){.nib-content{padding-inline:12px}.nib-head{padding-top:16px}.nib-body{margin-left:0}.nib-item{padding:10px 8px}}
96
+ .nib-bell{position:relative;display:inline-flex}
97
+ @media (width<=640px){.nib-content{padding-inline:12px}.nib-heading{padding-top:16px}.nib-item{padding:8px 6px}.nib-line{gap:10px}}
98
+ @media (width<=640px),(pointer:coarse){.nib-page button,.nib-page .ua-btn,.nib-page .ua-step{min-height:40px}.nib-page .nib-tools button,.nib-page .nib-mark{min-width:40px}.nib-filters button{padding-inline:14px}.nib-head{min-height:40px}}
81
99
  `
82
100
 
83
- // ---- shared state: the unread count and a version that bumps when anything changes ----
101
+ // ---- shared state: the counts and a version that bumps when anything changes ----
84
102
 
85
- const shared = { unread: 0, version: 0, pollSeconds: 30, linked: null, ui: null }
103
+ const shared = { unread: 0, version: 0, linked: null, ui: null, kit: null, summary: null, openSession: () => {} }
86
104
  const listeners = new Set()
87
105
  const emit = () => { for (const listener of listeners) listener() }
88
106
  const subscribe = listener => { listeners.add(listener); return () => listeners.delete(listener) }
@@ -102,129 +120,156 @@ window.__ModuleLoader__.load({
102
120
  async function refreshSummary() {
103
121
  try {
104
122
  const summary = await call('summary')
105
- shared.pollSeconds = summary.pollSeconds || 30
106
- const key = `${summary.unread}|${summary.latest}|${summary.total}|${summary.handled}`
123
+ const key = JSON.stringify([summary.unread, summary.latest, summary.total, summary.groups, summary.line])
107
124
  if (key !== lastSummary) {
108
125
  lastSummary = key
109
126
  shared.unread = summary.unread
127
+ shared.summary = summary
110
128
  shared.version += 1
111
129
  emit()
112
130
  }
113
131
  } catch {
114
- // Signed out or DSH restarting; try again at the next tick.
132
+ // Signed out or DSH restarting; the stream's next notice (or the page coming back) tries again.
115
133
  }
116
134
  }
117
135
  const changed = () => { lastSummary = ''; refreshSummary() }
118
136
 
119
- // ---- time ----
120
-
121
- function relative(iso, t) {
122
- const seconds = (Date.parse(iso) - Date.now()) / 1000
123
- const format = new Intl.RelativeTimeFormat(t('time.locale'), { numeric: 'auto', style: 'short' })
124
- const abs = Math.abs(seconds)
125
- if (abs < 60) return format.format(Math.round(seconds), 'second')
126
- if (abs < 3600) return format.format(Math.round(seconds / 60), 'minute')
127
- if (abs < 86400) return format.format(Math.round(seconds / 3600), 'hour')
128
- if (abs < 86400 * 7) return format.format(Math.round(seconds / 86400), 'day')
129
- return new Date(iso).toLocaleDateString(t('time.locale'), { month: 'short', day: 'numeric' })
130
- }
131
137
  const absolute = (iso, t) => new Date(iso).toLocaleString(t('time.locale'), { dateStyle: 'medium', timeStyle: 'short' })
138
+ /** Text a person reads: a string, or a map from language tag to text. */
139
+ const said = (value, t) => (typeof value === 'string' ? value : value?.[t('time.locale').split('-')[0]] ?? Object.values(value ?? {})[0] ?? '')
132
140
 
133
- /** What happened to this item's latest press, in words, or null. */
134
- function pressStatus(item, t) {
135
- const press = item.presses[item.presses.length - 1]
136
- if (press === undefined) return null
137
- if (press.action === 'step') return t('press.started')
138
- const handled = item.handled.find(row => row.press === press.press)
139
- if (handled !== undefined) {
140
- if (handled.result === 'snoozed' && handled.until) return t('press.snoozed', { time: absolute(handled.until, t) })
141
- if (handled.result === 'done') return t('press.done')
142
- return handled.result
143
- }
144
- return Date.now() - Date.parse(press.at) < PENDING_MS ? t('press.pending') : t('press.unhandled')
145
- }
146
-
147
- // ---- the buttons: @soffits/dsh-ui-actions (ctx.uiActions), shared with other plugin pages ----
148
-
149
- const OWNER = '@soffits/dsh-notify-inbox'
141
+ // ---- the buttons ----
150
142
 
151
143
  /** The server's view of each button's last press: pending, done or unhandled. */
152
144
  function pressStates(item) {
153
145
  const states = {}
154
146
  for (const press of item.presses) {
155
147
  const action = item.actions.find(row => row.id === press.id) ?? item.actions.find(row => row.kind === press.action) ?? { id: press.action }
156
- const handled = item.handled.some(row => row.press === press.press)
148
+ const handled = item.outcomes.some(row => row.press === press.press)
157
149
  states[action.id] = handled ? 'done' : Date.now() - Date.parse(press.at) < PENDING_MS ? 'pending' : 'unhandled'
158
150
  }
159
151
  return states
160
152
  }
161
153
 
162
- function Actions({ item, t, ui, onMark }) {
163
- const markUnread = item.read && h('button', { type: 'button', className: 'nib-btn', onClick: () => onMark(item, false) }, t('markUnread'))
164
- if (ui === null) return markUnread ? h('div', { className: 'nib-actions' }, markUnread) : null
165
- // What "Ask" attaches to the conversation: the notification as a card, its ids for the agent.
166
- const about = {
167
- source: OWNER,
168
- title: item.title || item.spoken || item.text,
169
- lines: [item.title && item.spoken !== item.title ? item.spoken : '', ...(item.text || '').split('\n'), ...item.links].filter(line => line && line !== item.title),
170
- context: { notification: item.id, time: item.time, lane: item.lane, domain: item.domain || undefined },
171
- }
172
- const onPress = async (action, extra) => {
173
- await call('action', { record: item.id, action: action.id, ...(extra?.until ? { until: extra.until } : {}) })
174
- changed()
154
+ /** What happened to the latest press, in words, or null. */
155
+ function pressStatus(item, t) {
156
+ const press = item.presses[item.presses.length - 1]
157
+ if (press === undefined || press.action === 'step') return null
158
+ const outcome = item.outcomes.find(row => row.press === press.press)
159
+ if (outcome !== undefined) {
160
+ if (outcome.result === 'snoozed' && outcome.until) return t('press.snoozed', { time: absolute(outcome.until, t) })
161
+ if (outcome.result === 'done') return t('press.done')
162
+ return outcome.result
175
163
  }
176
- const status = pressStatus(item, t)
177
- return h('div', { className: 'nib-actions' }, h(ui.ActionBar, { actions: item.actions, states: pressStates(item), about, defaultChat: true, onPress },
178
- markUnread,
179
- status && h('span', { className: 'nib-status' }, status)))
164
+ return Date.now() - Date.parse(press.at) < PENDING_MS ? t('press.pending') : t('press.unhandled')
180
165
  }
181
166
 
182
- // ---- one notification ----
183
-
184
- function MarkUnreadIcon() {
185
- return h('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, focusable: 'false' },
186
- h('path', { d: 'M9.5 3.5H3A1.5 1.5 0 0 0 1.5 5v6.5A1.5 1.5 0 0 0 3 13h9a1.5 1.5 0 0 0 1.5-1.5V8' }),
187
- h('path', { d: 'M1.8 4.6 7.5 8.6l2.3-1.6' }),
188
- h('circle', { cx: 12.5, cy: 3.5, r: 2, fill: 'currentColor', stroke: 'none' }))
167
+ /** What "Ask" and a step attach to the conversation: the notification as a card. */
168
+ const aboutOf = item => ({
169
+ source: OWNER,
170
+ title: item.title || item.spoken || item.text,
171
+ lines: [item.title && item.spoken !== item.title ? item.spoken : '', ...(item.text || '').split('\n'), ...item.links].filter(line => line && line !== item.title),
172
+ context: { notification: item.id, time: item.time, lane: item.lane, domain: item.domain || undefined, thread: item.thread || undefined, ask: item.ask?.id },
173
+ })
174
+
175
+ /** A reply to an ask, sent into the session that asked as the person, with the ask quoted in. */
176
+ function Reply({ item, ui, t, onSent }) {
177
+ const [text, setText] = useState('')
178
+ const [state, setState] = useState({ phase: 'idle' })
179
+ const send = async () => {
180
+ const words = text.trim()
181
+ if (words === '' || state.phase === 'sending') return
182
+ setState({ phase: 'sending' })
183
+ try {
184
+ const session = await ui.start(aboutOf(item), { instruction: words, session: item.session })
185
+ setText('')
186
+ setState({ phase: 'sent', session })
187
+ onSent()
188
+ } catch (reason) {
189
+ setState({ phase: 'failed', message: reason.message })
190
+ }
191
+ }
192
+ return h('div', { className: 'nib-reply' },
193
+ h('textarea', {
194
+ value: text,
195
+ rows: 2,
196
+ placeholder: t('reply.placeholder'),
197
+ 'aria-label': t('reply.label'),
198
+ onChange: event => setText(event.target.value),
199
+ onKeyDown: event => { if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) send() },
200
+ }),
201
+ h('div', { className: 'nib-replyBar' },
202
+ h(Button, { variant: 'outline', size: 'sm', disabled: text.trim() === '' || state.phase === 'sending', onClick: send },
203
+ h(IconSendOutlineRegular, null), ' ', t(state.phase === 'sending' ? 'reply.sending' : 'reply.send')),
204
+ state.phase === 'sent' && h('span', { className: 'nib-meta' }, t('reply.sent'), ' ',
205
+ h(Button, { variant: 'outline', size: 'sm', onClick: () => shared.openSession(state.session) }, t('reply.open'))),
206
+ state.phase === 'failed' && h('span', { className: 'nib-meta nib-bad', role: 'alert' }, t('reply.failed', { message: state.message }))))
189
207
  }
190
208
 
191
- function Item({ item, t, open, onToggle, onMark, ui }) {
192
- const urgent = item.lane === 'interrupt'
193
- const className = ['nib-item', item.read ? '' : 'nib-unread', urgent ? 'nib-urgent' : '', open ? 'nib-open' : ''].filter(Boolean).join(' ')
209
+ // ---- one item ----
210
+
211
+ function Item({ item, group, kit, ui, t, domains, open, onToggle, onMark }) {
212
+ const wash = kit.useWash(item.id, item.key)
213
+ const domain = domains[item.domain] ?? {}
214
+ const tone = domain.tone ?? GROUP_TONE[group]
194
215
  const title = item.title || item.spoken || item.text.slice(0, 80)
195
216
  const sub = item.spoken && item.spoken !== title ? item.spoken : item.text !== title ? item.text : ''
196
- return h('li', { className, id: `nib-${item.id}` },
217
+ const doneText = item.handled?.text ?? (item.moved === 'done' ? t('moved.done') : item.moved === 'closed' ? t('moved.closed') : null)
218
+ const status = item.moved === 'snoozed' ? pressStatus(item, t) : item.moved === 'ended' ? t('moved.ended') : null
219
+ const history = !item.liveNow && item.history.length > 0 && item.history.map(row => ({ at: row.time, text: said(row.spoken, t) || said(row.title, t) }))
220
+ const onPress = async (action, extra) => {
221
+ await call('action', { record: item.id, action: action.id, ...(extra?.until ? { until: extra.until } : {}) })
222
+ changed()
223
+ }
224
+ const className = ['nib-item', item.read ? '' : 'nib-unread', open ? 'nib-open' : '', wash].filter(Boolean).join(' ')
225
+ return h('li', { className, id: `nib-${item.key}` },
197
226
  h('div', { className: 'nib-line' },
198
- h('button', { type: 'button', className: 'nib-row', 'aria-expanded': open, onClick: () => onToggle(item) },
199
- h('span', { className: 'nib-dot', 'aria-hidden': true }),
200
- h('span', { className: 'nib-main' },
201
- h('span', { className: 'nib-titleLine' },
202
- urgent && h('span', { className: 'nib-chip' }, t('urgent')),
203
- item.test && h('span', { className: 'nib-chip nib-muted' }, t('test')),
204
- h('span', { className: 'nib-title' }, title),
205
- !open && item.presses.length > 0 && h('span', { className: 'nib-chip nib-muted' }, pressStatus(item, t)),
206
- h('span', { className: 'nib-time', title: absolute(item.time, t) }, relative(item.time, t))),
207
- !open && sub && h('span', { className: 'nib-spoken' }, sub))),
208
- item.read && !open && h('button', { type: 'button', className: 'nib-mark', title: t('markUnread'), 'aria-label': t('markUnread'), onClick: () => onMark(item, false) }, h(MarkUnreadIcon))),
209
- open && h('div', { className: 'nib-body' },
210
- item.text && item.text !== title && h('div', { className: 'nib-text' }, item.text),
211
- item.links.length > 0 && h('div', { className: 'nib-links' },
212
- item.links.map(link => h('a', { key: link, href: link, target: '_blank', rel: 'noopener noreferrer' }, link))),
213
- item.files.length > 0 && h('div', { className: 'nib-links' },
214
- h('span', { className: 'nib-meta' }, t('files')),
215
- item.files.map(file => file.stored
216
- ? h('a', { key: file.name, href: api(`file?id=${encodeURIComponent(item.id)}&name=${encodeURIComponent(file.name)}`), target: '_blank', rel: 'noopener' }, file.name)
217
- : h('span', { key: file.name, className: 'nib-meta' }, `${file.name} (${t('notStored', { reason: file.reason || '?' })})`))),
218
- h(Actions, { item, t, ui, onMark }),
219
- h('div', { className: 'nib-meta' },
220
- item.routed.length === 0 ? t('notSent') : h(React.Fragment, null, `${t('alsoSent')}: `,
221
- item.routed.map(row => h('span', { key: row.destination, className: 'nib-route', title: row.detail || '' },
222
- row.destination, h('span', { className: row.ok ? 'nib-ok' : 'nib-bad' }, row.ok ? '✓' : '✗'),
223
- !row.ok && row.detail ? ` ${row.detail}` : ''))),
224
- ` · ${absolute(item.time, t)}`)))
227
+ h(kit.Tile, { icon: domain.icon ?? GROUP_ICON[group], tone, size: 32 }),
228
+ h('div', { className: 'nib-main' },
229
+ h('button', { type: 'button', className: 'nib-head', 'aria-expanded': open, onClick: () => onToggle(item) },
230
+ h('span', { className: 'nib-titleLine' },
231
+ !item.read && h(kit.NewDot),
232
+ h('span', { className: 'nib-title' }, title),
233
+ group === 'needs-you' && item.ask?.points && h('span', { className: 'nib-points' }, t('points', { n: item.ask.points })),
234
+ h('span', { className: 'nib-when' },
235
+ item.liveNow && h(StateDot, { state: 'done' }),
236
+ h(kit.TimeAgo, { at: item.time }))),
237
+ !open && group !== 'handled' && sub && h('span', { className: 'nib-sub' }, status ? `${sub} · ${status}` : sub)),
238
+ doneText && h('div', { className: 'nib-done' }, h(IconCheckCircleOutlineRegular, { size: 14 }), h('span', null, doneText)),
239
+ item.liveNow && item.live?.progress && h('div', { className: 'nib-progress' },
240
+ h(kit.Progress, { from: item.live.progress.from, to: item.live.progress.to, end: h(kit.TimeUntil, { to: item.live.progress.to }) })),
241
+ history && h(kit.History, { items: history, max: 2 }),
242
+ open && h(Details, { item, kit, ui, t, onPress, onMark }))))
225
243
  }
226
244
 
227
- // ---- push on this device ----
245
+ function Details({ item, kit, ui, t, onPress, onMark }) {
246
+ const status = pressStatus(item, t)
247
+ const about = aboutOf(item)
248
+ const states = pressStates(item)
249
+ return h('div', { className: 'nib-body' },
250
+ item.text && item.text !== item.title && h('div', { className: 'nib-text' }, item.text),
251
+ item.links.length > 0 && h('div', { className: 'nib-links' },
252
+ item.links.map(link => h('a', { key: link, href: link, target: '_blank', rel: 'noopener noreferrer' }, link))),
253
+ item.files.length > 0 && h('div', { className: 'nib-links' },
254
+ h('span', { className: 'nib-meta' }, t('files')),
255
+ item.files.map(file => file.stored
256
+ ? h('a', { key: file.name, href: api(`file?id=${encodeURIComponent(item.id)}&name=${encodeURIComponent(file.name)}`), target: '_blank', rel: 'noopener' }, file.name)
257
+ : h('span', { key: file.name, className: 'nib-meta' }, `${file.name} (${t('notStored', { reason: file.reason || '?' })})`))),
258
+ h('div', { className: 'nib-actions' },
259
+ ui !== null && h(ui.ActionBar, { actions: item.actions, states, about, defaultChat: true, part: 'buttons', onPress }),
260
+ item.read && h(Button, { variant: 'outline', size: 'sm', onClick: () => onMark(item, false) }, t('markUnread')),
261
+ status && h('span', { className: 'nib-meta' }, status)),
262
+ item.group === 'needs-you' && item.session && ui?.start && h(Reply, { item, ui, t, onSent: () => { if (!item.read) onMark(item, true) } }),
263
+ h(kit.Suggested, { actions: item.actions, about, states, onPress }),
264
+ h('div', { className: 'nib-meta' },
265
+ item.routed.length === 0 ? t('notSent') : h(React.Fragment, null, `${t('alsoSent')}: `,
266
+ item.routed.map((row, i) => h(React.Fragment, { key: row.destination },
267
+ i > 0 && ', ',
268
+ h('span', { title: row.detail || '' }, row.destination, ' ', h('span', { className: row.ok ? 'nib-ok' : 'nib-bad' }, row.ok ? '✓' : '✗'))))),
269
+ ` · ${absolute(item.time, t)}`))
270
+ }
271
+
272
+ // ---- push on this device: items of the page's "more" menu ----
228
273
 
229
274
  const pushSupported = () => typeof navigator !== 'undefined' && 'serviceWorker' in navigator && typeof window.PushManager === 'function' && typeof window.Notification === 'function'
230
275
  const isIos = () => /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
@@ -239,43 +284,34 @@ window.__ModuleLoader__.load({
239
284
  const browser = /Edg\//.test(ua) ? 'Edge' : /Firefox\//.test(ua) ? 'Firefox' : /Chrome\//.test(ua) ? 'Chrome' : /Safari\//.test(ua) ? 'Safari' : 'Browser'
240
285
  return [browser, os].filter(Boolean).join(' · ')
241
286
  }
242
-
243
287
  async function currentSubscription() {
244
288
  const registration = await navigator.serviceWorker.getRegistration(api(''))
245
289
  return (await registration?.pushManager.getSubscription()) ?? null
246
290
  }
247
291
 
248
- function PushControl({ t }) {
292
+ /** This browser's push state and the steps to change it. */
293
+ function usePush(t) {
249
294
  const supported = pushSupported()
250
- const [state, setState] = useState('checking')
295
+ const [state, setState] = useState(supported ? 'checking' : 'unsupported')
251
296
  const [note, setNote] = useState(null)
252
- const [busy, setBusy] = useState(false)
253
297
  useEffect(() => {
254
- if (!supported) return
298
+ if (!supported) return undefined
255
299
  let live = true
256
300
  currentSubscription()
257
301
  .then(async sub => (sub === null ? false : (await call('push/state', { endpoint: sub.endpoint })).subscribed))
258
302
  .then(on => { if (live) setState(on ? 'on' : 'off') }, () => { if (live) setState('off') })
259
303
  return () => { live = false }
260
304
  }, [supported])
261
- if (!supported) {
262
- return h('div', { className: 'nib-push' }, h('span', { className: 'nib-grow' }, h('strong', null, t('push.title'))),
263
- h('span', { className: 'nib-hint' }, isIos() && !standalone() ? t('push.ios') : t('push.unsupported')))
264
- }
265
305
  const run = task => async () => {
266
- setBusy(true)
267
306
  setNote(null)
268
307
  try {
269
308
  await task()
270
309
  } catch (reason) {
271
310
  setNote(reason.message)
272
- } finally {
273
- setBusy(false)
274
311
  }
275
312
  }
276
313
  const enable = run(async () => {
277
- const permission = await Notification.requestPermission()
278
- if (permission !== 'granted') {
314
+ if (await Notification.requestPermission() !== 'granted') {
279
315
  setNote(t('push.denied'))
280
316
  return
281
317
  }
@@ -302,102 +338,171 @@ window.__ModuleLoader__.load({
302
338
  const result = await call('push/test', { title: t('push.testTitle'), body: t('push.testBody') })
303
339
  setNote(t('push.testSent', { n: result.sent }))
304
340
  })
305
- return h('div', { className: 'nib-push' },
306
- h('span', { className: 'nib-grow' }, h('strong', null, t('push.title')), ' · ', state === 'on' ? t('push.on') : state === 'off' ? t('push.off') : '…'),
307
- state === 'on' && h('button', { type: 'button', className: 'nib-btn', disabled: busy, onClick: test }, t('push.test')),
308
- state === 'on' && h('button', { type: 'button', className: 'nib-btn', disabled: busy, onClick: disable }, t('push.disable')),
309
- state === 'off' && h('button', { type: 'button', className: 'nib-btn nib-primary', disabled: busy, onClick: enable }, t('push.enable')),
310
- note && h('span', { className: 'nib-hint' }, note))
341
+ const explain = state === 'unsupported' ? t(isIos() && !standalone() ? 'push.ios' : 'push.unsupported') : null
342
+ return { state, note: note ?? explain, enable, disable, test }
343
+ }
344
+
345
+ function MoreMenu({ t }) {
346
+ const push = usePush(t)
347
+ const [open, setOpen] = useState(false)
348
+ const items = [
349
+ { type: 'label', id: 'push', text: `${t('push.title')} · ${t(`push.${push.state === 'on' ? 'on' : push.state === 'off' ? 'off' : 'unavailable'}`)}` },
350
+ ...(push.state === 'off' ? [{ id: 'enable', label: t('push.enable') }] : []),
351
+ ...(push.state === 'on' ? [{ id: 'test', label: t('push.test') }, { id: 'disable', label: t('push.disable') }] : []),
352
+ ]
353
+ const pick = id => {
354
+ setOpen(false)
355
+ if (id === 'enable') push.enable()
356
+ else if (id === 'disable') push.disable()
357
+ else if (id === 'test') push.test()
358
+ }
359
+ return h(React.Fragment, null,
360
+ push.note && h('span', { className: 'nib-meta', role: 'status' }, push.note),
361
+ h(Menu, {
362
+ open,
363
+ onClose: () => setOpen(false),
364
+ align: 'end',
365
+ portal: true,
366
+ items,
367
+ onSelect: pick,
368
+ anchor: h(Tooltip, { label: t('more'), side: 'bottom', portal: true, disabled: open },
369
+ h(Button, { variant: 'outline', size: 'sm', 'aria-label': t('more'), 'aria-haspopup': 'menu', 'aria-expanded': open, onClick: () => setOpen(value => !value) },
370
+ h(IconEllipsisOutlineRegular, null))),
371
+ }))
311
372
  }
312
373
 
313
374
  // ---- the page ----
314
375
 
315
376
  function InboxPage({ translate: t }) {
377
+ const kit = useShared(s => s.kit)
378
+ if (kit === null) return h('div', { className: 'nib-page' }, h('p', { className: 'nib-empty' }, t('kitMissing')))
379
+ return h(Inbox, { t, kit })
380
+ }
381
+
382
+ function Inbox({ t, kit }) {
316
383
  const version = useShared(s => s.version)
317
384
  const unread = useShared(s => s.unread)
385
+ const summary = useShared(s => s.summary)
318
386
  const linked = useShared(s => s.linked)
319
- const [filter, setFilter] = useState(() => (shared.linked ? 'all' : 'unread'))
387
+ const ui = useShared(s => s.ui)
388
+ const [view, setView] = useState('all')
320
389
  const [items, setItems] = useState(null)
321
390
  const [more, setMore] = useState(false)
322
391
  const [error, setError] = useState(null)
323
392
  const [open, setOpen] = useState(() => shared.linked)
324
- // Rows shown under Unread during this visit stay on screen as they turn read, done or snoozed,
325
- // so the list never moves under the person's finger; leaving the view (or tapping its tab again) lets them go.
326
- const shown = useRef(new Set())
393
+ // Items shown in this view stay where they first showed (their group, and in "Needs you" at all)
394
+ // as they turn read, done or snoozed, so nothing moves under the person's finger; leaving the
395
+ // view (or tapping its filter again) lets them go.
396
+ const placed = useRef(new Map())
327
397
  const [visit, setVisit] = useState(0)
328
- const ui = useShared(s => s.ui)
398
+ /** Remember where items first showed: the page's first items in order, later arrivals on top, older pages below. */
399
+ const place = (rows, append) => {
400
+ const ranks = [...placed.current.values()].map(spot => spot.rank)
401
+ let top = Math.min(0, ...ranks)
402
+ let bottom = Math.max(-1, ...ranks)
403
+ const fresh = placed.current.size === 0 || append
404
+ for (const row of fresh ? rows : [...rows].reverse()) {
405
+ if (placed.current.has(row.key)) continue
406
+ placed.current.set(row.key, { group: row.group, rank: fresh ? ++bottom : --top })
407
+ }
408
+ }
409
+ const stream = kit.useEventStream('api/notify-inbox/events', changed)
329
410
 
330
- const load = useCallback(async (append) => {
411
+ const load = useCallback(async append => {
331
412
  try {
332
413
  const params = new URLSearchParams()
333
- if (filter === 'unread') {
334
- params.set('unread', '1')
335
- if (shown.current.size > 0) params.set('keep', [...shown.current].join(','))
414
+ if (view === 'needs-you') {
415
+ params.set('view', 'needs-you')
416
+ if (placed.current.size > 0) params.set('keep', [...placed.current.keys()].join(','))
336
417
  }
337
- if (append && items?.length) params.set('before', items[items.length - 1].id)
418
+ if (append && items?.length) params.set('before', items[items.length - 1].key)
338
419
  const page = await call(`items?${params}`)
339
- if (filter === 'unread') for (const row of page.items) shown.current.add(row.id)
420
+ place(page.items, append)
340
421
  setItems(previous => (append && previous ? [...previous, ...page.items] : page.items))
341
422
  setMore(page.more)
342
423
  setError(null)
343
424
  } catch (reason) {
344
425
  setError(reason.message)
345
426
  }
346
- }, [filter, items])
427
+ }, [view, items])
347
428
 
348
- useEffect(() => { load(false) }, [filter, version, visit])
429
+ useEffect(() => { load(false) }, [view, version, visit])
349
430
  const showView = key => {
350
- shown.current = new Set()
351
- if (key === filter) setVisit(n => n + 1)
352
- else setFilter(key)
431
+ placed.current = new Map()
432
+ if (key === view) setVisit(n => n + 1)
433
+ else setView(key)
353
434
  }
354
435
  useEffect(() => {
355
436
  if (!linked) return
356
437
  showView('all')
357
438
  setOpen(linked)
358
439
  shared.linked = null
359
- call('read', { ids: [linked] }).then(changed, () => {})
360
- setTimeout(() => document.getElementById(`nib-${linked}`)?.scrollIntoView({ block: 'center' }), 300)
440
+ call('items').then(page => {
441
+ const item = page.items.find(row => row.ids.includes(linked) || row.key === linked)
442
+ if (item === undefined) return
443
+ setOpen(item.key)
444
+ call('read', { ids: item.ids }).then(changed, () => {})
445
+ setTimeout(() => document.getElementById(`nib-${item.key}`)?.scrollIntoView({ block: 'center' }), 300)
446
+ }, () => {})
361
447
  }, [linked])
362
448
 
363
449
  const mark = (item, read) => {
364
- setItems(list => list.map(row => (row.id === item.id ? { ...row, read } : row)))
365
- call('read', { ids: [item.id], read }).then(changed, reason => setError(reason.message))
450
+ setItems(list => list.map(row => (row.key === item.key ? { ...row, read } : row)))
451
+ call('read', { ids: read ? item.ids : [item.id], read }).then(changed, reason => setError(reason.message))
366
452
  }
367
453
  const toggle = item => {
368
- const next = open === item.id ? null : item.id
454
+ const next = open === item.key ? null : item.key
369
455
  setOpen(next)
370
456
  if (next !== null && !item.read) mark(item, true)
371
457
  }
372
458
  const markAll = () => call('read', { all: true }).then(changed, reason => setError(reason.message))
373
459
 
460
+ const groups = summary?.groups ?? {}
461
+ const domains = summary?.domains ?? {}
462
+ const total = summary?.total ?? 0
463
+ const byGroup = new Map(GROUPS.map(group => [group, []]))
464
+ for (const item of items ?? []) byGroup.get(placed.current.get(item.key)?.group ?? item.group)?.push(item)
465
+ const rank = item => placed.current.get(item.key)?.rank ?? 0
466
+ for (const list of byGroup.values()) list.sort((a, b) => rank(a) - rank(b))
467
+ const filters = [['needs-you', t('group.needs-you'), groups['needs-you'] ?? 0], ['all', t('filter.all'), total]]
468
+
374
469
  return h('div', { className: 'nib-page' },
375
470
  h('div', { className: 'nib-scroll' },
376
471
  h('div', { className: 'nib-content' },
377
- h('div', { className: 'nib-head' },
378
- h('h1', null, t('title'), unread > 0 && h('span', { className: 'nib-count' }, unread)),
379
- h('div', { className: 'nib-tabs', role: 'group' },
380
- ['unread', 'all'].map(key => h('button', { key, type: 'button', className: 'nib-tab', 'aria-pressed': filter === key, onClick: () => showView(key) }, t(`filter.${key}`)))),
381
- h('button', { type: 'button', className: 'nib-btn', disabled: unread === 0, onClick: markAll }, t('markAll'))),
382
- h(PushControl, { t }),
472
+ h('div', { className: 'nib-heading' },
473
+ h('h1', null, t('title')),
474
+ h('div', { className: 'nib-tools' },
475
+ h(Button, { variant: 'outline', size: 'sm', disabled: unread === 0, onClick: markAll }, t('markAll')),
476
+ h(MoreMenu, { t }))),
477
+ summary?.line && h('p', { className: 'nib-said' }, said(summary.line.text, t)),
478
+ h('div', { className: 'nib-status' },
479
+ h(kit.LiveStatus, { status: stream, updatedAt: summary?.latest ?? undefined }),
480
+ total > 0 && h('span', { className: 'nib-counts' },
481
+ GROUPS.filter(group => (groups[group] ?? 0) > 0).map(group => h('span', { key: group }, `${t(`group.${group}`)} `, h('b', { 'data-group': group }, groups[group]))))),
482
+ h('div', { className: 'nib-filters', role: 'group', 'aria-label': t('filter.label') },
483
+ filters.map(([key, label, n]) => h(Pill, { key, active: view === key, 'aria-pressed': view === key, onClick: () => showView(key) },
484
+ label, n > 0 && h('span', { className: 'nib-n' }, n)))),
383
485
  error && h('p', { className: 'nib-error', role: 'alert' }, t('error', { message: error })),
384
- items !== null && items.length === 0 && h('p', { className: 'nib-empty' }, t(filter === 'unread' ? 'empty.unread' : 'empty.all')),
385
- items !== null && h('ul', { className: 'nib-list' },
386
- items.map(item => h(Item, { key: item.id, item, t, open: open === item.id, onToggle: toggle, onMark: mark, ui }))),
387
- more && h('button', { type: 'button', className: 'nib-btn nib-more', onClick: () => load(true) }, t('loadMore')))))
486
+ items !== null && items.length === 0 && h('p', { className: 'nib-empty' }, t(`empty.${view}`)),
487
+ GROUPS.map(group => byGroup.get(group).length > 0 && h('section', { key: group, className: 'nib-group', 'data-group': group, 'aria-label': t(`group.${group}`) },
488
+ h('div', { className: 'nib-groupHead' },
489
+ h('h2', null, t(`group.${group}`)),
490
+ h('span', { className: 'nib-n' }, byGroup.get(group).length)),
491
+ h('ul', { className: 'nib-list' },
492
+ byGroup.get(group).map(item => h(Item, { key: item.key, item, group, kit, ui, t, domains, open: open === item.key, onToggle: toggle, onMark: mark }))))),
493
+ more && h('div', { className: 'nib-more' }, h(Button, { variant: 'outline', size: 'sm', onClick: () => load(true) }, t('loadMore'))))))
388
494
  }
389
495
 
390
- function BellIcon({ size }) {
391
- const stroke = { stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round', strokeLinejoin: 'round' }
392
- return h('svg', { width: size, height: size, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, focusable: 'false' },
393
- h('path', { d: 'M8 2.2c-2.3 0-3.9 1.8-3.9 4v2.3L3 10.4c-.2.4.1.9.5.9h9c.4 0 .7-.5.5-.9l-1.1-1.9V6.2c0-2.2-1.6-4-3.9-4Z', ...stroke }),
394
- h('path', { d: 'M6.5 13.2c.3.7.9 1.1 1.5 1.1s1.2-.4 1.5-1.1', ...stroke }))
496
+ /** The bell, from the kit's icons (DSH has none). */
497
+ function BellGlyph({ size }) {
498
+ const kit = useShared(s => s.kit)
499
+ return kit === null ? null : h(kit.Icon, { name: 'bell', size })
395
500
  }
396
501
 
397
502
  function SidebarIcon({ size }) {
398
503
  const unread = useShared(s => s.unread)
399
- return h('span', { className: 'nib-icon' },
400
- h(BellIcon, { size }),
504
+ return h('span', { className: 'nib-bell' },
505
+ h(BellGlyph, { size }),
401
506
  unread > 0 && h('span', { className: 'nib-badge' }, unread > 99 ? '99+' : String(unread)))
402
507
  }
403
508
 
@@ -425,12 +530,21 @@ window.__ModuleLoader__.load({
425
530
  return () => tag.remove()
426
531
  }, 'notify-inbox: styles')
427
532
 
533
+ // Shared pieces DSH doesn't have (tiles, time, live status, history): @soffits/dsh-ui-kit.
534
+ ctx.inject(['uiKit'], scope => {
535
+ scope.effect(() => {
536
+ shared.kit = scope.uiKit
537
+ emit()
538
+ return () => { shared.kit = null; emit() }
539
+ }, 'notify-inbox: kit')
540
+ })
541
+
428
542
  // The buttons, when @soffits/dsh-ui-actions is installed; without it the page shows no buttons.
429
543
  ctx.inject(['uiActions'], scope => {
430
544
  scope.effect(() => {
431
545
  shared.ui = scope.uiActions
432
546
  emit()
433
- const unregister = scope.uiActions.registerSource({ id: OWNER, name: () => t('panel'), icon: BellIcon })
547
+ const unregister = scope.uiActions.registerSource({ id: OWNER, name: () => t('panel'), icon: BellGlyph })
434
548
  return () => { unregister(); shared.ui = null; emit() }
435
549
  }, 'notify-inbox: buttons')
436
550
  })
@@ -449,19 +563,26 @@ window.__ModuleLoader__.load({
449
563
  label: () => t('panel'),
450
564
  }, SidebarIcon))
451
565
 
452
- // The unread count: checked while the page is visible, and right away when it becomes visible.
566
+ shared.openSession = id => ctx.get('uiWorkspace')?.openSession(id)
567
+
568
+ // The counts: read when the app shows, and again whenever the events stream says the inbox
569
+ // changed (the stream is open while the app is visible; EventSource reconnects by itself).
453
570
  ctx.effect(() => {
454
- let timer
455
- const tick = () => {
456
- clearTimeout(timer)
457
- if (document.visibilityState === 'visible') refreshSummary()
458
- timer = setTimeout(tick, shared.pollSeconds * 1000)
571
+ let source = null
572
+ const open = () => {
573
+ if (source !== null || typeof EventSource !== 'function') return
574
+ source = new EventSource(api('events'), { withCredentials: true })
575
+ source.onmessage = changed
576
+ source.onopen = changed
577
+ }
578
+ const close = () => { source?.close(); source = null }
579
+ const onVisible = () => {
580
+ if (document.visibilityState === 'visible') { open(); refreshSummary() } else close()
459
581
  }
460
- const onVisible = () => { if (document.visibilityState === 'visible') tick() }
461
582
  document.addEventListener('visibilitychange', onVisible)
462
- tick()
463
- return () => { clearTimeout(timer); document.removeEventListener('visibilitychange', onVisible) }
464
- }, 'notify-inbox: unread count')
583
+ onVisible()
584
+ return () => { close(); document.removeEventListener('visibilitychange', onVisible) }
585
+ }, 'notify-inbox: counts')
465
586
 
466
587
  // ?notify-inbox=<id> (a tapped push, a shared link) opens the page on that notification.
467
588
  const openLinked = id => {