@domicile-desktop/manganese-notifications 1.1.1 → 2.1.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/package.json +20 -18
- package/src/MailPicker.tsx +155 -0
- package/src/NotificationActions.tsx +2 -0
- package/src/NotificationCard.tsx +14 -2
- package/src/NotificationDrawer.tsx +97 -41
- package/src/fixture.ts +1 -0
- package/src/inbox.ts +45 -3
- package/src/notifications-context.ts +2 -2
- package/src/pause.ts +54 -0
- package/src/stored-pause.ts +57 -0
- package/src/useMailLinks.ts +172 -0
- package/src/useNotifications.ts +73 -16
- package/styled-system/patterns/aspect-ratio.mjs +2 -2
- package/styled-system/patterns/bleed.mjs +1 -2
- package/styled-system/patterns/float.mjs +5 -11
- package/styled-system/patterns/grid-item.mjs +1 -2
- package/styled-system/patterns/grid.mjs +1 -2
- package/styled-system/patterns/link-overlay.mjs +1 -1
- package/styled-system/patterns/spacer.mjs +3 -3
- package/styled-system/patterns/visually-hidden.mjs +1 -1
- package/styled-system/styles.css +2202 -1998
- package/styled-system/tokens/index.mjs +7 -3
- package/styled-system/tokens/tokens.d.ts +2 -2
- package/styled-system/types/prop-type.d.ts +2 -2
- package/src/do-not-disturb.ts +0 -18
package/package.json
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@domicile-desktop/component-library": "2.0
|
|
4
|
-
"@domicile-desktop/manganese-bar": "1.1.
|
|
5
|
-
"@domicile-desktop/manganese-host": "2.0.
|
|
6
|
-
"@domicile-desktop/react": "0.
|
|
7
|
-
"@domicile-desktop/sdk": "
|
|
8
|
-
"@pandacss/dev": "^1.12.
|
|
3
|
+
"@domicile-desktop/component-library": "2.2.0",
|
|
4
|
+
"@domicile-desktop/manganese-bar": "1.1.3",
|
|
5
|
+
"@domicile-desktop/manganese-host": "2.0.3",
|
|
6
|
+
"@domicile-desktop/react": "0.2.0",
|
|
7
|
+
"@domicile-desktop/sdk": "3.0.0",
|
|
8
|
+
"@pandacss/dev": "^1.12.2",
|
|
9
9
|
"@phosphor-icons/react": "^2.1.10",
|
|
10
|
-
"react": "^19.
|
|
11
|
-
"react-dom": "^19.
|
|
10
|
+
"react": "^19.3.1",
|
|
11
|
+
"react-dom": "^19.3.1",
|
|
12
|
+
"zod": "^4.6.7"
|
|
12
13
|
},
|
|
13
14
|
"description": "Manganese's notification toasts and drawer.",
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"@cprussin/tsconfig": "^5.0.0",
|
|
16
|
-
"@domicile-desktop/manganese-window-management": "
|
|
17
|
+
"@domicile-desktop/manganese-window-management": "2.0.0",
|
|
17
18
|
"@domicile-desktop/test-support": "0.0.2",
|
|
18
|
-
"@pandacss/preset-panda": "^1.12.
|
|
19
|
+
"@pandacss/preset-panda": "^1.12.2",
|
|
19
20
|
"@testing-library/react": "^16.3.3",
|
|
20
|
-
"@testing-library/user-event": "^14.6.
|
|
21
|
-
"@types/bun": "^1.4.
|
|
22
|
-
"@types/react": "^19.
|
|
23
|
-
"@types/react-dom": "^19.
|
|
24
|
-
"postcss": "^8.5.
|
|
21
|
+
"@testing-library/user-event": "^14.6.10",
|
|
22
|
+
"@types/bun": "^1.4.4",
|
|
23
|
+
"@types/react": "^19.3.0",
|
|
24
|
+
"@types/react-dom": "^19.3.0",
|
|
25
|
+
"postcss": "^8.5.32",
|
|
25
26
|
"typescript": "^7.0.2"
|
|
26
27
|
},
|
|
27
28
|
"engines": {
|
|
28
|
-
"bun": ">=1.4.2"
|
|
29
|
-
"node": ">=24"
|
|
29
|
+
"bun": ">=1.4.2"
|
|
30
30
|
},
|
|
31
31
|
"exports": {
|
|
32
32
|
"./ago": "./src/ago.ts",
|
|
33
33
|
"./inbox": "./src/inbox.ts",
|
|
34
|
+
"./MailPicker": "./src/MailPicker.tsx",
|
|
34
35
|
"./NotificationDrawer": "./src/NotificationDrawer.tsx",
|
|
35
36
|
"./NotificationToasts": "./src/NotificationToasts.tsx",
|
|
36
37
|
"./notifications-context": "./src/notifications-context.ts",
|
|
38
|
+
"./useMailLinks": "./src/useMailLinks.ts",
|
|
37
39
|
"./useNotifications": "./src/useNotifications.ts",
|
|
38
40
|
"./useNow": "./src/useNow.ts"
|
|
39
41
|
},
|
|
@@ -60,5 +62,5 @@
|
|
|
60
62
|
"test:unit": "bun test"
|
|
61
63
|
},
|
|
62
64
|
"type": "module",
|
|
63
|
-
"version": "
|
|
65
|
+
"version": "2.1.0"
|
|
64
66
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Button } from "@domicile-desktop/component-library/Button";
|
|
2
|
+
import {
|
|
3
|
+
ChoiceList,
|
|
4
|
+
RadioRow,
|
|
5
|
+
} from "@domicile-desktop/component-library/ChoiceRow";
|
|
6
|
+
import { ModalDialog } from "@domicile-desktop/component-library/ModalDialog";
|
|
7
|
+
import type { Icon } from "@phosphor-icons/react";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
|
|
10
|
+
import { css } from "../styled-system/css";
|
|
11
|
+
|
|
12
|
+
/** One address an inbox writes email from. */
|
|
13
|
+
export type Sender = {
|
|
14
|
+
/** The address, such as `me@example.com` or an alias. */
|
|
15
|
+
address: string;
|
|
16
|
+
/** The inbox's icon. */
|
|
17
|
+
icon: Icon;
|
|
18
|
+
/** The inbox's name, such as `Work`. */
|
|
19
|
+
inbox: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type Props = {
|
|
23
|
+
/** The `mailto:` link, shown on one line at the bottom. */
|
|
24
|
+
link: string;
|
|
25
|
+
/** The name of the application that asked, if known. */
|
|
26
|
+
asker?: string | undefined;
|
|
27
|
+
/** Every address it may write from, in the order listed. */
|
|
28
|
+
senders: readonly Sender[];
|
|
29
|
+
/** The address picked last time, which starts picked. */
|
|
30
|
+
lastChoice?: string | undefined;
|
|
31
|
+
onChoose: (sender: Sender) => void;
|
|
32
|
+
onCancel: () => void;
|
|
33
|
+
/** Whether it is up. Turned off, it animates out. */
|
|
34
|
+
open?: boolean | undefined;
|
|
35
|
+
screen?: string | undefined;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Pick which inbox, and which of its addresses, to write a `mailto:` link's
|
|
40
|
+
* email from. The address picked last time, else the first, starts picked.
|
|
41
|
+
* Enter writes; dismissing it cancels.
|
|
42
|
+
*/
|
|
43
|
+
export const MailPicker = ({
|
|
44
|
+
asker,
|
|
45
|
+
lastChoice,
|
|
46
|
+
link,
|
|
47
|
+
onCancel,
|
|
48
|
+
onChoose,
|
|
49
|
+
open = true,
|
|
50
|
+
screen,
|
|
51
|
+
senders,
|
|
52
|
+
}: Props) => {
|
|
53
|
+
const [picked, setPicked] = useState<string | undefined>();
|
|
54
|
+
const chosen =
|
|
55
|
+
senders.find(({ address }) => address === picked) ??
|
|
56
|
+
senders.find(({ address }) => address === lastChoice) ??
|
|
57
|
+
senders[0];
|
|
58
|
+
const write = () => {
|
|
59
|
+
if (chosen !== undefined) {
|
|
60
|
+
onChoose(chosen);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const to = recipientsOf(link);
|
|
64
|
+
return (
|
|
65
|
+
<ModalDialog
|
|
66
|
+
closeButton={false}
|
|
67
|
+
footer={
|
|
68
|
+
<>
|
|
69
|
+
{asker !== undefined && (
|
|
70
|
+
<p className={askerStyles}>{`${asker} asks`}</p>
|
|
71
|
+
)}
|
|
72
|
+
<Button onClick={onCancel} variant="outline">
|
|
73
|
+
Cancel
|
|
74
|
+
</Button>
|
|
75
|
+
<Button
|
|
76
|
+
disabled={chosen === undefined}
|
|
77
|
+
onClick={write}
|
|
78
|
+
variant="accent"
|
|
79
|
+
>
|
|
80
|
+
Write email
|
|
81
|
+
</Button>
|
|
82
|
+
</>
|
|
83
|
+
}
|
|
84
|
+
onOpenChange={(opening) => {
|
|
85
|
+
if (!opening) {
|
|
86
|
+
onCancel();
|
|
87
|
+
}
|
|
88
|
+
}}
|
|
89
|
+
open={open}
|
|
90
|
+
screen={screen}
|
|
91
|
+
title={to === "" ? "Write an email" : `Write to ${to}`}
|
|
92
|
+
>
|
|
93
|
+
<p className={textStyles}>Choose the inbox to send from.</p>
|
|
94
|
+
<div className={listStyles}>
|
|
95
|
+
<ChoiceList<string>
|
|
96
|
+
aria-label="Send from"
|
|
97
|
+
// Enter on a row writes, as the dialog's main button does.
|
|
98
|
+
onKeyDown={(event) => {
|
|
99
|
+
if (event.key === "Enter") {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
write();
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
onValueChange={setPicked}
|
|
105
|
+
value={chosen?.address}
|
|
106
|
+
>
|
|
107
|
+
{senders.map(({ address, icon: SenderIcon, inbox }) => (
|
|
108
|
+
<RadioRow
|
|
109
|
+
detail={address}
|
|
110
|
+
icon={<SenderIcon weight="duotone" />}
|
|
111
|
+
key={address}
|
|
112
|
+
name={inbox}
|
|
113
|
+
value={address}
|
|
114
|
+
/>
|
|
115
|
+
))}
|
|
116
|
+
</ChoiceList>
|
|
117
|
+
</div>
|
|
118
|
+
<p className={addressStyles}>{link}</p>
|
|
119
|
+
</ModalDialog>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** The addresses a `mailto:` link writes to, as people read them. */
|
|
124
|
+
const recipientsOf = (link: string): string => {
|
|
125
|
+
const to = link.slice(link.indexOf(":") + 1).split("?")[0] ?? "";
|
|
126
|
+
return decodeURIComponent(to).split(",").join(", ");
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const textStyles = css({ color: "muted", margin: 0 });
|
|
130
|
+
|
|
131
|
+
// Who asks sits opposite the buttons, as in the app chooser.
|
|
132
|
+
const askerStyles = css({
|
|
133
|
+
color: "muted",
|
|
134
|
+
fontSize: "ui",
|
|
135
|
+
margin: 0,
|
|
136
|
+
marginInlineEnd: "auto",
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const listStyles = css({
|
|
140
|
+
marginBlockStart: 3,
|
|
141
|
+
maxBlockSize: 80,
|
|
142
|
+
overflowY: "auto",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// A link can be long, with no spaces, as the app chooser's address can.
|
|
146
|
+
const addressStyles = css({
|
|
147
|
+
color: "muted",
|
|
148
|
+
fontFamily: "mono",
|
|
149
|
+
fontSize: "xs",
|
|
150
|
+
marginBlockEnd: 0,
|
|
151
|
+
marginBlockStart: 3,
|
|
152
|
+
overflow: "hidden",
|
|
153
|
+
textOverflow: "ellipsis",
|
|
154
|
+
whiteSpace: "nowrap",
|
|
155
|
+
});
|
|
@@ -166,6 +166,8 @@ const stripStyles = cva({
|
|
|
166
166
|
display: "grid",
|
|
167
167
|
gridColumn: "1 / -1",
|
|
168
168
|
gridTemplateRows: "1fr 0fr",
|
|
169
|
+
// main-thread animation: swaps the actions for the reply field once, moving
|
|
170
|
+
// what is below.
|
|
169
171
|
transition: "grid-template-rows {durations.slow} {easings.outQuart}",
|
|
170
172
|
},
|
|
171
173
|
// Cancels the card's padding so the strip spans it edge to edge. Matches
|
package/src/NotificationCard.tsx
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Avatar } from "@domicile-desktop/component-library/Avatar";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Notification,
|
|
4
|
+
NotificationAction,
|
|
5
|
+
} from "@domicile-desktop/sdk/notification";
|
|
3
6
|
import {
|
|
4
7
|
DEFAULT_NOTIFICATION_ACTION,
|
|
5
8
|
INLINE_REPLY_NOTIFICATION_ACTION,
|
|
@@ -152,7 +155,7 @@ export const NotificationCard = ({
|
|
|
152
155
|
density={density}
|
|
153
156
|
onAction={onAction}
|
|
154
157
|
onReply={onReply}
|
|
155
|
-
replyLabel={reply
|
|
158
|
+
replyLabel={replyLabel(reply)}
|
|
156
159
|
/>
|
|
157
160
|
)}
|
|
158
161
|
<button
|
|
@@ -319,3 +322,12 @@ const closeStyles = css({
|
|
|
319
322
|
transition:
|
|
320
323
|
"opacity {durations.fast} {easings.out}, transform {durations.fast} {easings.outBack}, background-color {durations.fast} {easings.default}",
|
|
321
324
|
});
|
|
325
|
+
|
|
326
|
+
/** A reply's label: its own, or "Reply" when the app leaves it empty. */
|
|
327
|
+
const replyLabel = (reply: NotificationAction | undefined) => {
|
|
328
|
+
if (reply === undefined) {
|
|
329
|
+
return undefined;
|
|
330
|
+
} else {
|
|
331
|
+
return reply.label === "" ? "Reply" : reply.label;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
@@ -3,15 +3,17 @@ import { EmptyState } from "@domicile-desktop/component-library/EmptyState";
|
|
|
3
3
|
import { LeavingRow } from "@domicile-desktop/component-library/LeavingRow";
|
|
4
4
|
import { List } from "@domicile-desktop/component-library/ListRow";
|
|
5
5
|
import type { Row } from "@domicile-desktop/component-library/leaving-rows";
|
|
6
|
-
import {
|
|
6
|
+
import { Menu } from "@domicile-desktop/component-library/Menu";
|
|
7
7
|
import { PanelHeader } from "@domicile-desktop/component-library/PanelHeader";
|
|
8
8
|
import { PanelSection } from "@domicile-desktop/component-library/PanelSection";
|
|
9
9
|
import { Popover } from "@domicile-desktop/component-library/Popover";
|
|
10
|
-
import { Switch } from "@domicile-desktop/component-library/Switch";
|
|
11
10
|
import { useLeavingRows } from "@domicile-desktop/component-library/useLeavingRows";
|
|
12
11
|
import type { Notification } from "@domicile-desktop/sdk/notification";
|
|
13
12
|
import { BellSimpleIcon } from "@phosphor-icons/react/dist/ssr/BellSimple";
|
|
14
13
|
import { BroomIcon } from "@phosphor-icons/react/dist/ssr/Broom";
|
|
14
|
+
import { CaretDownIcon } from "@phosphor-icons/react/dist/ssr/CaretDown";
|
|
15
|
+
import { PauseIcon } from "@phosphor-icons/react/dist/ssr/Pause";
|
|
16
|
+
import { PlayIcon } from "@phosphor-icons/react/dist/ssr/Play";
|
|
15
17
|
import { memo } from "react";
|
|
16
18
|
|
|
17
19
|
import { css } from "../styled-system/css";
|
|
@@ -21,6 +23,8 @@ import type { Inbox, InboxReading } from "./inbox";
|
|
|
21
23
|
import { NotificationCard } from "./NotificationCard";
|
|
22
24
|
import type { NotificationsHandle } from "./notifications-context";
|
|
23
25
|
import { bellId, screenOfBell } from "./notifications-context";
|
|
26
|
+
import { PauseLength, pausedFor } from "./pause";
|
|
27
|
+
import type { Pause } from "./stored-pause";
|
|
24
28
|
|
|
25
29
|
/** The inboxes listed in the drawer, and what the shell knows of them. */
|
|
26
30
|
export type DrawerInboxes = {
|
|
@@ -32,8 +36,6 @@ export type DrawerInboxes = {
|
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
type Props = {
|
|
35
|
-
/** Toasts are held back, but for critical ones. */
|
|
36
|
-
doNotDisturb: boolean;
|
|
37
39
|
/** Opens it under the bell pressed. */
|
|
38
40
|
handle: NotificationsHandle;
|
|
39
41
|
/** The inboxes, listed above the notifications. */
|
|
@@ -43,6 +45,8 @@ type Props = {
|
|
|
43
45
|
/** The current time, for the relative timestamps. */
|
|
44
46
|
now: number;
|
|
45
47
|
open: boolean;
|
|
48
|
+
/** Toasts are held back, but for critical ones, until it ends. */
|
|
49
|
+
pause: Pause | undefined;
|
|
46
50
|
/** The monitor whose bell it opens under. */
|
|
47
51
|
screen: string | undefined;
|
|
48
52
|
/** The bell on monitor `screen` was pressed. */
|
|
@@ -50,8 +54,10 @@ type Props = {
|
|
|
50
54
|
onClose: () => void;
|
|
51
55
|
/** Clear `ids`. */
|
|
52
56
|
onDismiss: (ids: readonly number[]) => void;
|
|
53
|
-
/**
|
|
54
|
-
|
|
57
|
+
/** Pause toasts for `length`. */
|
|
58
|
+
onPause: (length: PauseLength) => void;
|
|
59
|
+
/** End the pause. */
|
|
60
|
+
onResume: () => void;
|
|
55
61
|
/** Press `key` on `id`. */
|
|
56
62
|
onAction: (id: number, key: string) => void;
|
|
57
63
|
/** Send `text` from `id`'s reply field. */
|
|
@@ -61,8 +67,8 @@ type Props = {
|
|
|
61
67
|
/**
|
|
62
68
|
* The notification drawer, a panel under the bell. Each notification can be
|
|
63
69
|
* pressed or cleared, or all cleared at once. A press closes the drawer,
|
|
64
|
-
* which would cover the window it raises.
|
|
65
|
-
*
|
|
70
|
+
* which would cover the window it raises. Its header pauses notifications from
|
|
71
|
+
* a menu of lengths, and says until when while paused.
|
|
66
72
|
*
|
|
67
73
|
* A notification stays here after its toast is gone, until it is cleared or its
|
|
68
74
|
* application withdraws it. See docs/architecture/NOTIFICATIONS.md.
|
|
@@ -75,7 +81,6 @@ type Props = {
|
|
|
75
81
|
*/
|
|
76
82
|
export const NotificationDrawer = memo(
|
|
77
83
|
({
|
|
78
|
-
doNotDisturb,
|
|
79
84
|
handle,
|
|
80
85
|
inboxes,
|
|
81
86
|
items,
|
|
@@ -83,10 +88,12 @@ export const NotificationDrawer = memo(
|
|
|
83
88
|
onAction,
|
|
84
89
|
onClose,
|
|
85
90
|
onDismiss,
|
|
86
|
-
onDoNotDisturb,
|
|
87
91
|
onOpen,
|
|
92
|
+
onPause,
|
|
88
93
|
onReply,
|
|
94
|
+
onResume,
|
|
89
95
|
open,
|
|
96
|
+
pause,
|
|
90
97
|
screen,
|
|
91
98
|
}: Props) => {
|
|
92
99
|
const { onLeft, rows } = useLeavingRows(items, idOf, open);
|
|
@@ -117,7 +124,26 @@ export const NotificationDrawer = memo(
|
|
|
117
124
|
triggerId={screen === undefined ? null : bellId(screen)}
|
|
118
125
|
>
|
|
119
126
|
<section aria-labelledby={TITLE_ID} className={drawerStyles}>
|
|
120
|
-
<PanelHeader
|
|
127
|
+
<PanelHeader
|
|
128
|
+
action={
|
|
129
|
+
pause === undefined ? (
|
|
130
|
+
<PauseMenu onPause={onPause} />
|
|
131
|
+
) : (
|
|
132
|
+
<Button
|
|
133
|
+
beforeIcon={<PlayIcon aria-hidden size={12} weight="fill" />}
|
|
134
|
+
onClick={onResume}
|
|
135
|
+
rounded
|
|
136
|
+
size="xs"
|
|
137
|
+
variant="accent"
|
|
138
|
+
>
|
|
139
|
+
Resume
|
|
140
|
+
</Button>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
status={pause === undefined ? undefined : pausedFor(pause, now)}
|
|
144
|
+
title="Notifications"
|
|
145
|
+
titleId={TITLE_ID}
|
|
146
|
+
/>
|
|
121
147
|
<div className={paneStyles}>
|
|
122
148
|
{inboxes !== undefined && (
|
|
123
149
|
<PanelSection label="Inboxes">
|
|
@@ -130,41 +156,70 @@ export const NotificationDrawer = memo(
|
|
|
130
156
|
</List>
|
|
131
157
|
</PanelSection>
|
|
132
158
|
)}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
159
|
+
<PanelSection
|
|
160
|
+
action={
|
|
161
|
+
items.length > 0 && (
|
|
162
|
+
<Button
|
|
163
|
+
beforeIcon={<BroomIcon aria-hidden size={14} />}
|
|
164
|
+
onClick={() => {
|
|
165
|
+
onDismiss(items.map(({ id }) => id));
|
|
166
|
+
}}
|
|
167
|
+
rounded
|
|
168
|
+
size="xs"
|
|
169
|
+
variant="ghost"
|
|
170
|
+
>
|
|
171
|
+
Clear all
|
|
172
|
+
</Button>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
label="Recent"
|
|
176
|
+
>
|
|
177
|
+
{notifications}
|
|
178
|
+
</PanelSection>
|
|
138
179
|
</div>
|
|
139
|
-
<PanelFooter
|
|
140
|
-
action={
|
|
141
|
-
items.length > 0 && (
|
|
142
|
-
<Button
|
|
143
|
-
beforeIcon={<BroomIcon aria-hidden size={14} />}
|
|
144
|
-
onClick={() => {
|
|
145
|
-
onDismiss(items.map(({ id }) => id));
|
|
146
|
-
}}
|
|
147
|
-
rounded
|
|
148
|
-
size="xs"
|
|
149
|
-
variant="ghost"
|
|
150
|
-
>
|
|
151
|
-
Clear all
|
|
152
|
-
</Button>
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
>
|
|
156
|
-
<Switch
|
|
157
|
-
checked={doNotDisturb}
|
|
158
|
-
label="Do not disturb"
|
|
159
|
-
onCheckedChange={onDoNotDisturb}
|
|
160
|
-
/>
|
|
161
|
-
</PanelFooter>
|
|
162
180
|
</section>
|
|
163
181
|
</Popover>
|
|
164
182
|
);
|
|
165
183
|
},
|
|
166
184
|
);
|
|
167
185
|
|
|
186
|
+
type PauseMenuProps = Pick<Props, "onPause">;
|
|
187
|
+
|
|
188
|
+
/** The header's Pause button, and the lengths it offers. */
|
|
189
|
+
const PauseMenu = ({ onPause }: PauseMenuProps) => (
|
|
190
|
+
<Menu
|
|
191
|
+
trigger={
|
|
192
|
+
<Button
|
|
193
|
+
afterIcon={<CaretDownIcon aria-hidden size={10} weight="fill" />}
|
|
194
|
+
beforeIcon={<PauseIcon aria-hidden size={12} weight="fill" />}
|
|
195
|
+
rounded
|
|
196
|
+
size="xs"
|
|
197
|
+
variant="ghost"
|
|
198
|
+
>
|
|
199
|
+
Pause
|
|
200
|
+
</Button>
|
|
201
|
+
}
|
|
202
|
+
>
|
|
203
|
+
{PAUSE_LENGTHS.map(({ label, length }) => (
|
|
204
|
+
<Menu.Item
|
|
205
|
+
key={label}
|
|
206
|
+
onClick={() => {
|
|
207
|
+
onPause(length);
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
{label}
|
|
211
|
+
</Menu.Item>
|
|
212
|
+
))}
|
|
213
|
+
</Menu>
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
/** The Pause menu's items, shortest first. */
|
|
217
|
+
const PAUSE_LENGTHS = [
|
|
218
|
+
{ label: "For 1 hour", length: PauseLength.Hour },
|
|
219
|
+
{ label: "Until tomorrow", length: PauseLength.Tomorrow },
|
|
220
|
+
{ label: "Until I resume", length: PauseLength.UntilResumed },
|
|
221
|
+
];
|
|
222
|
+
|
|
168
223
|
/** Tells one notification from another. */
|
|
169
224
|
const idOf = ({ id }: Notification): number => id;
|
|
170
225
|
|
|
@@ -275,6 +330,8 @@ const listStyles = flex({
|
|
|
275
330
|
overflowX: "clip",
|
|
276
331
|
overflowY: "clip",
|
|
277
332
|
paddingInline: 0,
|
|
333
|
+
// main-thread animation: holds the drawer's height once, as its last row
|
|
334
|
+
// leaves.
|
|
278
335
|
transition: "min-block-size {durations.normal} {easings.in-out}",
|
|
279
336
|
});
|
|
280
337
|
|
|
@@ -292,8 +349,7 @@ const cardBoxStyles = css({
|
|
|
292
349
|
backgroundColor: "fill",
|
|
293
350
|
borderRadius: "lg",
|
|
294
351
|
minBlockSize: 0,
|
|
295
|
-
transition:
|
|
296
|
-
"background-color {durations.fast} {easings.default}, box-shadow {durations.fast} {easings.default}",
|
|
352
|
+
transition: "background-color {durations.fast} {easings.default}",
|
|
297
353
|
});
|
|
298
354
|
|
|
299
355
|
// Fades in as the last cleared row leaves.
|
package/src/fixture.ts
CHANGED
package/src/inbox.ts
CHANGED
|
@@ -22,13 +22,16 @@ export type UnreadMessage = {
|
|
|
22
22
|
export const InboxReading = {
|
|
23
23
|
/**
|
|
24
24
|
* Every conversation, and the unread ones, with the newest message of each
|
|
25
|
-
* of the newest unread conversations, newest first
|
|
25
|
+
* of the newest unread conversations, newest first, and the addresses the
|
|
26
|
+
* account sends from, its own first, when known.
|
|
26
27
|
*/
|
|
27
28
|
Counted: (
|
|
28
29
|
total: number,
|
|
29
30
|
unread: number,
|
|
30
31
|
latest: readonly UnreadMessage[] = [],
|
|
32
|
+
addresses: readonly string[] = [],
|
|
31
33
|
) => ({
|
|
34
|
+
addresses,
|
|
32
35
|
kind: InboxReadingKind.Counted as const,
|
|
33
36
|
latest,
|
|
34
37
|
total,
|
|
@@ -105,11 +108,25 @@ export const Inbox = {
|
|
|
105
108
|
read: (domicile: Domicile) => SharedWatch<InboxReading>;
|
|
106
109
|
/** Opens it, or signs it in, for a press of its row. */
|
|
107
110
|
open: (domicile: Domicile, reading: InboxReading | undefined) => void;
|
|
111
|
+
/**
|
|
112
|
+
* Writes email from its account, for `mailto:` links: opens a new
|
|
113
|
+
* message from address `from`, filled in from the link `link`. Without
|
|
114
|
+
* it, the inbox writes no email. See {@link sendersOf}.
|
|
115
|
+
*/
|
|
116
|
+
write?: (domicile: Domicile, link: string, from: string) => void;
|
|
108
117
|
/**
|
|
109
118
|
* The app window it opens in, if any, which the launcher lists: app
|
|
110
|
-
* `appId`'s, at `url`.
|
|
119
|
+
* `appId`'s, at `url`. With `pageNotifies`, its page notifies what the
|
|
120
|
+
* inbox notifies already, so the page's are cleared as they arrive.
|
|
121
|
+
* With `profile`, it opens in that browser profile rather than its
|
|
122
|
+
* site's.
|
|
111
123
|
*/
|
|
112
|
-
app?: {
|
|
124
|
+
app?: {
|
|
125
|
+
appId: string;
|
|
126
|
+
url: string;
|
|
127
|
+
pageNotifies?: boolean;
|
|
128
|
+
profile?: string;
|
|
129
|
+
};
|
|
113
130
|
},
|
|
114
131
|
) => ({ ...inbox, kind: InboxKind.Watched as const }),
|
|
115
132
|
/**
|
|
@@ -124,6 +141,11 @@ export const Inbox = {
|
|
|
124
141
|
appId: string;
|
|
125
142
|
/** The page's address. */
|
|
126
143
|
url: string;
|
|
144
|
+
/**
|
|
145
|
+
* The id of the browser profile its window opens in, such as `work`.
|
|
146
|
+
* By default, the one its site opens in.
|
|
147
|
+
*/
|
|
148
|
+
profile?: string;
|
|
127
149
|
/**
|
|
128
150
|
* Calls `onUnread` with the page's unread conversations, read with
|
|
129
151
|
* `countMatches`, which counts the window's elements matching a CSS
|
|
@@ -138,3 +160,23 @@ export const Inbox = {
|
|
|
138
160
|
};
|
|
139
161
|
|
|
140
162
|
export type Inbox = ReturnType<(typeof Inbox)[keyof typeof Inbox]>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The addresses `inbox` writes email from, given its `reading`: those the
|
|
166
|
+
* reading names, else its account's. None when it writes no email.
|
|
167
|
+
*/
|
|
168
|
+
export const sendersOf = (
|
|
169
|
+
inbox: Inbox,
|
|
170
|
+
reading: InboxReading | undefined,
|
|
171
|
+
): readonly string[] => {
|
|
172
|
+
if (inbox.kind !== InboxKind.Watched || inbox.write === undefined) {
|
|
173
|
+
return [];
|
|
174
|
+
} else if (
|
|
175
|
+
reading?.kind === InboxReadingKind.Counted &&
|
|
176
|
+
reading.addresses.length > 0
|
|
177
|
+
) {
|
|
178
|
+
return reading.addresses;
|
|
179
|
+
} else {
|
|
180
|
+
return inbox.account === undefined ? [] : [inbox.account];
|
|
181
|
+
}
|
|
182
|
+
};
|
|
@@ -7,10 +7,10 @@ export type NotificationsHandle = ReturnType<typeof createHandle>;
|
|
|
7
7
|
|
|
8
8
|
/** The notification drawer, for the bell that opens it. */
|
|
9
9
|
export type NotificationsDrawer = {
|
|
10
|
-
/** Toasts are held back, but for critical ones. */
|
|
11
|
-
doNotDisturb: boolean;
|
|
12
10
|
/** Opens the drawer under the bell pressed. */
|
|
13
11
|
handle: NotificationsHandle;
|
|
12
|
+
/** Toasts are held back, but for critical ones. */
|
|
13
|
+
paused: boolean;
|
|
14
14
|
/** How many notifications arrived since the drawer was last opened. */
|
|
15
15
|
unread: number;
|
|
16
16
|
};
|
package/src/pause.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Pause } from "./stored-pause";
|
|
2
|
+
|
|
3
|
+
/** How long a pause lasts, as picked from the drawer's Pause menu. */
|
|
4
|
+
export enum PauseLength {
|
|
5
|
+
Hour,
|
|
6
|
+
Tomorrow,
|
|
7
|
+
UntilResumed,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const HOUR_MS = 3_600_000;
|
|
11
|
+
|
|
12
|
+
/** The hour of the morning a pause until tomorrow ends. */
|
|
13
|
+
const MORNING_HOUR = 8;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* When a pause of `length` started at `now` ends, in ms since the epoch, or
|
|
17
|
+
* `undefined` for one that lasts until resumed.
|
|
18
|
+
*/
|
|
19
|
+
export const pauseEnd = (
|
|
20
|
+
length: PauseLength,
|
|
21
|
+
now: number,
|
|
22
|
+
): number | undefined => {
|
|
23
|
+
switch (length) {
|
|
24
|
+
case PauseLength.Hour: {
|
|
25
|
+
return now + HOUR_MS;
|
|
26
|
+
}
|
|
27
|
+
case PauseLength.Tomorrow: {
|
|
28
|
+
return nextMorning(new Date(now)).getTime();
|
|
29
|
+
}
|
|
30
|
+
case PauseLength.UntilResumed: {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** What the drawer says under its title while `pause` holds at `now`. */
|
|
37
|
+
export const pausedFor = ({ until }: Pause, now: number): string =>
|
|
38
|
+
until === undefined ? "Paused" : `Paused until ${endsAt(until, now)}`;
|
|
39
|
+
|
|
40
|
+
/** 8 AM the day after `now`'s date, local time. */
|
|
41
|
+
const nextMorning = (now: Date): Date =>
|
|
42
|
+
new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, MORNING_HOUR);
|
|
43
|
+
|
|
44
|
+
/** `until`'s time, after "tomorrow" when that is not `now`'s date. */
|
|
45
|
+
const endsAt = (until: number, now: number): string => {
|
|
46
|
+
const end = new Date(until);
|
|
47
|
+
const time = end.toLocaleTimeString(undefined, {
|
|
48
|
+
hour: "numeric",
|
|
49
|
+
minute: "2-digit",
|
|
50
|
+
});
|
|
51
|
+
return end.toDateString() === new Date(now).toDateString()
|
|
52
|
+
? time
|
|
53
|
+
: `tomorrow, ${time}`;
|
|
54
|
+
};
|