@remit/ui 0.0.131 → 0.0.132
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
CHANGED
|
@@ -17,7 +17,7 @@ const meta: Meta<typeof ComposeActionBar> = {
|
|
|
17
17
|
onSend: fn(),
|
|
18
18
|
onBlocked: fn(),
|
|
19
19
|
onDiscard: fn(),
|
|
20
|
-
|
|
20
|
+
save: { status: "idle" },
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
export default meta;
|
|
@@ -26,11 +26,35 @@ type Story = StoryObj<typeof ComposeActionBar>;
|
|
|
26
26
|
|
|
27
27
|
export const Ready: Story = {};
|
|
28
28
|
|
|
29
|
-
export const Saving: Story = { args: {
|
|
29
|
+
export const Saving: Story = { args: { save: { status: "saving" } } };
|
|
30
30
|
|
|
31
|
-
export const Saved: Story = { args: {
|
|
31
|
+
export const Saved: Story = { args: { save: { status: "saved" } } };
|
|
32
32
|
|
|
33
|
-
export const SaveFailed: Story = { args: {
|
|
33
|
+
export const SaveFailed: Story = { args: { save: { status: "error" } } };
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Nothing has been written to the server yet and nothing will be until the
|
|
37
|
+
* draft has a To address to be created against. Silence here was the worst of
|
|
38
|
+
* both: the text was not being kept, and the composer looked exactly like one
|
|
39
|
+
* that had nothing to keep. The sentence names To rather than "a recipient",
|
|
40
|
+
* which a message addressed only in Cc already has.
|
|
41
|
+
*/
|
|
42
|
+
export const NotSavedYet: Story = {
|
|
43
|
+
name: "Unsaved — the draft has no To address yet",
|
|
44
|
+
args: {
|
|
45
|
+
send: { status: "blocked", reason: "Add a To address before sending." },
|
|
46
|
+
save: {
|
|
47
|
+
status: "unsaved",
|
|
48
|
+
reason: "Not saved — add a To address to keep this draft.",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
play: async ({ canvasElement }) => {
|
|
52
|
+
const canvas = within(canvasElement);
|
|
53
|
+
await expect(canvas.getByRole("status")).toHaveTextContent(
|
|
54
|
+
"Not saved — add a To address to keep this draft.",
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
34
58
|
|
|
35
59
|
export const Sending: Story = {
|
|
36
60
|
name: "Sending — also while the pending draft is written",
|
|
@@ -45,7 +69,7 @@ export const Sending: Story = {
|
|
|
45
69
|
export const NoRecipient: Story = {
|
|
46
70
|
name: "Blocked — nobody to send to",
|
|
47
71
|
args: {
|
|
48
|
-
send: { status: "blocked", reason: "Add
|
|
72
|
+
send: { status: "blocked", reason: "Add a To address before sending." },
|
|
49
73
|
},
|
|
50
74
|
render: (args) => {
|
|
51
75
|
const [reason, setReason] = useState<string>();
|
|
@@ -74,7 +98,7 @@ export const NoRecipient: Story = {
|
|
|
74
98
|
const canvas = within(canvasElement);
|
|
75
99
|
await userEvent.click(canvas.getByRole("button", { name: "Send" }));
|
|
76
100
|
await expect(canvas.getByTestId("compose-unavailable")).toHaveTextContent(
|
|
77
|
-
"Add
|
|
101
|
+
"Add a To address before sending.",
|
|
78
102
|
);
|
|
79
103
|
await expect(args.onSend).not.toHaveBeenCalled();
|
|
80
104
|
},
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { Loader2, Send, Trash2 } from "lucide-react";
|
|
2
2
|
import { Button } from "./button.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* What the draft is doing, and — when it is not being saved — the sentence that
|
|
6
|
+
* says why. Built the same way as `ComposeSendState` and for the same reason:
|
|
7
|
+
* a composer holding text it is not persisting must never be able to say so
|
|
8
|
+
* without saying what is missing. The bare "idle" this replaces rendered
|
|
9
|
+
* nothing at all, so a message that could not be saved yet looked identical to
|
|
10
|
+
* one that had nothing to save.
|
|
11
|
+
*/
|
|
12
|
+
export type ComposeSaveState =
|
|
13
|
+
| { status: "idle" }
|
|
14
|
+
| { status: "saving" }
|
|
15
|
+
| { status: "saved" }
|
|
16
|
+
| { status: "error" }
|
|
17
|
+
| { status: "unsaved"; reason: string };
|
|
5
18
|
|
|
6
19
|
/**
|
|
7
20
|
* Whether Send can act, and when it cannot, the sentence that says why.
|
|
@@ -22,20 +35,25 @@ export interface ComposeActionBarProps {
|
|
|
22
35
|
/** Called with the reason when Send is pressed while it cannot act. */
|
|
23
36
|
onBlocked: (reason: string) => void;
|
|
24
37
|
onDiscard: () => void;
|
|
25
|
-
|
|
38
|
+
save?: ComposeSaveState;
|
|
26
39
|
}
|
|
27
40
|
|
|
28
|
-
const
|
|
29
|
-
if (status === "saving") {
|
|
41
|
+
const SaveStateIndicator = ({ save }: { save: ComposeSaveState }) => {
|
|
42
|
+
if (save.status === "saving") {
|
|
30
43
|
return (
|
|
31
|
-
<
|
|
44
|
+
<output className="animate-pulse text-xs text-fg-muted">Saving...</output>
|
|
32
45
|
);
|
|
33
46
|
}
|
|
34
|
-
if (status === "saved") {
|
|
35
|
-
return <
|
|
47
|
+
if (save.status === "saved") {
|
|
48
|
+
return <output className="text-xs text-fg-muted">Draft saved</output>;
|
|
49
|
+
}
|
|
50
|
+
if (save.status === "error") {
|
|
51
|
+
return <output className="text-xs text-danger">Save failed</output>;
|
|
36
52
|
}
|
|
37
|
-
if (status === "
|
|
38
|
-
return
|
|
53
|
+
if (save.status === "unsaved") {
|
|
54
|
+
return (
|
|
55
|
+
<output className="truncate text-xs text-warning">{save.reason}</output>
|
|
56
|
+
);
|
|
39
57
|
}
|
|
40
58
|
return null;
|
|
41
59
|
};
|
|
@@ -51,7 +69,7 @@ export function ComposeActionBar({
|
|
|
51
69
|
onSend,
|
|
52
70
|
onBlocked,
|
|
53
71
|
onDiscard,
|
|
54
|
-
|
|
72
|
+
save = { status: "idle" },
|
|
55
73
|
}: ComposeActionBarProps) {
|
|
56
74
|
const sending = send.status === "sending";
|
|
57
75
|
const blockedReason = send.status === "blocked" ? send.reason : undefined;
|
|
@@ -84,7 +102,7 @@ export function ComposeActionBar({
|
|
|
84
102
|
>
|
|
85
103
|
Send
|
|
86
104
|
</Button>
|
|
87
|
-
<
|
|
105
|
+
<SaveStateIndicator save={save} />
|
|
88
106
|
</div>
|
|
89
107
|
<Button
|
|
90
108
|
variant="ghost"
|
package/src/index.ts
CHANGED
|
@@ -166,7 +166,7 @@ export { Checkbox, type CheckboxProps } from "./components/checkbox.js";
|
|
|
166
166
|
export {
|
|
167
167
|
ComposeActionBar,
|
|
168
168
|
type ComposeActionBarProps,
|
|
169
|
-
type
|
|
169
|
+
type ComposeSaveState,
|
|
170
170
|
type ComposeSendState,
|
|
171
171
|
} from "./components/compose-action-bar.js";
|
|
172
172
|
export {
|