@soffits/dsh-notify-inbox 0.4.0 → 0.5.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/CHANGELOG.md +9 -0
- package/README.md +23 -3
- package/client.js +272 -203
- package/docs/ui.md +36 -0
- package/index.js +21 -2
- package/locale/en.json +14 -6
- package/locale/fr.json +15 -7
- package/locale/zh.json +13 -5
- package/package.json +24 -4
- package/src/changes.js +75 -0
- package/src/domains.js +49 -0
- package/src/routes.js +67 -14
- package/src/store.js +100 -6
- package/src/view.js +75 -0
package/client.js
CHANGED
|
@@ -3,86 +3,93 @@
|
|
|
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)
|
|
7
|
-
* from
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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.
|
|
10
14
|
*/
|
|
11
15
|
window.__ModuleLoader__.load({
|
|
12
16
|
id: '@soffits/dsh-notify-inbox',
|
|
13
17
|
factory(require) {
|
|
14
18
|
const React = require('react')
|
|
19
|
+
const { Button, Pill, Menu, Tooltip, StateDot, IconCheckCircleOutlineRegular, IconEllipsisOutlineRegular } = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
15
20
|
const h = React.createElement
|
|
16
21
|
const { useState, useEffect, useCallback, useRef, useSyncExternalStore } = React
|
|
17
22
|
|
|
18
23
|
const NS = 'dsh-notify-inbox'
|
|
19
24
|
const PANEL = 'dsh-notify-inbox'
|
|
25
|
+
const OWNER = '@soffits/dsh-notify-inbox'
|
|
20
26
|
const LINK_PARAM = 'notify-inbox'
|
|
21
27
|
const STYLE_ID = 'dsh-notify-inbox-style'
|
|
22
28
|
const PENDING_MS = 2 * 60 * 1000
|
|
29
|
+
const GROUPS = ['needs-you', 'live', 'handled', 'info']
|
|
30
|
+
/** The colour an item's tile takes from what it needs, unless its domain names one. */
|
|
31
|
+
const GROUP_TONE = { 'needs-you': 'accent', live: 'accent', handled: 'ok', info: 'muted' }
|
|
32
|
+
const GROUP_ICON = { 'needs-you': 'circle-alert', live: 'activity', handled: 'circle-check', info: 'info' }
|
|
23
33
|
const api = path => new URL(`api/notify-inbox/${path}`, document.baseURI).href
|
|
24
34
|
|
|
35
|
+
// Only what DSH's components don't cover: the page frame and row layout mirror DSH's own pages
|
|
36
|
+
// (ui-schedule TaskManagerPage, plugin manager groups), since their CSS modules are private.
|
|
25
37
|
const CSS = `
|
|
26
|
-
.nib-page{width:100%;min-width:0;
|
|
27
|
-
.nib-
|
|
28
|
-
.nib-
|
|
29
|
-
.nib-
|
|
30
|
-
|
|
31
|
-
.nib-
|
|
32
|
-
.nib-
|
|
33
|
-
.nib-
|
|
34
|
-
.nib-
|
|
35
|
-
.nib-
|
|
36
|
-
.nib-
|
|
37
|
-
.nib-
|
|
38
|
-
|
|
39
|
-
.nib-
|
|
40
|
-
.nib-
|
|
41
|
-
.nib-
|
|
42
|
-
.nib-
|
|
43
|
-
.nib-
|
|
38
|
+
.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}
|
|
39
|
+
.nib-page :focus-visible{outline:2px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
|
|
40
|
+
.nib-scroll{flex:1;min-height:0;overflow:auto;scrollbar-gutter:stable;--dsh-scrollbar-width:9px;--dsh-scrollbar-thumb-border:2px}
|
|
41
|
+
.nib-content{max-width:960px;margin:0 auto;padding:0 clamp(24px,4vw,48px) 48px}
|
|
42
|
+
.nib-heading{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px 16px;padding-top:28px;margin-bottom:4px}
|
|
43
|
+
[data-platform=darwin] .nib-heading{padding-top:calc(28px + var(--dsh-frame-top-clearance,0px))}
|
|
44
|
+
.nib-heading h1{flex:0 1 auto;min-width:0;margin:0;font-size:20px;line-height:28px;font-weight:500}
|
|
45
|
+
.nib-tools{display:flex;align-items:center;gap:8px}
|
|
46
|
+
.nib-said{margin:0;font-size:15px;line-height:24px;overflow-wrap:anywhere}
|
|
47
|
+
.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}
|
|
48
|
+
.nib-counts>*+*::before{content:'·';padding:0 6px}
|
|
49
|
+
.nib-counts b{font-weight:500;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}
|
|
50
|
+
.nib-counts b[data-group=needs-you]{color:var(--dsw-alias-state-business-primary)}
|
|
51
|
+
.nib-filters{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:20px}
|
|
52
|
+
.nib-n{font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-tertiary)}
|
|
53
|
+
.nib-group{display:flex;flex-direction:column;gap:4px;margin-bottom:24px}
|
|
54
|
+
.nib-groupHead{display:flex;align-items:baseline;gap:8px;padding:0 8px}
|
|
55
|
+
.nib-groupHead h2{margin:0;font-size:14px;line-height:22px;font-weight:500}
|
|
44
56
|
.nib-list{display:flex;flex-direction:column;gap:2px;margin:0;padding:0;list-style:none}
|
|
45
|
-
.nib-item{border-radius:12px;padding:
|
|
46
|
-
.nib-item.nib-open{background:var(--dsw-alias-bg-layer-1
|
|
47
|
-
.nib-
|
|
48
|
-
.nib-
|
|
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)}
|
|
57
|
+
.nib-item{border-radius:12px;padding:8px}
|
|
58
|
+
.nib-item.nib-open{background:var(--dsw-alias-bg-layer-1)}
|
|
59
|
+
@media (hover:hover){.nib-item:not(.nib-open):hover{background:var(--dsw-alias-interactive-bg-hover)}}
|
|
60
|
+
.nib-line{display:flex;gap:12px;align-items:flex-start}
|
|
54
61
|
.nib-main{flex:1;min-width:0}
|
|
55
|
-
.nib-
|
|
56
|
-
.nib-
|
|
57
|
-
.nib-
|
|
58
|
-
.nib-
|
|
59
|
-
.nib-
|
|
60
|
-
.nib-
|
|
61
|
-
.nib-
|
|
62
|
-
.nib-
|
|
63
|
-
.nib-
|
|
64
|
-
.nib-
|
|
62
|
+
.nib-head{display:block;width:100%;padding:0;border:0;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer}
|
|
63
|
+
.nib-titleLine{display:flex;align-items:flex-start;gap:8px;min-width:0;padding-top:4px}
|
|
64
|
+
.nib-titleLine>.uk-newDot{margin-top:8px}
|
|
65
|
+
.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)}
|
|
66
|
+
.nib-unread .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)}
|
|
67
|
+
.nib-open .nib-title{-webkit-line-clamp:unset}
|
|
68
|
+
.nib-when{flex:none;display:inline-flex;align-items:center;gap:6px;font-size:12px;line-height:23px;color:var(--dsw-alias-label-caption)}
|
|
69
|
+
.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}
|
|
70
|
+
.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}
|
|
71
|
+
.nib-done svg{flex:none;margin-top:3px;color:var(--dsw-alias-state-success-primary)}
|
|
72
|
+
.nib-progress{margin-top:8px;max-width:560px}
|
|
73
|
+
.nib-body{display:flex;flex-direction:column;gap:12px;margin-top:10px}
|
|
74
|
+
.nib-text{white-space:pre-wrap;overflow-wrap:anywhere;line-height:22px}
|
|
65
75
|
.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-
|
|
68
|
-
.nib-
|
|
76
|
+
.nib-links a{color:var(--dsw-alias-link,var(--dsw-alias-state-business-primary));overflow-wrap:anywhere}
|
|
77
|
+
.nib-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
|
|
78
|
+
.nib-meta{font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary)}
|
|
69
79
|
.nib-ok{color:var(--dsw-alias-state-success-primary)}
|
|
70
80
|
.nib-bad{color:var(--dsw-alias-state-error-primary)}
|
|
71
|
-
.nib-
|
|
72
|
-
.nib-
|
|
73
|
-
.nib-
|
|
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}
|
|
81
|
+
.nib-empty{padding:48px 20px;text-align:center;color:var(--dsw-alias-label-tertiary)}
|
|
82
|
+
.nib-error{color:var(--dsw-alias-state-error-primary)}
|
|
83
|
+
.nib-more{display:flex;justify-content:center}
|
|
78
84
|
.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
|
-
|
|
80
|
-
@media (width<=640px){.nib-content{padding-inline:12px}.nib-
|
|
85
|
+
.nib-bell{position:relative;display:inline-flex}
|
|
86
|
+
@media (width<=640px){.nib-content{padding-inline:12px}.nib-heading{padding-top:16px}.nib-item{padding:8px 6px}.nib-line{gap:10px}}
|
|
87
|
+
@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
88
|
`
|
|
82
89
|
|
|
83
|
-
// ---- shared state: the
|
|
90
|
+
// ---- shared state: the counts and a version that bumps when anything changes ----
|
|
84
91
|
|
|
85
|
-
const shared = { unread: 0, version: 0, pollSeconds: 30, linked: null, ui: null }
|
|
92
|
+
const shared = { unread: 0, version: 0, pollSeconds: 30, linked: null, ui: null, kit: null, summary: null }
|
|
86
93
|
const listeners = new Set()
|
|
87
94
|
const emit = () => { for (const listener of listeners) listener() }
|
|
88
95
|
const subscribe = listener => { listeners.add(listener); return () => listeners.delete(listener) }
|
|
@@ -103,10 +110,11 @@ window.__ModuleLoader__.load({
|
|
|
103
110
|
try {
|
|
104
111
|
const summary = await call('summary')
|
|
105
112
|
shared.pollSeconds = summary.pollSeconds || 30
|
|
106
|
-
const key =
|
|
113
|
+
const key = JSON.stringify([summary.unread, summary.latest, summary.total, summary.groups, summary.line])
|
|
107
114
|
if (key !== lastSummary) {
|
|
108
115
|
lastSummary = key
|
|
109
116
|
shared.unread = summary.unread
|
|
117
|
+
shared.summary = summary
|
|
110
118
|
shared.version += 1
|
|
111
119
|
emit()
|
|
112
120
|
}
|
|
@@ -116,115 +124,106 @@ window.__ModuleLoader__.load({
|
|
|
116
124
|
}
|
|
117
125
|
const changed = () => { lastSummary = ''; refreshSummary() }
|
|
118
126
|
|
|
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
127
|
const absolute = (iso, t) => new Date(iso).toLocaleString(t('time.locale'), { dateStyle: 'medium', timeStyle: 'short' })
|
|
128
|
+
/** Text a person reads: a string, or a map from language tag to text. */
|
|
129
|
+
const said = (value, t) => (typeof value === 'string' ? value : value?.[t('time.locale').split('-')[0]] ?? Object.values(value ?? {})[0] ?? '')
|
|
132
130
|
|
|
133
|
-
|
|
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'
|
|
131
|
+
// ---- the buttons ----
|
|
150
132
|
|
|
151
133
|
/** The server's view of each button's last press: pending, done or unhandled. */
|
|
152
134
|
function pressStates(item) {
|
|
153
135
|
const states = {}
|
|
154
136
|
for (const press of item.presses) {
|
|
155
137
|
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.
|
|
138
|
+
const handled = item.outcomes.some(row => row.press === press.press)
|
|
157
139
|
states[action.id] = handled ? 'done' : Date.now() - Date.parse(press.at) < PENDING_MS ? 'pending' : 'unhandled'
|
|
158
140
|
}
|
|
159
141
|
return states
|
|
160
142
|
}
|
|
161
143
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
const onPress = async (action, extra) => {
|
|
173
|
-
await call('action', { record: item.id, action: action.id, ...(extra?.until ? { until: extra.until } : {}) })
|
|
174
|
-
changed()
|
|
144
|
+
/** What happened to the latest press, in words, or null. */
|
|
145
|
+
function pressStatus(item, t) {
|
|
146
|
+
const press = item.presses[item.presses.length - 1]
|
|
147
|
+
if (press === undefined || press.action === 'step') return null
|
|
148
|
+
const outcome = item.outcomes.find(row => row.press === press.press)
|
|
149
|
+
if (outcome !== undefined) {
|
|
150
|
+
if (outcome.result === 'snoozed' && outcome.until) return t('press.snoozed', { time: absolute(outcome.until, t) })
|
|
151
|
+
if (outcome.result === 'done') return t('press.done')
|
|
152
|
+
return outcome.result
|
|
175
153
|
}
|
|
176
|
-
|
|
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)))
|
|
154
|
+
return Date.now() - Date.parse(press.at) < PENDING_MS ? t('press.pending') : t('press.unhandled')
|
|
180
155
|
}
|
|
181
156
|
|
|
182
|
-
|
|
157
|
+
/** What "Ask" and a step attach to the conversation: the notification as a card. */
|
|
158
|
+
const aboutOf = item => ({
|
|
159
|
+
source: OWNER,
|
|
160
|
+
title: item.title || item.spoken || item.text,
|
|
161
|
+
lines: [item.title && item.spoken !== item.title ? item.spoken : '', ...(item.text || '').split('\n'), ...item.links].filter(line => line && line !== item.title),
|
|
162
|
+
context: { notification: item.id, time: item.time, lane: item.lane, domain: item.domain || undefined, thread: item.thread || undefined },
|
|
163
|
+
})
|
|
183
164
|
|
|
184
|
-
|
|
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' }))
|
|
189
|
-
}
|
|
165
|
+
// ---- one item ----
|
|
190
166
|
|
|
191
|
-
function Item({ item, t, open, onToggle, onMark
|
|
192
|
-
const
|
|
193
|
-
const
|
|
167
|
+
function Item({ item, group, kit, ui, t, domains, open, onToggle, onMark }) {
|
|
168
|
+
const wash = kit.useWash(item.id, item.key)
|
|
169
|
+
const domain = domains[item.domain] ?? {}
|
|
170
|
+
const tone = domain.tone ?? (group === 'needs-you' && item.lane === 'interrupt' ? 'bad' : GROUP_TONE[group])
|
|
194
171
|
const title = item.title || item.spoken || item.text.slice(0, 80)
|
|
195
172
|
const sub = item.spoken && item.spoken !== title ? item.spoken : item.text !== title ? item.text : ''
|
|
196
|
-
|
|
173
|
+
const doneText = item.handled?.text ?? (item.moved === 'done' ? t('moved.done') : null)
|
|
174
|
+
const status = item.moved === 'snoozed' ? pressStatus(item, t) : item.moved === 'ended' ? t('moved.ended') : null
|
|
175
|
+
const history = !item.liveNow && item.history.length > 0 && item.history.map(row => ({ at: row.time, text: said(row.spoken, t) || said(row.title, t) }))
|
|
176
|
+
const onPress = async (action, extra) => {
|
|
177
|
+
await call('action', { record: item.id, action: action.id, ...(extra?.until ? { until: extra.until } : {}) })
|
|
178
|
+
changed()
|
|
179
|
+
}
|
|
180
|
+
const className = ['nib-item', item.read ? '' : 'nib-unread', open ? 'nib-open' : '', wash].filter(Boolean).join(' ')
|
|
181
|
+
return h('li', { className, id: `nib-${item.key}` },
|
|
197
182
|
h('div', { className: 'nib-line' },
|
|
198
|
-
|
|
199
|
-
h('
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
183
|
+
h(kit.Tile, { icon: domain.icon ?? GROUP_ICON[group], tone, size: 32 }),
|
|
184
|
+
h('div', { className: 'nib-main' },
|
|
185
|
+
h('button', { type: 'button', className: 'nib-head', 'aria-expanded': open, onClick: () => onToggle(item) },
|
|
186
|
+
h('span', { className: 'nib-titleLine' },
|
|
187
|
+
!item.read && h(kit.NewDot),
|
|
188
|
+
h('span', { className: 'nib-title' }, title),
|
|
189
|
+
h('span', { className: 'nib-when' },
|
|
190
|
+
item.liveNow && h(StateDot, { state: 'done' }),
|
|
191
|
+
h(kit.TimeAgo, { at: item.time }))),
|
|
192
|
+
!open && group !== 'handled' && sub && h('span', { className: 'nib-sub' }, status ? `${sub} · ${status}` : sub)),
|
|
193
|
+
doneText && h('div', { className: 'nib-done' }, h(IconCheckCircleOutlineRegular, { size: 14 }), h('span', null, doneText)),
|
|
194
|
+
item.liveNow && item.live?.progress && h('div', { className: 'nib-progress' },
|
|
195
|
+
h(kit.Progress, { from: item.live.progress.from, to: item.live.progress.to, end: h(kit.TimeUntil, { to: item.live.progress.to }) })),
|
|
196
|
+
history && h(kit.History, { items: history, max: 2 }),
|
|
197
|
+
open && h(Details, { item, kit, ui, t, onPress, onMark }))))
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function Details({ item, kit, ui, t, onPress, onMark }) {
|
|
201
|
+
const status = pressStatus(item, t)
|
|
202
|
+
const about = aboutOf(item)
|
|
203
|
+
const states = pressStates(item)
|
|
204
|
+
return h('div', { className: 'nib-body' },
|
|
205
|
+
item.text && item.text !== item.title && h('div', { className: 'nib-text' }, item.text),
|
|
206
|
+
item.links.length > 0 && h('div', { className: 'nib-links' },
|
|
207
|
+
item.links.map(link => h('a', { key: link, href: link, target: '_blank', rel: 'noopener noreferrer' }, link))),
|
|
208
|
+
item.files.length > 0 && h('div', { className: 'nib-links' },
|
|
209
|
+
h('span', { className: 'nib-meta' }, t('files')),
|
|
210
|
+
item.files.map(file => file.stored
|
|
211
|
+
? h('a', { key: file.name, href: api(`file?id=${encodeURIComponent(item.id)}&name=${encodeURIComponent(file.name)}`), target: '_blank', rel: 'noopener' }, file.name)
|
|
212
|
+
: h('span', { key: file.name, className: 'nib-meta' }, `${file.name} (${t('notStored', { reason: file.reason || '?' })})`))),
|
|
213
|
+
h('div', { className: 'nib-actions' },
|
|
214
|
+
ui !== null && h(ui.ActionBar, { actions: item.actions, states, about, defaultChat: true, part: 'buttons', onPress }),
|
|
215
|
+
item.read && h(Button, { variant: 'outline', size: 'sm', onClick: () => onMark(item, false) }, t('markUnread')),
|
|
216
|
+
status && h('span', { className: 'nib-meta' }, status)),
|
|
217
|
+
h(kit.Suggested, { actions: item.actions, about, states, onPress }),
|
|
218
|
+
h('div', { className: 'nib-meta' },
|
|
219
|
+
item.routed.length === 0 ? t('notSent') : h(React.Fragment, null, `${t('alsoSent')}: `,
|
|
220
|
+
item.routed.map((row, i) => h(React.Fragment, { key: row.destination },
|
|
221
|
+
i > 0 && ', ',
|
|
222
|
+
h('span', { title: row.detail || '' }, row.destination, ' ', h('span', { className: row.ok ? 'nib-ok' : 'nib-bad' }, row.ok ? '✓' : '✗'))))),
|
|
223
|
+
` · ${absolute(item.time, t)}`))
|
|
225
224
|
}
|
|
226
225
|
|
|
227
|
-
// ---- push on this device ----
|
|
226
|
+
// ---- push on this device: items of the page's "more" menu ----
|
|
228
227
|
|
|
229
228
|
const pushSupported = () => typeof navigator !== 'undefined' && 'serviceWorker' in navigator && typeof window.PushManager === 'function' && typeof window.Notification === 'function'
|
|
230
229
|
const isIos = () => /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
|
|
@@ -239,43 +238,34 @@ window.__ModuleLoader__.load({
|
|
|
239
238
|
const browser = /Edg\//.test(ua) ? 'Edge' : /Firefox\//.test(ua) ? 'Firefox' : /Chrome\//.test(ua) ? 'Chrome' : /Safari\//.test(ua) ? 'Safari' : 'Browser'
|
|
240
239
|
return [browser, os].filter(Boolean).join(' · ')
|
|
241
240
|
}
|
|
242
|
-
|
|
243
241
|
async function currentSubscription() {
|
|
244
242
|
const registration = await navigator.serviceWorker.getRegistration(api(''))
|
|
245
243
|
return (await registration?.pushManager.getSubscription()) ?? null
|
|
246
244
|
}
|
|
247
245
|
|
|
248
|
-
|
|
246
|
+
/** This browser's push state and the steps to change it. */
|
|
247
|
+
function usePush(t) {
|
|
249
248
|
const supported = pushSupported()
|
|
250
|
-
const [state, setState] = useState('checking')
|
|
249
|
+
const [state, setState] = useState(supported ? 'checking' : 'unsupported')
|
|
251
250
|
const [note, setNote] = useState(null)
|
|
252
|
-
const [busy, setBusy] = useState(false)
|
|
253
251
|
useEffect(() => {
|
|
254
|
-
if (!supported) return
|
|
252
|
+
if (!supported) return undefined
|
|
255
253
|
let live = true
|
|
256
254
|
currentSubscription()
|
|
257
255
|
.then(async sub => (sub === null ? false : (await call('push/state', { endpoint: sub.endpoint })).subscribed))
|
|
258
256
|
.then(on => { if (live) setState(on ? 'on' : 'off') }, () => { if (live) setState('off') })
|
|
259
257
|
return () => { live = false }
|
|
260
258
|
}, [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
259
|
const run = task => async () => {
|
|
266
|
-
setBusy(true)
|
|
267
260
|
setNote(null)
|
|
268
261
|
try {
|
|
269
262
|
await task()
|
|
270
263
|
} catch (reason) {
|
|
271
264
|
setNote(reason.message)
|
|
272
|
-
} finally {
|
|
273
|
-
setBusy(false)
|
|
274
265
|
}
|
|
275
266
|
}
|
|
276
267
|
const enable = run(async () => {
|
|
277
|
-
|
|
278
|
-
if (permission !== 'granted') {
|
|
268
|
+
if (await Notification.requestPermission() !== 'granted') {
|
|
279
269
|
setNote(t('push.denied'))
|
|
280
270
|
return
|
|
281
271
|
}
|
|
@@ -302,102 +292,171 @@ window.__ModuleLoader__.load({
|
|
|
302
292
|
const result = await call('push/test', { title: t('push.testTitle'), body: t('push.testBody') })
|
|
303
293
|
setNote(t('push.testSent', { n: result.sent }))
|
|
304
294
|
})
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
295
|
+
const explain = state === 'unsupported' ? t(isIos() && !standalone() ? 'push.ios' : 'push.unsupported') : null
|
|
296
|
+
return { state, note: note ?? explain, enable, disable, test }
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function MoreMenu({ t }) {
|
|
300
|
+
const push = usePush(t)
|
|
301
|
+
const [open, setOpen] = useState(false)
|
|
302
|
+
const items = [
|
|
303
|
+
{ type: 'label', id: 'push', text: `${t('push.title')} · ${t(`push.${push.state === 'on' ? 'on' : push.state === 'off' ? 'off' : 'unavailable'}`)}` },
|
|
304
|
+
...(push.state === 'off' ? [{ id: 'enable', label: t('push.enable') }] : []),
|
|
305
|
+
...(push.state === 'on' ? [{ id: 'test', label: t('push.test') }, { id: 'disable', label: t('push.disable') }] : []),
|
|
306
|
+
]
|
|
307
|
+
const pick = id => {
|
|
308
|
+
setOpen(false)
|
|
309
|
+
if (id === 'enable') push.enable()
|
|
310
|
+
else if (id === 'disable') push.disable()
|
|
311
|
+
else if (id === 'test') push.test()
|
|
312
|
+
}
|
|
313
|
+
return h(React.Fragment, null,
|
|
314
|
+
push.note && h('span', { className: 'nib-meta', role: 'status' }, push.note),
|
|
315
|
+
h(Menu, {
|
|
316
|
+
open,
|
|
317
|
+
onClose: () => setOpen(false),
|
|
318
|
+
align: 'end',
|
|
319
|
+
portal: true,
|
|
320
|
+
items,
|
|
321
|
+
onSelect: pick,
|
|
322
|
+
anchor: h(Tooltip, { label: t('more'), side: 'bottom', portal: true, disabled: open },
|
|
323
|
+
h(Button, { variant: 'outline', size: 'sm', 'aria-label': t('more'), 'aria-haspopup': 'menu', 'aria-expanded': open, onClick: () => setOpen(value => !value) },
|
|
324
|
+
h(IconEllipsisOutlineRegular, null))),
|
|
325
|
+
}))
|
|
311
326
|
}
|
|
312
327
|
|
|
313
328
|
// ---- the page ----
|
|
314
329
|
|
|
315
330
|
function InboxPage({ translate: t }) {
|
|
331
|
+
const kit = useShared(s => s.kit)
|
|
332
|
+
if (kit === null) return h('div', { className: 'nib-page' }, h('p', { className: 'nib-empty' }, t('kitMissing')))
|
|
333
|
+
return h(Inbox, { t, kit })
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function Inbox({ t, kit }) {
|
|
316
337
|
const version = useShared(s => s.version)
|
|
317
338
|
const unread = useShared(s => s.unread)
|
|
339
|
+
const summary = useShared(s => s.summary)
|
|
318
340
|
const linked = useShared(s => s.linked)
|
|
319
|
-
const
|
|
341
|
+
const ui = useShared(s => s.ui)
|
|
342
|
+
const [view, setView] = useState('all')
|
|
320
343
|
const [items, setItems] = useState(null)
|
|
321
344
|
const [more, setMore] = useState(false)
|
|
322
345
|
const [error, setError] = useState(null)
|
|
323
346
|
const [open, setOpen] = useState(() => shared.linked)
|
|
324
|
-
//
|
|
325
|
-
//
|
|
326
|
-
|
|
347
|
+
// Items shown in this view stay where they first showed (their group, and in "Needs you" at all)
|
|
348
|
+
// as they turn read, done or snoozed, so nothing moves under the person's finger; leaving the
|
|
349
|
+
// view (or tapping its filter again) lets them go.
|
|
350
|
+
const placed = useRef(new Map())
|
|
327
351
|
const [visit, setVisit] = useState(0)
|
|
328
|
-
|
|
352
|
+
/** Remember where items first showed: the page's first items in order, later arrivals on top, older pages below. */
|
|
353
|
+
const place = (rows, append) => {
|
|
354
|
+
const ranks = [...placed.current.values()].map(spot => spot.rank)
|
|
355
|
+
let top = Math.min(0, ...ranks)
|
|
356
|
+
let bottom = Math.max(-1, ...ranks)
|
|
357
|
+
const fresh = placed.current.size === 0 || append
|
|
358
|
+
for (const row of fresh ? rows : [...rows].reverse()) {
|
|
359
|
+
if (placed.current.has(row.key)) continue
|
|
360
|
+
placed.current.set(row.key, { group: row.group, rank: fresh ? ++bottom : --top })
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const stream = kit.useEventStream('api/notify-inbox/events', changed)
|
|
329
364
|
|
|
330
|
-
const load = useCallback(async
|
|
365
|
+
const load = useCallback(async append => {
|
|
331
366
|
try {
|
|
332
367
|
const params = new URLSearchParams()
|
|
333
|
-
if (
|
|
334
|
-
params.set('
|
|
335
|
-
if (
|
|
368
|
+
if (view === 'needs-you') {
|
|
369
|
+
params.set('view', 'needs-you')
|
|
370
|
+
if (placed.current.size > 0) params.set('keep', [...placed.current.keys()].join(','))
|
|
336
371
|
}
|
|
337
|
-
if (append && items?.length) params.set('before', items[items.length - 1].
|
|
372
|
+
if (append && items?.length) params.set('before', items[items.length - 1].key)
|
|
338
373
|
const page = await call(`items?${params}`)
|
|
339
|
-
|
|
374
|
+
place(page.items, append)
|
|
340
375
|
setItems(previous => (append && previous ? [...previous, ...page.items] : page.items))
|
|
341
376
|
setMore(page.more)
|
|
342
377
|
setError(null)
|
|
343
378
|
} catch (reason) {
|
|
344
379
|
setError(reason.message)
|
|
345
380
|
}
|
|
346
|
-
}, [
|
|
381
|
+
}, [view, items])
|
|
347
382
|
|
|
348
|
-
useEffect(() => { load(false) }, [
|
|
383
|
+
useEffect(() => { load(false) }, [view, version, visit])
|
|
349
384
|
const showView = key => {
|
|
350
|
-
|
|
351
|
-
if (key ===
|
|
352
|
-
else
|
|
385
|
+
placed.current = new Map()
|
|
386
|
+
if (key === view) setVisit(n => n + 1)
|
|
387
|
+
else setView(key)
|
|
353
388
|
}
|
|
354
389
|
useEffect(() => {
|
|
355
390
|
if (!linked) return
|
|
356
391
|
showView('all')
|
|
357
392
|
setOpen(linked)
|
|
358
393
|
shared.linked = null
|
|
359
|
-
call('
|
|
360
|
-
|
|
394
|
+
call('items').then(page => {
|
|
395
|
+
const item = page.items.find(row => row.ids.includes(linked) || row.key === linked)
|
|
396
|
+
if (item === undefined) return
|
|
397
|
+
setOpen(item.key)
|
|
398
|
+
call('read', { ids: item.ids }).then(changed, () => {})
|
|
399
|
+
setTimeout(() => document.getElementById(`nib-${item.key}`)?.scrollIntoView({ block: 'center' }), 300)
|
|
400
|
+
}, () => {})
|
|
361
401
|
}, [linked])
|
|
362
402
|
|
|
363
403
|
const mark = (item, read) => {
|
|
364
|
-
setItems(list => list.map(row => (row.
|
|
365
|
-
call('read', { ids: [item.id], read }).then(changed, reason => setError(reason.message))
|
|
404
|
+
setItems(list => list.map(row => (row.key === item.key ? { ...row, read } : row)))
|
|
405
|
+
call('read', { ids: read ? item.ids : [item.id], read }).then(changed, reason => setError(reason.message))
|
|
366
406
|
}
|
|
367
407
|
const toggle = item => {
|
|
368
|
-
const next = open === item.
|
|
408
|
+
const next = open === item.key ? null : item.key
|
|
369
409
|
setOpen(next)
|
|
370
410
|
if (next !== null && !item.read) mark(item, true)
|
|
371
411
|
}
|
|
372
412
|
const markAll = () => call('read', { all: true }).then(changed, reason => setError(reason.message))
|
|
373
413
|
|
|
414
|
+
const groups = summary?.groups ?? {}
|
|
415
|
+
const domains = summary?.domains ?? {}
|
|
416
|
+
const total = summary?.total ?? 0
|
|
417
|
+
const byGroup = new Map(GROUPS.map(group => [group, []]))
|
|
418
|
+
for (const item of items ?? []) byGroup.get(placed.current.get(item.key)?.group ?? item.group)?.push(item)
|
|
419
|
+
const rank = item => placed.current.get(item.key)?.rank ?? 0
|
|
420
|
+
for (const list of byGroup.values()) list.sort((a, b) => rank(a) - rank(b))
|
|
421
|
+
const filters = [['needs-you', t('group.needs-you'), groups['needs-you'] ?? 0], ['all', t('filter.all'), total]]
|
|
422
|
+
|
|
374
423
|
return h('div', { className: 'nib-page' },
|
|
375
424
|
h('div', { className: 'nib-scroll' },
|
|
376
425
|
h('div', { className: 'nib-content' },
|
|
377
|
-
h('div', { className: 'nib-
|
|
378
|
-
h('h1', null, t('title')
|
|
379
|
-
h('div', { className: 'nib-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
h(
|
|
426
|
+
h('div', { className: 'nib-heading' },
|
|
427
|
+
h('h1', null, t('title')),
|
|
428
|
+
h('div', { className: 'nib-tools' },
|
|
429
|
+
h(Button, { variant: 'outline', size: 'sm', disabled: unread === 0, onClick: markAll }, t('markAll')),
|
|
430
|
+
h(MoreMenu, { t }))),
|
|
431
|
+
summary?.line && h('p', { className: 'nib-said' }, said(summary.line.text, t)),
|
|
432
|
+
h('div', { className: 'nib-status' },
|
|
433
|
+
h(kit.LiveStatus, { status: stream, updatedAt: summary?.latest ?? undefined }),
|
|
434
|
+
total > 0 && h('span', { className: 'nib-counts' },
|
|
435
|
+
GROUPS.filter(group => (groups[group] ?? 0) > 0).map(group => h('span', { key: group }, `${t(`group.${group}`)} `, h('b', { 'data-group': group }, groups[group]))))),
|
|
436
|
+
h('div', { className: 'nib-filters', role: 'group', 'aria-label': t('filter.label') },
|
|
437
|
+
filters.map(([key, label, n]) => h(Pill, { key, active: view === key, 'aria-pressed': view === key, onClick: () => showView(key) },
|
|
438
|
+
label, n > 0 && h('span', { className: 'nib-n' }, n)))),
|
|
383
439
|
error && h('p', { className: 'nib-error', role: 'alert' }, t('error', { message: error })),
|
|
384
|
-
items !== null && items.length === 0 && h('p', { className: 'nib-empty' }, t(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
440
|
+
items !== null && items.length === 0 && h('p', { className: 'nib-empty' }, t(`empty.${view}`)),
|
|
441
|
+
GROUPS.map(group => byGroup.get(group).length > 0 && h('section', { key: group, className: 'nib-group', 'data-group': group, 'aria-label': t(`group.${group}`) },
|
|
442
|
+
h('div', { className: 'nib-groupHead' },
|
|
443
|
+
h('h2', null, t(`group.${group}`)),
|
|
444
|
+
h('span', { className: 'nib-n' }, byGroup.get(group).length)),
|
|
445
|
+
h('ul', { className: 'nib-list' },
|
|
446
|
+
byGroup.get(group).map(item => h(Item, { key: item.key, item, group, kit, ui, t, domains, open: open === item.key, onToggle: toggle, onMark: mark }))))),
|
|
447
|
+
more && h('div', { className: 'nib-more' }, h(Button, { variant: 'outline', size: 'sm', onClick: () => load(true) }, t('loadMore'))))))
|
|
388
448
|
}
|
|
389
449
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
h('path', { d: 'M6.5 13.2c.3.7.9 1.1 1.5 1.1s1.2-.4 1.5-1.1', ...stroke }))
|
|
450
|
+
/** The bell, from the kit's icons (DSH has none). */
|
|
451
|
+
function BellGlyph({ size }) {
|
|
452
|
+
const kit = useShared(s => s.kit)
|
|
453
|
+
return kit === null ? null : h(kit.Icon, { name: 'bell', size })
|
|
395
454
|
}
|
|
396
455
|
|
|
397
456
|
function SidebarIcon({ size }) {
|
|
398
457
|
const unread = useShared(s => s.unread)
|
|
399
|
-
return h('span', { className: 'nib-
|
|
400
|
-
h(
|
|
458
|
+
return h('span', { className: 'nib-bell' },
|
|
459
|
+
h(BellGlyph, { size }),
|
|
401
460
|
unread > 0 && h('span', { className: 'nib-badge' }, unread > 99 ? '99+' : String(unread)))
|
|
402
461
|
}
|
|
403
462
|
|
|
@@ -425,12 +484,21 @@ window.__ModuleLoader__.load({
|
|
|
425
484
|
return () => tag.remove()
|
|
426
485
|
}, 'notify-inbox: styles')
|
|
427
486
|
|
|
487
|
+
// Shared pieces DSH doesn't have (tiles, time, live status, history): @soffits/dsh-ui-kit.
|
|
488
|
+
ctx.inject(['uiKit'], scope => {
|
|
489
|
+
scope.effect(() => {
|
|
490
|
+
shared.kit = scope.uiKit
|
|
491
|
+
emit()
|
|
492
|
+
return () => { shared.kit = null; emit() }
|
|
493
|
+
}, 'notify-inbox: kit')
|
|
494
|
+
})
|
|
495
|
+
|
|
428
496
|
// The buttons, when @soffits/dsh-ui-actions is installed; without it the page shows no buttons.
|
|
429
497
|
ctx.inject(['uiActions'], scope => {
|
|
430
498
|
scope.effect(() => {
|
|
431
499
|
shared.ui = scope.uiActions
|
|
432
500
|
emit()
|
|
433
|
-
const unregister = scope.uiActions.registerSource({ id: OWNER, name: () => t('panel'), icon:
|
|
501
|
+
const unregister = scope.uiActions.registerSource({ id: OWNER, name: () => t('panel'), icon: BellGlyph })
|
|
434
502
|
return () => { unregister(); shared.ui = null; emit() }
|
|
435
503
|
}, 'notify-inbox: buttons')
|
|
436
504
|
})
|
|
@@ -449,7 +517,8 @@ window.__ModuleLoader__.load({
|
|
|
449
517
|
label: () => t('panel'),
|
|
450
518
|
}, SidebarIcon))
|
|
451
519
|
|
|
452
|
-
// The
|
|
520
|
+
// The counts: checked while the page is visible, right away when it becomes visible, and at
|
|
521
|
+
// once when the events stream says something changed.
|
|
453
522
|
ctx.effect(() => {
|
|
454
523
|
let timer
|
|
455
524
|
const tick = () => {
|
|
@@ -461,7 +530,7 @@ window.__ModuleLoader__.load({
|
|
|
461
530
|
document.addEventListener('visibilitychange', onVisible)
|
|
462
531
|
tick()
|
|
463
532
|
return () => { clearTimeout(timer); document.removeEventListener('visibilitychange', onVisible) }
|
|
464
|
-
}, 'notify-inbox:
|
|
533
|
+
}, 'notify-inbox: counts')
|
|
465
534
|
|
|
466
535
|
// ?notify-inbox=<id> (a tapped push, a shared link) opens the page on that notification.
|
|
467
536
|
const openLinked = id => {
|