@tristan2828/ui-foundation 4.155.1 → 4.156.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/conventions/docs/reminders.md +114 -5
- package/conventions/docs/timed-screens.md +11 -4
- package/dist/api/gateway/push.d.ts +12 -0
- package/dist/api/gateway/push.js +32 -0
- package/dist/api/schema.d.ts +132 -2
- package/dist/components/app/allow-reminders.js +2 -1
- package/dist/components/app/notification-settings.d.ts +38 -0
- package/dist/components/app/notification-settings.js +128 -0
- package/dist/components/app/push-status-words.d.ts +27 -0
- package/dist/components/app/push-status-words.js +14 -0
- package/dist/hooks/use-push-devices.d.ts +37 -0
- package/dist/hooks/use-push-devices.js +72 -0
- package/dist/hooks/use-push-permission.d.ts +26 -3
- package/dist/hooks/use-push-permission.js +59 -7
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/lib/audio-cues.d.ts +7 -1
- package/dist/lib/audio-cues.js +36 -2
- package/dist/lib/push-endpoint-hash.d.ts +6 -0
- package/dist/lib/push-endpoint-hash.js +12 -0
- package/dist/mocks/index.d.ts +1 -1
- package/dist/mocks/index.js +1 -1
- package/dist/mocks/push.d.ts +8 -0
- package/dist/mocks/push.js +60 -9
- package/openapi/foundation.yaml +119 -2
- package/package.json +1 -1
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Reminders
|
|
2
2
|
|
|
3
|
+
<!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
|
|
4
|
+
## Index
|
|
5
|
+
|
|
6
|
+
- [Allowing reminders](#allowing-reminders) · lines 40–72
|
|
7
|
+
- [A settings page: this device, a test and the devices](#a-settings-page-this-device-a-test-and-the-devices) · lines 74–146
|
|
8
|
+
- [On iPhone and iPad](#on-iphone-and-ipad) · lines 148–154
|
|
9
|
+
- [The app's own icon](#the-apps-own-icon) · lines 156–186
|
|
10
|
+
- [Home-screen shortcuts](#home-screen-shortcuts) · lines 188–204
|
|
11
|
+
- [A reminder is the app's own row](#a-reminder-is-the-apps-own-row) · lines 206–261
|
|
12
|
+
- [Repeating reminders](#repeating-reminders) · lines 263–340
|
|
13
|
+
- [A Done button on the notification](#a-done-button-on-the-notification) · lines 342–385
|
|
14
|
+
- [Testing](#testing) · lines 387–403
|
|
15
|
+
|
|
16
|
+
<!-- /index -->
|
|
17
|
+
|
|
3
18
|
A notification at a time the user chose ("time for your morning routine",
|
|
4
19
|
"a short break at 3 pm", a habit, a medication) that reaches them with the
|
|
5
20
|
app closed. It's Web Push: the browser subscribes with its push service
|
|
@@ -12,7 +27,9 @@ to the device, where the app's service worker shows it.
|
|
|
12
27
|
| `pwa({ name })` | `vite.config.ts`, from `@tristan2828/ui-foundation/vite` | The app installable: a manifest, icons in the theme's colours (or the app's own), and `/push-sw.js`, the service worker that shows pushes and opens their path |
|
|
13
28
|
| `usePushPermission()` | the package | Whether this device gets reminders, and `enable`/`disable` |
|
|
14
29
|
| `AllowReminders` | the package | The control: says what reminders are, then asks, on a click |
|
|
15
|
-
|
|
|
30
|
+
| `ThisDeviceSetting`, `TestNotificationSetting`, `NotificationDevices` | the package | A settings page's rows: this device's switch, a test send to it, and the account's devices (renamed, removed) |
|
|
31
|
+
| `usePushDevices(push)` | the package | The account's devices for those rows, this one marked: `rename`, `remove`, `sendTest` |
|
|
32
|
+
| `/push/public-key`, `/push/subscriptions`, `/push/subscriptions/{id}`, `/push/subscriptions/{id}/test` | `openapi.yaml`, the foundation's part (optional) | The VAPID key to subscribe with; this device's subscription saved or dropped; the devices listed and renamed; a test sent |
|
|
16
33
|
| `foundation_backend.push` | `ui-foundation-backend` | `send_push(session, user_id, title, body, url)`: encrypted (RFC 8291), signed (VAPID), to every device the user allowed; optionally a `PushAction` button and `renotify` |
|
|
17
34
|
| `foundation_backend.reminders`, `reminders` | `ui-foundation-backend` | A reminder row (when, which days, the text, the path), and the `send-reminders` job that sends each one when it's due |
|
|
18
35
|
|
|
@@ -44,6 +61,89 @@ const push = usePushPermission()
|
|
|
44
61
|
| `blocked` | The person said no | Where to allow it again |
|
|
45
62
|
| `unsupported` | No push in this browser | That it can't |
|
|
46
63
|
| `mock` | The app runs on MSW | That reminders need the real backend |
|
|
64
|
+
| `unavailable` | The backend has push turned off (`GET /push/subscriptions` is a 404) | That the app's server doesn't send notifications yet |
|
|
65
|
+
|
|
66
|
+
`unavailable` is a status added after the first six: code of the app's
|
|
67
|
+
own that switches over `PushStatus` gives it a case.
|
|
68
|
+
|
|
69
|
+
A device removed from another one (the list below) is found the next
|
|
70
|
+
time `usePushPermission` works its status out: the browser is still
|
|
71
|
+
subscribed, but the account's list hasn't got it, so it unsubscribes
|
|
72
|
+
quietly and reads `off`. Nothing is ever sent to it.
|
|
73
|
+
|
|
74
|
+
## A settings page: this device, a test and the devices
|
|
75
|
+
|
|
76
|
+
Three rows of a settings page (design-language.md "A settings page"), in
|
|
77
|
+
one `SettingsCard`:
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import {
|
|
81
|
+
NotificationDevices,
|
|
82
|
+
SettingsCard,
|
|
83
|
+
TestNotificationSetting,
|
|
84
|
+
ThisDeviceSetting,
|
|
85
|
+
usePushPermission,
|
|
86
|
+
} from '@tristan2828/ui-foundation'
|
|
87
|
+
|
|
88
|
+
const push = usePushPermission()
|
|
89
|
+
<SettingsCard>
|
|
90
|
+
<ThisDeviceSetting push={push} />
|
|
91
|
+
<TestNotificationSetting push={push} />
|
|
92
|
+
<NotificationDevices push={push} />
|
|
93
|
+
</SettingsCard>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- **`ThisDeviceSetting`**, "On This Device": a switch that asks the
|
|
97
|
+
browser only from its click. Where it can't be switched (`blocked`,
|
|
98
|
+
`needs-install`, `unsupported`, `mock`, `unavailable`) it is off and
|
|
99
|
+
disabled, and its help line says what to do: the same words
|
|
100
|
+
`AllowReminders` shows.
|
|
101
|
+
- **`TestNotificationSetting`**, "Send a Test": one notification to this
|
|
102
|
+
device, opening the page it was sent from (`url` to say otherwise). Its
|
|
103
|
+
answer is on its own help line, with no toast: sent, "Wait N seconds
|
|
104
|
+
and try again", or that the device can't be reached any more (its push
|
|
105
|
+
service said it's gone, so the backend deleted it).
|
|
106
|
+
- **`NotificationDevices`**, "Devices": the account's devices, this one
|
|
107
|
+
first and marked This Device, then the newest. Each name is edited in
|
|
108
|
+
place (1 to 60 characters, ✓ Saved); one saved before names reads
|
|
109
|
+
"Unknown device". Each shows "Added Nov 25, 2026" and Remove, a hard
|
|
110
|
+
delete's confirm ("Removed iPhone, Safari"). Removing this device turns
|
|
111
|
+
it off; another stops getting notifications at once and turns itself off
|
|
112
|
+
the next time it opens. The list has its four states (loading, empty,
|
|
113
|
+
an error with Try again, the devices); `unavailable` says so, and isn't
|
|
114
|
+
an error.
|
|
115
|
+
- The rows share one request for the list with `usePushPermission`'s
|
|
116
|
+
status check. Each fetches it itself; a story or test passes
|
|
117
|
+
`devices` (usePushDevices' shape) to show any state.
|
|
118
|
+
- The names edit inside the page's `EditInPlaceScope` when there is one,
|
|
119
|
+
and inside their own otherwise. Either needs the data router every app
|
|
120
|
+
has.
|
|
121
|
+
|
|
122
|
+
What the backend does:
|
|
123
|
+
|
|
124
|
+
| Route | Does | Refuses |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| `GET /push/subscriptions` | The user's devices, newest first: `id`, `name`, `createdAt`, `endpointHash`. Never an endpoint or a key | 404 with push off |
|
|
127
|
+
| `PATCH /push/subscriptions/{id}` | Renames it, trimmed | 422 under 1 or over 60 characters; 404 for another user's |
|
|
128
|
+
| `POST /push/subscriptions/{id}/test` | One notification ("Test notification") to that device only, opening `url` (the app's own path) | 404 for another user's, or one its push service says is gone (deleted); 429 with `Retry-After` after 5 a minute per user; 502 when the push service refuses it otherwise |
|
|
129
|
+
|
|
130
|
+
- **Names**: a new device is named from its request's User-Agent, as
|
|
131
|
+
"<platform>, <browser>" (`foundation_backend.push.device_name`):
|
|
132
|
+
"iPhone, Safari", "iPhone, Home Screen app" (the installed app says no
|
|
133
|
+
browser), "Android, Samsung Internet", "Windows, Edge", "Mac, Firefox",
|
|
134
|
+
"Chromebook, Chrome". Whichever half is known, or no name. An iPad that
|
|
135
|
+
reports itself as a Mac is "Mac, Safari"; the user can rename it.
|
|
136
|
+
- **Subscribing again** (new keys, or `disable()` learning its id) keeps
|
|
137
|
+
the name and when the device was first added, and names a device that
|
|
138
|
+
had none. `created_at` is when it was first added.
|
|
139
|
+
- **This Device** is found by hash: the browser hashes its own
|
|
140
|
+
subscription's endpoint (SHA-256, base64url, no padding; the package's
|
|
141
|
+
`hashEndpoint`) and finds the row with that `endpointHash`.
|
|
142
|
+
- **The column**: `push_subscriptions.name` (varchar 60, null), with its
|
|
143
|
+
comment, and `created_at`'s comment rewritten. The backend package's
|
|
144
|
+
reference migration is `migrations/0016_push_device_names.py`; copy it
|
|
145
|
+
into the app's own chain, renumbered (the template carries it as
|
|
146
|
+
`0019_push_device_names.py`).
|
|
47
147
|
|
|
48
148
|
## On iPhone and iPad
|
|
49
149
|
|
|
@@ -288,7 +388,16 @@ reminders.register(
|
|
|
288
388
|
|
|
289
389
|
Under MSW the page is held by MSW's service worker, so `usePushPermission`
|
|
290
390
|
reads `mock` and never subscribes: screens show the `mock` state, and a
|
|
291
|
-
Playwright spec checks it the same way. The
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
`
|
|
391
|
+
Playwright spec checks it the same way. The device list works under MSW:
|
|
392
|
+
`seedMockPushDevices([{ name, createdAt }])` (from the package's
|
|
393
|
+
`/mocks`) puts devices in it, none of them This Device, and
|
|
394
|
+
`resetMockPush()` clears them. A 404 for `GET /push/subscriptions` (an MSW
|
|
395
|
+
override) shows `unavailable`. Send a Test can't be pressed there (the
|
|
396
|
+
status is `mock`); its answers are the package's own tests. The rest is
|
|
397
|
+
the backend's: its tests decrypt every message as a browser would.
|
|
398
|
+
|
|
399
|
+
To try it end to end, run the real backend with push on, turn
|
|
400
|
+
notifications on in the browser, and press Send a Test on the settings
|
|
401
|
+
page. `python -m foundation_backend.scripts.send_test_push <email>` (from
|
|
402
|
+
`backend/`) still sends to every device of an account, for a check on the
|
|
403
|
+
server itself.
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
- [The dark stage](#the-dark-stage) · lines 74–109
|
|
8
8
|
- [The clock](#the-clock) · lines 111–141
|
|
9
9
|
- [Sound](#sound) · lines 143–192
|
|
10
|
-
- [Background tabs](#background-tabs) · lines 194–
|
|
11
|
-
- [Interruptions](#interruptions) · lines 228–
|
|
12
|
-
- [Motion](#motion) · lines
|
|
13
|
-
- [Testing a timed screen in Playwright](#testing-a-timed-screen-in-playwright) · lines
|
|
10
|
+
- [Background tabs](#background-tabs) · lines 194–255
|
|
11
|
+
- [Interruptions](#interruptions) · lines 228–255
|
|
12
|
+
- [Motion](#motion) · lines 257–261
|
|
13
|
+
- [Testing a timed screen in Playwright](#testing-a-timed-screen-in-playwright) · lines 263–415
|
|
14
14
|
|
|
15
15
|
<!-- /index -->
|
|
16
16
|
|
|
@@ -247,6 +247,13 @@ its run is now, so it rebooks:
|
|
|
247
247
|
for where no recovery was announced: when it's false, `cancelCues()` and
|
|
248
248
|
book again.
|
|
249
249
|
|
|
250
|
+
**Speech is the one wait.** A line from `say()` starting to speak is itself
|
|
251
|
+
what stops the context, and resuming it then cuts the line off partway, so
|
|
252
|
+
while a line is being spoken the resume waits for its end (or `hush()`, or
|
|
253
|
+
a fallback a few seconds past its length). A chime due while the line
|
|
254
|
+
speaks stays silent, as it already did while the context stood still; the
|
|
255
|
+
recovery after the line rebooks from there on.
|
|
256
|
+
|
|
250
257
|
## Motion
|
|
251
258
|
|
|
252
259
|
`usePrefersReducedMotion()` is true while the person's system asks for
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { components } from "../schema.js";
|
|
2
2
|
export type PushSubscriptionRequest = components["schemas"]["PushSubscriptionRequest"];
|
|
3
|
+
/** One device on the account that gets notifications. Never its endpoint or keys. */
|
|
4
|
+
export type PushDevice = components["schemas"]["PushDevice"];
|
|
3
5
|
/** The key to subscribe with. A 404 is a backend with push turned off. */
|
|
4
6
|
export declare function getPushPublicKey(): Promise<string>;
|
|
5
7
|
/** Saves the subscription; the same device again answers the same id. */
|
|
6
8
|
export declare function savePushSubscription(subscription: PushSubscriptionRequest): Promise<number>;
|
|
7
9
|
/** Already gone (404) counts as done. */
|
|
8
10
|
export declare function deletePushSubscription(id: number): Promise<void>;
|
|
11
|
+
/** The signed-in user's devices, newest first. A 404 is a backend with push turned off. */
|
|
12
|
+
export declare function listPushDevices(): Promise<PushDevice[]>;
|
|
13
|
+
/** Renames one; 1 to 60 characters once trimmed (a 422 otherwise). */
|
|
14
|
+
export declare function renamePushDevice(id: number, name: string): Promise<PushDevice>;
|
|
15
|
+
/**
|
|
16
|
+
* One notification to that device, opening `url` (the app's own path).
|
|
17
|
+
* A 404 is a device that can't be reached any more (the backend deleted
|
|
18
|
+
* it); a 429 is `rate_limited` with `retryAfterSeconds`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sendTestPush(id: number, url: string): Promise<void>;
|
package/dist/api/gateway/push.js
CHANGED
|
@@ -23,3 +23,35 @@ export async function deletePushSubscription(id) {
|
|
|
23
23
|
if (res.status !== 204 && res.status !== 404)
|
|
24
24
|
throw toAppError(res.status, res.body, res.headers);
|
|
25
25
|
}
|
|
26
|
+
/** The signed-in user's devices, newest first. A 404 is a backend with push turned off. */
|
|
27
|
+
export async function listPushDevices() {
|
|
28
|
+
const res = await safeFetch("/push/subscriptions");
|
|
29
|
+
if (res.status !== 200)
|
|
30
|
+
throw toAppError(res.status, res.body, res.headers);
|
|
31
|
+
return res.body;
|
|
32
|
+
}
|
|
33
|
+
/** Renames one; 1 to 60 characters once trimmed (a 422 otherwise). */
|
|
34
|
+
export async function renamePushDevice(id, name) {
|
|
35
|
+
const res = await safeFetch(`/push/subscriptions/${id}`, {
|
|
36
|
+
method: "PATCH",
|
|
37
|
+
headers: { "content-type": "application/json" },
|
|
38
|
+
body: JSON.stringify({ name }),
|
|
39
|
+
});
|
|
40
|
+
if (res.status !== 200)
|
|
41
|
+
throw toAppError(res.status, res.body, res.headers);
|
|
42
|
+
return res.body;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* One notification to that device, opening `url` (the app's own path).
|
|
46
|
+
* A 404 is a device that can't be reached any more (the backend deleted
|
|
47
|
+
* it); a 429 is `rate_limited` with `retryAfterSeconds`.
|
|
48
|
+
*/
|
|
49
|
+
export async function sendTestPush(id, url) {
|
|
50
|
+
const res = await safeFetch(`/push/subscriptions/${id}/test`, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: { "content-type": "application/json" },
|
|
53
|
+
body: JSON.stringify({ url }),
|
|
54
|
+
});
|
|
55
|
+
if (res.status !== 204)
|
|
56
|
+
throw toAppError(res.status, res.body, res.headers);
|
|
57
|
+
}
|
package/dist/api/schema.d.ts
CHANGED
|
@@ -158,11 +158,15 @@ export interface paths {
|
|
|
158
158
|
path?: never;
|
|
159
159
|
cookie?: never;
|
|
160
160
|
};
|
|
161
|
-
|
|
161
|
+
/**
|
|
162
|
+
* The signed-in user's devices that get notifications, newest first
|
|
163
|
+
* @description Never an endpoint or a key: a browser finds its own device by endpointHash. A plain array (a user has at most 20). 404 when the backend has push turned off.
|
|
164
|
+
*/
|
|
165
|
+
get: operations["listPushDevices"];
|
|
162
166
|
put?: never;
|
|
163
167
|
/**
|
|
164
168
|
* Save this device's push subscription for the signed-in user
|
|
165
|
-
* @description The browser's PushSubscription.toJSON(). The same endpoint again replaces its keys and owner and answers the same id. The endpoint must be a push service's (422 otherwise): the backend POSTs to it.
|
|
169
|
+
* @description The browser's PushSubscription.toJSON(). The same endpoint again replaces its keys and owner, keeps its name and when it was first added, and answers the same id. A new device is named from the request's User-Agent. The endpoint must be a push service's (422 otherwise): the backend POSTs to it.
|
|
166
170
|
*/
|
|
167
171
|
post: operations["savePushSubscription"];
|
|
168
172
|
delete?: never;
|
|
@@ -185,6 +189,30 @@ export interface paths {
|
|
|
185
189
|
delete: operations["deletePushSubscription"];
|
|
186
190
|
options?: never;
|
|
187
191
|
head?: never;
|
|
192
|
+
/**
|
|
193
|
+
* Rename one of the signed-in user's devices
|
|
194
|
+
* @description The name is trimmed, then 1 to 60 characters (422 otherwise). 404 for another user's device.
|
|
195
|
+
*/
|
|
196
|
+
patch: operations["renamePushDevice"];
|
|
197
|
+
trace?: never;
|
|
198
|
+
};
|
|
199
|
+
"/push/subscriptions/{id}/test": {
|
|
200
|
+
parameters: {
|
|
201
|
+
query?: never;
|
|
202
|
+
header?: never;
|
|
203
|
+
path?: never;
|
|
204
|
+
cookie?: never;
|
|
205
|
+
};
|
|
206
|
+
get?: never;
|
|
207
|
+
put?: never;
|
|
208
|
+
/**
|
|
209
|
+
* Send one test notification to one of the signed-in user's devices
|
|
210
|
+
* @description To that device only. 404 for another user's device, or for one its push service says is gone (its row is deleted). 429 after 5 a minute per user. 502 when the push service refused it for another reason.
|
|
211
|
+
*/
|
|
212
|
+
post: operations["sendTestPush"];
|
|
213
|
+
delete?: never;
|
|
214
|
+
options?: never;
|
|
215
|
+
head?: never;
|
|
188
216
|
patch?: never;
|
|
189
217
|
trace?: never;
|
|
190
218
|
};
|
|
@@ -259,6 +287,25 @@ export interface components {
|
|
|
259
287
|
PushSubscriptionCreated: {
|
|
260
288
|
id: number;
|
|
261
289
|
};
|
|
290
|
+
PushDevice: {
|
|
291
|
+
id: number;
|
|
292
|
+
/** @description What the device is called: from its user agent when first saved ("iPhone, Home Screen app"), or as renamed. null for a device saved before names. */
|
|
293
|
+
name: string | null;
|
|
294
|
+
/**
|
|
295
|
+
* Format: date-time
|
|
296
|
+
* @description When the device was first added. Subscribing again keeps it.
|
|
297
|
+
*/
|
|
298
|
+
createdAt: string;
|
|
299
|
+
/** @description The endpoint's SHA-256, base64url without padding: how a browser finds its own device here without the list holding endpoints. */
|
|
300
|
+
endpointHash: string;
|
|
301
|
+
};
|
|
302
|
+
PushDeviceRename: {
|
|
303
|
+
name: string;
|
|
304
|
+
};
|
|
305
|
+
PushTestRequest: {
|
|
306
|
+
/** @description The app's own path the notification opens, starting with one /. */
|
|
307
|
+
url: string;
|
|
308
|
+
};
|
|
262
309
|
/** @description A repeating schedule (RecurrenceField, foundation_backend.recurrence). The rule's days, each at every one of its times, read in its zone. */
|
|
263
310
|
Recurrence: {
|
|
264
311
|
/** @description RFC 5545's RRULE value, without DTSTART: FREQ (daily, weekly, monthly, yearly), INTERVAL, BYMONTH, BYMONTHDAY (-1 is the last day), BYDAY (an nth for monthly and yearly: 2TU, -1FR), UNTIL (a date, YYYYMMDD, the last day it can fall on) or COUNT (occurrences, each time of each day), and WKST (the day weeks start on, MO when left out: it moves an every-N-weeks rule's weeks). "FREQ=MONTHLY;BYDAY=2TU", "FREQ=WEEKLY;INTERVAL=2;BYDAY=SU,WE;WKST=SU". */
|
|
@@ -567,6 +614,29 @@ export interface operations {
|
|
|
567
614
|
500: components["responses"]["ServerError"];
|
|
568
615
|
};
|
|
569
616
|
};
|
|
617
|
+
listPushDevices: {
|
|
618
|
+
parameters: {
|
|
619
|
+
query?: never;
|
|
620
|
+
header?: never;
|
|
621
|
+
path?: never;
|
|
622
|
+
cookie?: never;
|
|
623
|
+
};
|
|
624
|
+
requestBody?: never;
|
|
625
|
+
responses: {
|
|
626
|
+
/** @description OK. */
|
|
627
|
+
200: {
|
|
628
|
+
headers: {
|
|
629
|
+
[name: string]: unknown;
|
|
630
|
+
};
|
|
631
|
+
content: {
|
|
632
|
+
"application/json": components["schemas"]["PushDevice"][];
|
|
633
|
+
};
|
|
634
|
+
};
|
|
635
|
+
401: components["responses"]["UnauthorizedError"];
|
|
636
|
+
404: components["responses"]["NotFoundError"];
|
|
637
|
+
500: components["responses"]["ServerError"];
|
|
638
|
+
};
|
|
639
|
+
};
|
|
570
640
|
savePushSubscription: {
|
|
571
641
|
parameters: {
|
|
572
642
|
query?: never;
|
|
@@ -618,4 +688,64 @@ export interface operations {
|
|
|
618
688
|
500: components["responses"]["ServerError"];
|
|
619
689
|
};
|
|
620
690
|
};
|
|
691
|
+
renamePushDevice: {
|
|
692
|
+
parameters: {
|
|
693
|
+
query?: never;
|
|
694
|
+
header?: never;
|
|
695
|
+
path: {
|
|
696
|
+
id: number;
|
|
697
|
+
};
|
|
698
|
+
cookie?: never;
|
|
699
|
+
};
|
|
700
|
+
requestBody: {
|
|
701
|
+
content: {
|
|
702
|
+
"application/json": components["schemas"]["PushDeviceRename"];
|
|
703
|
+
};
|
|
704
|
+
};
|
|
705
|
+
responses: {
|
|
706
|
+
/** @description Renamed. */
|
|
707
|
+
200: {
|
|
708
|
+
headers: {
|
|
709
|
+
[name: string]: unknown;
|
|
710
|
+
};
|
|
711
|
+
content: {
|
|
712
|
+
"application/json": components["schemas"]["PushDevice"];
|
|
713
|
+
};
|
|
714
|
+
};
|
|
715
|
+
401: components["responses"]["UnauthorizedError"];
|
|
716
|
+
404: components["responses"]["NotFoundError"];
|
|
717
|
+
422: components["responses"]["ValidationError"];
|
|
718
|
+
500: components["responses"]["ServerError"];
|
|
719
|
+
};
|
|
720
|
+
};
|
|
721
|
+
sendTestPush: {
|
|
722
|
+
parameters: {
|
|
723
|
+
query?: never;
|
|
724
|
+
header?: never;
|
|
725
|
+
path: {
|
|
726
|
+
id: number;
|
|
727
|
+
};
|
|
728
|
+
cookie?: never;
|
|
729
|
+
};
|
|
730
|
+
requestBody: {
|
|
731
|
+
content: {
|
|
732
|
+
"application/json": components["schemas"]["PushTestRequest"];
|
|
733
|
+
};
|
|
734
|
+
};
|
|
735
|
+
responses: {
|
|
736
|
+
/** @description Taken by the device's push service. */
|
|
737
|
+
204: {
|
|
738
|
+
headers: {
|
|
739
|
+
[name: string]: unknown;
|
|
740
|
+
};
|
|
741
|
+
content?: never;
|
|
742
|
+
};
|
|
743
|
+
401: components["responses"]["UnauthorizedError"];
|
|
744
|
+
404: components["responses"]["NotFoundError"];
|
|
745
|
+
422: components["responses"]["ValidationError"];
|
|
746
|
+
429: components["responses"]["RateLimitedError"];
|
|
747
|
+
500: components["responses"]["ServerError"];
|
|
748
|
+
502: components["responses"]["ServerError"];
|
|
749
|
+
};
|
|
750
|
+
};
|
|
621
751
|
}
|
|
@@ -4,8 +4,9 @@ import { cn } from 'cn';
|
|
|
4
4
|
import { Button } from '../ui/button.js';
|
|
5
5
|
import { Skeleton } from '../ui/skeleton.js';
|
|
6
6
|
import { Notice } from './notice.js';
|
|
7
|
+
import { PUSH_STATUS_WORDS } from './push-status-words.js';
|
|
7
8
|
const DEFAULT_DESCRIPTION = 'Get a notification on this device at the times you set, even when the app is closed. Your browser will ask first.';
|
|
8
9
|
export function AllowReminders({ push, description = DEFAULT_DESCRIPTION, className }) {
|
|
9
10
|
const { status, pending, error } = push;
|
|
10
|
-
return (_jsxs("div", { "data-slot": "allow-reminders", className: cn('flex flex-col gap-3', className), "aria-busy": status === undefined || pending, children: [status === undefined && _jsx(Skeleton, { className: "h-9 w-full max-w-md" }), status === 'off' && (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm text-foreground", children: description }), _jsx("div", { children: _jsxs(Button, { onClick: push.enable, disabled: pending, children: [_jsx(BellIcon, { "aria-hidden": "true" }), pending ? 'Turning on…' : 'Allow Reminders'] }) })] })), status === 'on' && (_jsx(Notice, { tone: "success", icon: BellIcon, action: _jsxs(Button, { size: "sm", variant: "outline", onClick: push.disable, disabled: pending, children: [_jsx(BellOffIcon, { "aria-hidden": "true" }), pending ? 'Turning off…' : 'Turn Off'] }), children: "Reminders are on for this device." })), status === 'needs-install' && (_jsx(Notice, { title:
|
|
11
|
+
return (_jsxs("div", { "data-slot": "allow-reminders", className: cn('flex flex-col gap-3', className), "aria-busy": status === undefined || pending, children: [status === undefined && _jsx(Skeleton, { className: "h-9 w-full max-w-md" }), status === 'off' && (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm text-foreground", children: description }), _jsx("div", { children: _jsxs(Button, { onClick: push.enable, disabled: pending, children: [_jsx(BellIcon, { "aria-hidden": "true" }), pending ? 'Turning on…' : 'Allow Reminders'] }) })] })), status === 'on' && (_jsx(Notice, { tone: "success", icon: BellIcon, action: _jsxs(Button, { size: "sm", variant: "outline", onClick: push.disable, disabled: pending, children: [_jsx(BellOffIcon, { "aria-hidden": "true" }), pending ? 'Turning off…' : 'Turn Off'] }), children: "Reminders are on for this device." })), status === 'needs-install' && (_jsx(Notice, { title: PUSH_STATUS_WORDS['needs-install'].title, children: PUSH_STATUS_WORDS['needs-install'].text })), status === 'blocked' && (_jsx(Notice, { tone: "warning", title: PUSH_STATUS_WORDS.blocked.title, icon: BellOffIcon, children: PUSH_STATUS_WORDS.blocked.text })), (status === 'unsupported' || status === 'mock' || status === 'unavailable') && (_jsx("p", { className: "text-sm text-muted-foreground", children: PUSH_STATUS_WORDS[status].text })), error && (_jsx("p", { role: "alert", className: "text-sm text-destructive-text", children: error }))] }));
|
|
11
12
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type PushDevices } from '../../hooks/use-push-devices.js';
|
|
3
|
+
import type { PushPermission } from '../../hooks/use-push-permission.js';
|
|
4
|
+
export type ThisDeviceSettingProps = {
|
|
5
|
+
/** usePushPermission()'s result. */
|
|
6
|
+
push: PushPermission;
|
|
7
|
+
/** Defaults to "On This Device". */
|
|
8
|
+
label?: string;
|
|
9
|
+
/** The help line while it can be switched; defaults to what it does. */
|
|
10
|
+
help?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/** This device's notifications as a settings row with a switch, turned on from its click. */
|
|
13
|
+
export declare function ThisDeviceSetting({ push, label, help }: ThisDeviceSettingProps): import("react").JSX.Element;
|
|
14
|
+
export type TestNotificationSettingProps = {
|
|
15
|
+
push: PushPermission;
|
|
16
|
+
/** The app's own path the notification opens. Defaults to this page's. */
|
|
17
|
+
url?: string;
|
|
18
|
+
/** usePushDevices(push)'s result; left out, it's fetched. */
|
|
19
|
+
devices?: PushDevices;
|
|
20
|
+
/** Defaults to "Send a Test". */
|
|
21
|
+
label?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Send a Test: one notification to this device, its result on the row's own line. */
|
|
24
|
+
export declare function TestNotificationSetting({ devices, label, ...props }: TestNotificationSettingProps): import("react").JSX.Element;
|
|
25
|
+
export type NotificationDevicesProps = {
|
|
26
|
+
push: PushPermission;
|
|
27
|
+
/** usePushDevices(push)'s result; left out, it's fetched. */
|
|
28
|
+
devices?: PushDevices;
|
|
29
|
+
/** Defaults to "Devices". */
|
|
30
|
+
label?: string;
|
|
31
|
+
help?: ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The account's devices that get notifications, as a settings row with the
|
|
35
|
+
* list under its label: each named (renamed in place), when it was added,
|
|
36
|
+
* This Device on this one, and Remove.
|
|
37
|
+
*/
|
|
38
|
+
export declare function NotificationDevices({ push, devices, label, help }: NotificationDevicesProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Notifications as rows of a settings page (design-language.md "A settings
|
|
3
|
+
// page"): this device's switch (ThisDeviceSetting), a test send to it
|
|
4
|
+
// (TestNotificationSetting) and the account's devices (NotificationDevices),
|
|
5
|
+
// each a SettingsRow, in one SettingsCard the app puts them in:
|
|
6
|
+
//
|
|
7
|
+
// const push = usePushPermission()
|
|
8
|
+
// <SettingsCard>
|
|
9
|
+
// <ThisDeviceSetting push={push} />
|
|
10
|
+
// <TestNotificationSetting push={push} />
|
|
11
|
+
// <NotificationDevices push={push} />
|
|
12
|
+
// </SettingsCard>
|
|
13
|
+
//
|
|
14
|
+
// - The switch asks the browser only from its click (Safari shows the
|
|
15
|
+
// prompt only then). Where it can't be turned on (blocked, needs-install,
|
|
16
|
+
// unsupported, mock, unavailable) it is off and disabled, and its help
|
|
17
|
+
// line is PUSH_STATUS_WORDS', the words AllowReminders shows.
|
|
18
|
+
// - Send a Test answers on its own help line, in place, with no toast:
|
|
19
|
+
// sent, wait N seconds, can't be reached, or the failure.
|
|
20
|
+
// - Each device: its name edited in place (✓ Saved; a device saved before
|
|
21
|
+
// names reads "Unknown device"), This Device on this browser's own,
|
|
22
|
+
// "Added <date>" and Remove, a hard delete's confirm. Removing this
|
|
23
|
+
// device turns it off. The list has its four states; push off on the
|
|
24
|
+
// server says so, and isn't an error.
|
|
25
|
+
// - `devices` (usePushDevices' result) lets a story or test show any
|
|
26
|
+
// state; left out, each part fetches it.
|
|
27
|
+
import { useContext, useId, useState } from 'react';
|
|
28
|
+
import { SendIcon } from 'lucide-react';
|
|
29
|
+
import { Badge } from '../ui/badge.js';
|
|
30
|
+
import { Button } from '../ui/button.js';
|
|
31
|
+
import { Skeleton } from '../ui/skeleton.js';
|
|
32
|
+
import { Switch } from '../ui/switch.js';
|
|
33
|
+
import { usePushDevices } from '../../hooks/use-push-devices.js';
|
|
34
|
+
import { DeleteAction } from './delete-action.js';
|
|
35
|
+
import { EditInPlaceContext } from './edit-in-place.js';
|
|
36
|
+
import { inPlace } from './edit-in-place-presets.js';
|
|
37
|
+
import { EditInPlaceScope } from './edit-in-place-scope.js';
|
|
38
|
+
import { EditableValue } from './editable-value.js';
|
|
39
|
+
import { ErrorState } from './error-state.js';
|
|
40
|
+
import { hasStatusWords, PUSH_STATUS_WORDS } from './push-status-words.js';
|
|
41
|
+
import { SettingsRow } from './settings-page.js';
|
|
42
|
+
const THIS_DEVICE_HELP = 'Notifications reach this browser, even with the app closed. Your browser asks first.';
|
|
43
|
+
/** This device's notifications as a settings row with a switch, turned on from its click. */
|
|
44
|
+
export function ThisDeviceSetting({ push, label = 'On This Device', help = THIS_DEVICE_HELP }) {
|
|
45
|
+
const id = useId();
|
|
46
|
+
const { status, pending, error } = push;
|
|
47
|
+
const switchable = status === 'on' || status === 'off';
|
|
48
|
+
return (_jsx(SettingsRow, { label: label, htmlFor: id, help: _jsxs(_Fragment, { children: [hasStatusWords(status) ? PUSH_STATUS_WORDS[status].text : help, error && (_jsx("span", { role: "alert", className: "block text-destructive-text", children: error }))] }), control: (aria) => status === undefined ? (_jsx(Skeleton, { "data-slot": "this-device-loading", className: "h-[--spacing(4.6)] w-8 rounded-full" })) : (_jsx(Switch, { ...aria, id: id, checked: status === 'on', disabled: !switchable || pending, "aria-busy": pending || undefined,
|
|
49
|
+
// Straight from the click: Safari shows the prompt only in it.
|
|
50
|
+
onCheckedChange: (on) => (on ? push.enable() : push.disable()) })) }));
|
|
51
|
+
}
|
|
52
|
+
function testLine(result, on) {
|
|
53
|
+
if (!on)
|
|
54
|
+
return { text: 'Turn on notifications for this device first.' };
|
|
55
|
+
if (result.state === 'sent')
|
|
56
|
+
return { text: 'Sent. It should arrive in a few seconds.' };
|
|
57
|
+
if (result.state !== 'failed')
|
|
58
|
+
return { text: 'A notification to this device now.' };
|
|
59
|
+
const { error } = result;
|
|
60
|
+
if (error.kind === 'rate_limited')
|
|
61
|
+
return { text: `Wait ${error.retryAfterSeconds ?? 60} seconds and try again.` };
|
|
62
|
+
if (error.kind === 'notfound')
|
|
63
|
+
return { text: 'This device can’t be reached any more. Turn it off and on again.' };
|
|
64
|
+
return { text: error.message, alert: true };
|
|
65
|
+
}
|
|
66
|
+
function TestNotificationRow({ push, url, devices, label }) {
|
|
67
|
+
const [result, setResult] = useState({ state: 'idle' });
|
|
68
|
+
const on = push.status === 'on';
|
|
69
|
+
const line = testLine(result, on);
|
|
70
|
+
const send = async () => {
|
|
71
|
+
setResult({ state: 'sending' });
|
|
72
|
+
try {
|
|
73
|
+
await devices.sendTest(url ?? location.pathname);
|
|
74
|
+
setResult({ state: 'sent' });
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
setResult({ state: 'failed', error: error });
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return (_jsx(SettingsRow, { label: label, help: _jsx("span", { "data-slot": "test-notification-result", role: line.alert ? 'alert' : 'status', className: line.alert ? 'text-destructive-text' : undefined, children: line.text }), control: (aria) => (_jsxs(Button, { ...aria, variant: "outline", disabled: !on || result.state === 'sending', onClick: () => void send(), children: [_jsx(SendIcon, { "aria-hidden": "true" }), result.state === 'sending' ? 'Sending…' : 'Send a Test'] })) }));
|
|
81
|
+
}
|
|
82
|
+
function TestNotificationFetched(props) {
|
|
83
|
+
const devices = usePushDevices(props.push);
|
|
84
|
+
return _jsx(TestNotificationRow, { ...props, devices: devices });
|
|
85
|
+
}
|
|
86
|
+
/** Send a Test: one notification to this device, its result on the row's own line. */
|
|
87
|
+
export function TestNotificationSetting({ devices, label = 'Send a Test', ...props }) {
|
|
88
|
+
return devices ? (_jsx(TestNotificationRow, { ...props, label: label, devices: devices })) : (_jsx(TestNotificationFetched, { ...props, label: label }));
|
|
89
|
+
}
|
|
90
|
+
const DEVICES_HELP = 'The devices on your account that get notifications. Each device turns its own on.';
|
|
91
|
+
const ADDED = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
|
|
92
|
+
const deviceName = (device) => device.name ?? 'Unknown device';
|
|
93
|
+
function DeviceItem({ device, devices }) {
|
|
94
|
+
return (_jsxs("li", { "data-slot": "notification-device", "data-this-device": device.thisDevice || undefined, className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-1 py-2.5 first:pt-0 last:pb-0", children: [_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1", children: [_jsx(EditableValue, { label: "Name", layout: "inline", edit: inPlace.text({
|
|
95
|
+
value: device.name,
|
|
96
|
+
required: true,
|
|
97
|
+
maxLength: 60,
|
|
98
|
+
save: (name) => devices.rename(device.id, name),
|
|
99
|
+
}), children: device.name ?? _jsx("span", { className: "text-muted-foreground", children: "Unknown device" }) }), device.thisDevice && _jsx(Badge, { variant: "outline", children: "This Device" })] }), _jsxs("div", { className: "flex items-center gap-3", children: [_jsxs("span", { className: "type-caption text-muted-foreground", children: ["Added ", ADDED.format(new Date(device.createdAt))] }), _jsx(DeleteAction, { name: deviceName(device), kind: "hard", verb: "Remove", trigger: "button", size: "sm", onDelete: () => devices.remove(device) })] })] }));
|
|
100
|
+
}
|
|
101
|
+
function DeviceList({ devices }) {
|
|
102
|
+
const scoped = useContext(EditInPlaceContext) !== null;
|
|
103
|
+
if (devices.unavailable)
|
|
104
|
+
return _jsx("p", { className: "type-body text-muted-foreground", children: PUSH_STATUS_WORDS.unavailable.text });
|
|
105
|
+
if (devices.error)
|
|
106
|
+
return _jsx(ErrorState, { error: devices.error, onRetry: devices.refetch, size: "compact" });
|
|
107
|
+
if (!devices.devices) {
|
|
108
|
+
return (_jsxs("div", { "data-slot": "notification-devices-loading", "aria-busy": "true", className: "flex flex-col gap-3", children: [_jsx(Skeleton, { className: "h-5 w-full max-w-md" }), _jsx(Skeleton, { className: "h-5 w-full max-w-sm" }), _jsx(Skeleton, { className: "h-5 w-full max-w-xs" })] }));
|
|
109
|
+
}
|
|
110
|
+
if (devices.devices.length === 0) {
|
|
111
|
+
return _jsx("p", { className: "type-body text-muted-foreground", children: "No devices get notifications yet." });
|
|
112
|
+
}
|
|
113
|
+
const list = (_jsx("ul", { "data-slot": "notification-devices", className: "flex flex-col divide-y divide-border", children: devices.devices.map((device) => (_jsx(DeviceItem, { device: device, devices: devices }, device.id))) }));
|
|
114
|
+
// A page that runs its own editing in place (an EditInPlaceScope round
|
|
115
|
+
// the card) keeps it; otherwise the names get one of their own.
|
|
116
|
+
return scoped ? list : _jsx(EditInPlaceScope, { children: list });
|
|
117
|
+
}
|
|
118
|
+
function DevicesFetched({ push }) {
|
|
119
|
+
return _jsx(DeviceList, { devices: usePushDevices(push) });
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The account's devices that get notifications, as a settings row with the
|
|
123
|
+
* list under its label: each named (renamed in place), when it was added,
|
|
124
|
+
* This Device on this one, and Remove.
|
|
125
|
+
*/
|
|
126
|
+
export function NotificationDevices({ push, devices, label = 'Devices', help = DEVICES_HELP }) {
|
|
127
|
+
return (_jsx(SettingsRow, { label: label, help: help, layout: "below", control: devices ? _jsx(DeviceList, { devices: devices }) : _jsx(DevicesFetched, { push: push }) }));
|
|
128
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PushStatus } from '../../hooks/use-push-permission.js';
|
|
2
|
+
/** A status in which this device can't turn notifications on, and the words for it. */
|
|
3
|
+
export type PushStatusWords = {
|
|
4
|
+
title?: string;
|
|
5
|
+
text: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const PUSH_STATUS_WORDS: {
|
|
8
|
+
readonly 'needs-install': {
|
|
9
|
+
readonly title: "Add the app to your Home Screen first";
|
|
10
|
+
readonly text: "On iPhone and iPad, reminders work in the app from the Home Screen. Tap Share, then Add to Home Screen, open the app from there and allow reminders.";
|
|
11
|
+
};
|
|
12
|
+
readonly blocked: {
|
|
13
|
+
readonly title: "Notifications are blocked";
|
|
14
|
+
readonly text: "This browser was told not to show this app’s notifications. Allow them in the site’s settings (the icon beside the address), then reload.";
|
|
15
|
+
};
|
|
16
|
+
readonly unsupported: {
|
|
17
|
+
readonly text: "This browser can’t show reminders.";
|
|
18
|
+
};
|
|
19
|
+
readonly mock: {
|
|
20
|
+
readonly text: "Reminders need the real backend: with mock data nothing can send them.";
|
|
21
|
+
};
|
|
22
|
+
readonly unavailable: {
|
|
23
|
+
readonly text: "This app’s server doesn’t send notifications yet.";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type PushStatusWithWords = keyof typeof PUSH_STATUS_WORDS;
|
|
27
|
+
export declare const hasStatusWords: (status: PushStatus | undefined) => status is PushStatusWithWords;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const PUSH_STATUS_WORDS = {
|
|
2
|
+
'needs-install': {
|
|
3
|
+
title: 'Add the app to your Home Screen first',
|
|
4
|
+
text: 'On iPhone and iPad, reminders work in the app from the Home Screen. Tap Share, then Add to Home Screen, open the app from there and allow reminders.',
|
|
5
|
+
},
|
|
6
|
+
blocked: {
|
|
7
|
+
title: 'Notifications are blocked',
|
|
8
|
+
text: 'This browser was told not to show this app’s notifications. Allow them in the site’s settings (the icon beside the address), then reload.',
|
|
9
|
+
},
|
|
10
|
+
unsupported: { text: 'This browser can’t show reminders.' },
|
|
11
|
+
mock: { text: 'Reminders need the real backend: with mock data nothing can send them.' },
|
|
12
|
+
unavailable: { text: 'This app’s server doesn’t send notifications yet.' },
|
|
13
|
+
};
|
|
14
|
+
export const hasStatusWords = (status) => status !== undefined && status in PUSH_STATUS_WORDS;
|