@remit/web-client 0.0.208 → 0.0.209
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 +1 -1
- package/src/components/mail/BriefPane.tsx +5 -1
- package/src/components/mail/FlaggedPane.tsx +5 -1
- package/src/components/mail/MailboxPane.tsx +6 -1
- package/src/hooks/useThreadActions.star.test.ts +200 -0
- package/src/hooks/useThreadActions.ts +29 -3
- package/src/hooks/useThreadRow.ts +24 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remit/web-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.209",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Remit web client, published as composable primitives — the app shell, auth shells, and runtime config. A distributor imports what it composes and bundles it.",
|
|
6
6
|
"exports": {
|
|
@@ -173,6 +173,7 @@ function BriefPaneProvider({ thread, children }: BriefPaneProps) {
|
|
|
173
173
|
|
|
174
174
|
const actions = useThreadActions({
|
|
175
175
|
thread: selectedThread,
|
|
176
|
+
isOpen: true,
|
|
176
177
|
onAfterOptimisticRemove: handleDeselectIfRemoved,
|
|
177
178
|
});
|
|
178
179
|
|
|
@@ -197,7 +198,10 @@ function BriefPaneProvider({ thread, children }: BriefPaneProps) {
|
|
|
197
198
|
[briefThreads, focusedThreadId],
|
|
198
199
|
);
|
|
199
200
|
const triageTarget = focusedThread ?? selectedThread;
|
|
200
|
-
const triageActions = useThreadActions({
|
|
201
|
+
const triageActions = useThreadActions({
|
|
202
|
+
thread: triageTarget,
|
|
203
|
+
isOpen: triageTarget?.messageId === selectedMessageId,
|
|
204
|
+
});
|
|
201
205
|
|
|
202
206
|
// The toolbar answers the conversation on screen; the keyboard answers the
|
|
203
207
|
// row the cursor is on, which may be one the address has not opened yet.
|
|
@@ -179,6 +179,7 @@ function FlaggedPaneProvider({ thread, children }: FlaggedPaneProps) {
|
|
|
179
179
|
|
|
180
180
|
const actions = useThreadActions({
|
|
181
181
|
thread: selectedThread,
|
|
182
|
+
isOpen: true,
|
|
182
183
|
onAfterOptimisticRemove: handleDeselectIfRemoved,
|
|
183
184
|
});
|
|
184
185
|
|
|
@@ -203,7 +204,10 @@ function FlaggedPaneProvider({ thread, children }: FlaggedPaneProps) {
|
|
|
203
204
|
[threads, focusedThreadId],
|
|
204
205
|
);
|
|
205
206
|
const triageTarget = focusedThread ?? selectedThread;
|
|
206
|
-
const triageActions = useThreadActions({
|
|
207
|
+
const triageActions = useThreadActions({
|
|
208
|
+
thread: triageTarget,
|
|
209
|
+
isOpen: triageTarget?.messageId === selectedMessageId,
|
|
210
|
+
});
|
|
207
211
|
|
|
208
212
|
// The toolbar answers the conversation on screen; the keyboard answers the
|
|
209
213
|
// row the cursor is on, which may be one the address has not opened yet.
|
|
@@ -227,6 +227,8 @@ interface MailboxPaneContextValue {
|
|
|
227
227
|
onReply: ((mode: ReplyMode) => void) | undefined;
|
|
228
228
|
onToolbarDelete: () => void;
|
|
229
229
|
onToolbarStar: () => void;
|
|
230
|
+
/** Whether the open message is starred, as the conversation reports it. */
|
|
231
|
+
isStarred: boolean | undefined;
|
|
230
232
|
onToolbarMove: (destMailboxId: string) => void;
|
|
231
233
|
// Phone actions
|
|
232
234
|
onBack: () => void;
|
|
@@ -515,6 +517,7 @@ function MailboxPaneProvider({
|
|
|
515
517
|
|
|
516
518
|
const toolbarActions = useThreadActions({
|
|
517
519
|
thread: selectedThread,
|
|
520
|
+
isOpen: true,
|
|
518
521
|
mailboxId,
|
|
519
522
|
accountId: mailboxAccountId,
|
|
520
523
|
onAfterOptimisticRemove: handleDeselectIfRemoved,
|
|
@@ -806,6 +809,7 @@ function MailboxPaneProvider({
|
|
|
806
809
|
onReply: replyToOpenThread,
|
|
807
810
|
onToolbarDelete: toolbarActions.deleteThread,
|
|
808
811
|
onToolbarStar: toolbarActions.toggleStar,
|
|
812
|
+
isStarred: toolbarActions.isStarred,
|
|
809
813
|
onToolbarMove: toolbarActions.moveThread,
|
|
810
814
|
onBack: goBack,
|
|
811
815
|
nextThread: adjacentThread(nextMessageId),
|
|
@@ -1080,6 +1084,7 @@ function MailboxReading() {
|
|
|
1080
1084
|
onReply,
|
|
1081
1085
|
onToolbarDelete,
|
|
1082
1086
|
onToolbarStar,
|
|
1087
|
+
isStarred,
|
|
1083
1088
|
onToolbarMove,
|
|
1084
1089
|
handleDeselectIfRemoved,
|
|
1085
1090
|
intelligenceRef,
|
|
@@ -1137,7 +1142,7 @@ function MailboxReading() {
|
|
|
1137
1142
|
onForward={onReply ? () => onReply("forward") : undefined}
|
|
1138
1143
|
onDelete={hasThread ? onToolbarDelete : undefined}
|
|
1139
1144
|
onToggleStar={hasThread ? onToolbarStar : undefined}
|
|
1140
|
-
isStarred={
|
|
1145
|
+
isStarred={isStarred}
|
|
1141
1146
|
moveContext={
|
|
1142
1147
|
hasThread && mailboxAccountId
|
|
1143
1148
|
? {
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression cover for issue #602 — the reading pane's star did not toggle and
|
|
3
|
+
* never showed the open message as starred.
|
|
4
|
+
*
|
|
5
|
+
* Both symptoms were one cause: the control answered from the list row that
|
|
6
|
+
* represented the conversation, not from the conversation. A row is a copy that
|
|
7
|
+
* stops being refreshed the moment the mail no longer matches the browsed
|
|
8
|
+
* predicate, so the star read unstarred however many times it had been set, and
|
|
9
|
+
* every press asked the server to star a message that already was.
|
|
10
|
+
*
|
|
11
|
+
* Each case mounts the real toolbar over a mocked server and lets the
|
|
12
|
+
* conversation's own listing disagree with the stale list row.
|
|
13
|
+
*/
|
|
14
|
+
import assert from "node:assert/strict";
|
|
15
|
+
import { afterEach, describe, it } from "node:test";
|
|
16
|
+
import { threadDetailOperationsListThreadMessagesQueryKey } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
|
|
17
|
+
import type { RemitImapThreadMessageResponse } from "@remit/api-http-client/types.gen.ts";
|
|
18
|
+
import { createElement } from "react";
|
|
19
|
+
import { MessageToolbar } from "@/components/mail/MessageToolbar";
|
|
20
|
+
import { useThreadActions } from "@/hooks/useThreadActions";
|
|
21
|
+
import { createDomHarness, type DomHarness } from "../test-support/dom";
|
|
22
|
+
import { makeConfig, makeThreadMessage } from "../test-support/fixtures";
|
|
23
|
+
import { type HttpMock, mockFetch } from "../test-support/http";
|
|
24
|
+
|
|
25
|
+
const MESSAGE_ID = "msg-1";
|
|
26
|
+
const THREAD_ID = "thread-1";
|
|
27
|
+
|
|
28
|
+
let harness: DomHarness | undefined;
|
|
29
|
+
let http: HttpMock | undefined;
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
harness?.close();
|
|
33
|
+
harness = undefined;
|
|
34
|
+
http?.restore();
|
|
35
|
+
http = undefined;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
interface ServerState {
|
|
39
|
+
starred: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const conversationKey = threadDetailOperationsListThreadMessagesQueryKey({
|
|
43
|
+
path: { threadId: THREAD_ID },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const conversationRow = (starred: boolean) =>
|
|
47
|
+
makeThreadMessage({
|
|
48
|
+
messageId: MESSAGE_ID,
|
|
49
|
+
threadId: THREAD_ID,
|
|
50
|
+
hasStars: starred,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The message as the conversation endpoint serves it, and the list row as the
|
|
55
|
+
* mailbox listing served it — which is deliberately allowed to disagree.
|
|
56
|
+
*/
|
|
57
|
+
const mountToolbar = async (options: {
|
|
58
|
+
server: ServerState;
|
|
59
|
+
row: Partial<RemitImapThreadMessageResponse>;
|
|
60
|
+
/** Defaults to the reading pane's case: this thread is the one on screen. */
|
|
61
|
+
isOpen?: boolean;
|
|
62
|
+
}) => {
|
|
63
|
+
const { server, isOpen = true } = options;
|
|
64
|
+
http = mockFetch((call) => {
|
|
65
|
+
if (call.method === "PATCH") {
|
|
66
|
+
const body = call.body as { isStarred?: boolean } | undefined;
|
|
67
|
+
server.starred = body?.isStarred === true;
|
|
68
|
+
return {
|
|
69
|
+
messageId: MESSAGE_ID,
|
|
70
|
+
isRead: true,
|
|
71
|
+
isStarred: server.starred,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (call.path.includes("/config")) return makeConfig([]);
|
|
75
|
+
if (call.path.endsWith(`/threads/${THREAD_ID}/messages`)) {
|
|
76
|
+
return { items: [conversationRow(server.starred)] };
|
|
77
|
+
}
|
|
78
|
+
return { items: [] };
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const thread = makeThreadMessage({
|
|
82
|
+
messageId: MESSAGE_ID,
|
|
83
|
+
threadId: THREAD_ID,
|
|
84
|
+
...options.row,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const Harness = () => {
|
|
88
|
+
const actions = useThreadActions({ thread, isOpen });
|
|
89
|
+
return createElement(MessageToolbar, {
|
|
90
|
+
hasThread: true,
|
|
91
|
+
intelligenceOpen: false,
|
|
92
|
+
canToggleIntelligence: false,
|
|
93
|
+
onToggleIntelligence: () => undefined,
|
|
94
|
+
onToggleStar: actions.toggleStar,
|
|
95
|
+
isStarred: actions.isStarred,
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
harness = createDomHarness();
|
|
100
|
+
// The conversation as the server has it, in the cache before the first
|
|
101
|
+
// render — the pane answers from this, not from the list row.
|
|
102
|
+
harness.queryClient.setQueryData(conversationKey, {
|
|
103
|
+
items: [conversationRow(server.starred)],
|
|
104
|
+
});
|
|
105
|
+
harness.renderApp(createElement(Harness));
|
|
106
|
+
await harness.flush();
|
|
107
|
+
await harness.wait(20);
|
|
108
|
+
await harness.flush();
|
|
109
|
+
return harness;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const starButton = (dom: DomHarness) => dom.byLabel("Star");
|
|
113
|
+
|
|
114
|
+
const rendersStarred = (dom: DomHarness): boolean =>
|
|
115
|
+
starButton(dom).getAttribute("aria-pressed") === "true";
|
|
116
|
+
|
|
117
|
+
const conversationRequests = (): number =>
|
|
118
|
+
http?.to(`/threads/${THREAD_ID}/messages`).length ?? 0;
|
|
119
|
+
|
|
120
|
+
const starRequests = (): Array<boolean | undefined> =>
|
|
121
|
+
(http?.calls ?? [])
|
|
122
|
+
.filter((call) => call.method === "PATCH")
|
|
123
|
+
.map(
|
|
124
|
+
(call) => (call.body as { isStarred?: boolean } | undefined)?.isStarred,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
describe("the reading pane's star follows the open message (#602)", () => {
|
|
128
|
+
it("shows the message starred when the conversation says so, though its list row does not", async () => {
|
|
129
|
+
const dom = await mountToolbar({
|
|
130
|
+
server: { starred: true },
|
|
131
|
+
// What the mailbox listing last said about this message, from before
|
|
132
|
+
// it was starred — the state the pane used to answer from (#602).
|
|
133
|
+
row: { hasStars: false },
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
assert.equal(
|
|
137
|
+
rendersStarred(dom),
|
|
138
|
+
true,
|
|
139
|
+
"the star answers from the conversation, not the list row",
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("asks for the star to come off when a lit star is pressed", async () => {
|
|
144
|
+
const server: ServerState = { starred: true };
|
|
145
|
+
const dom = await mountToolbar({ server, row: { hasStars: false } });
|
|
146
|
+
|
|
147
|
+
dom.click(starButton(dom));
|
|
148
|
+
await dom.flush();
|
|
149
|
+
assert.deepEqual(
|
|
150
|
+
starRequests(),
|
|
151
|
+
[false],
|
|
152
|
+
"pressing a lit star unstars the message",
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("stars, then unstars, on consecutive presses", async () => {
|
|
157
|
+
const server: ServerState = { starred: false };
|
|
158
|
+
const dom = await mountToolbar({ server, row: { hasStars: false } });
|
|
159
|
+
assert.equal(rendersStarred(dom), false);
|
|
160
|
+
|
|
161
|
+
dom.click(starButton(dom));
|
|
162
|
+
await dom.flush();
|
|
163
|
+
assert.equal(server.starred, true);
|
|
164
|
+
assert.deepEqual(starRequests(), [true]);
|
|
165
|
+
|
|
166
|
+
// Nothing is put into the cache by hand here: the settle-invalidate has
|
|
167
|
+
// to re-read the conversation, which the mock now serves starred. Seeding
|
|
168
|
+
// it would make the second press pass even if the refresh never happened.
|
|
169
|
+
await dom.wait(20);
|
|
170
|
+
await dom.flush();
|
|
171
|
+
assert.equal(
|
|
172
|
+
rendersStarred(dom),
|
|
173
|
+
true,
|
|
174
|
+
"the star lights from the refreshed conversation",
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
dom.click(starButton(dom));
|
|
178
|
+
await dom.flush();
|
|
179
|
+
assert.equal(server.starred, false, "the second press unstars");
|
|
180
|
+
assert.deepEqual(starRequests(), [true, false]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("asks for no conversation for a thread the pane has not opened", async () => {
|
|
184
|
+
// The triage cursor moves a row at a time. A conversation pulled for the
|
|
185
|
+
// row under the cursor would be a request per keystroke, so a target that
|
|
186
|
+
// is not the open thread answers from its own listing row.
|
|
187
|
+
const dom = await mountToolbar({
|
|
188
|
+
server: { starred: false },
|
|
189
|
+
row: { hasStars: true },
|
|
190
|
+
isOpen: false,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
assert.equal(conversationRequests(), 0);
|
|
194
|
+
assert.equal(
|
|
195
|
+
rendersStarred(dom),
|
|
196
|
+
true,
|
|
197
|
+
"the cursor target answers from the row it came from",
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
@@ -15,10 +15,22 @@ import { useDeleteMessages } from "@/hooks/useDeleteMessages";
|
|
|
15
15
|
import { useMailboxAccount } from "@/hooks/useMailboxAccount";
|
|
16
16
|
import { useMoveMessages } from "@/hooks/useMoveMessages";
|
|
17
17
|
import { useThreadMessageIds } from "@/hooks/useThreadMessageIds";
|
|
18
|
+
import { useThreadConversation } from "@/hooks/useThreadRow";
|
|
18
19
|
import { useToggleStar } from "@/hooks/useToggleStar";
|
|
19
20
|
|
|
20
21
|
interface UseThreadActionsOptions {
|
|
21
22
|
thread: RemitImapThreadMessageResponse | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the pane has this thread open, so its conversation is on screen
|
|
25
|
+
* and already fetched. The star then answers from that conversation: a list
|
|
26
|
+
* row is a copy that survives its listing, and once the mail no longer
|
|
27
|
+
* matches the browsed predicate the row stops being refreshed, so a star
|
|
28
|
+
* read off it is whatever was true when it was last listed (#602).
|
|
29
|
+
*
|
|
30
|
+
* A cursor target is not open — it answers from its own live listing row,
|
|
31
|
+
* because pulling a conversation for it would be a request per keystroke.
|
|
32
|
+
*/
|
|
33
|
+
isOpen?: boolean;
|
|
22
34
|
/** Mailbox whose listings the mutations patch. Defaults to the thread's own. */
|
|
23
35
|
mailboxId?: string;
|
|
24
36
|
/** Account the move picker offers folders from. Defaults to the thread's own. */
|
|
@@ -37,6 +49,7 @@ export interface ThreadActions {
|
|
|
37
49
|
|
|
38
50
|
export const useThreadActions = ({
|
|
39
51
|
thread,
|
|
52
|
+
isOpen = false,
|
|
40
53
|
mailboxId,
|
|
41
54
|
accountId,
|
|
42
55
|
onAfterOptimisticRemove,
|
|
@@ -67,9 +80,22 @@ export const useThreadActions = ({
|
|
|
67
80
|
onAfterOptimisticRemove,
|
|
68
81
|
});
|
|
69
82
|
|
|
83
|
+
// The conversation the pane has open, off the entry `ConversationView` and
|
|
84
|
+
// `useThreadRow` already hold, so the toolbar and the message card answer
|
|
85
|
+
// from the same row for no extra request.
|
|
86
|
+
const conversation = useThreadConversation(
|
|
87
|
+
isOpen ? thread?.threadId : undefined,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const openMessage = conversation.find(
|
|
91
|
+
(message) => message.messageId === thread?.messageId,
|
|
92
|
+
);
|
|
93
|
+
const isStarred = openMessage?.hasStars ?? thread?.hasStars;
|
|
94
|
+
|
|
70
95
|
const { toggleStar: toggleStarFor } = useToggleStar({
|
|
71
96
|
threadId: thread?.threadId ?? "",
|
|
72
97
|
mailboxId: resolvedMailboxId ?? "",
|
|
98
|
+
messages: conversation,
|
|
73
99
|
});
|
|
74
100
|
|
|
75
101
|
const deleteThread = useCallback(() => {
|
|
@@ -87,13 +113,13 @@ export const useThreadActions = ({
|
|
|
87
113
|
|
|
88
114
|
const toggleStar = useCallback(() => {
|
|
89
115
|
if (!thread) return;
|
|
90
|
-
toggleStarFor(thread.messageId,
|
|
91
|
-
}, [thread, toggleStarFor]);
|
|
116
|
+
toggleStarFor(thread.messageId, isStarred ?? false);
|
|
117
|
+
}, [thread, isStarred, toggleStarFor]);
|
|
92
118
|
|
|
93
119
|
return {
|
|
94
120
|
mailboxId: resolvedMailboxId,
|
|
95
121
|
accountId: resolvedAccountId,
|
|
96
|
-
isStarred
|
|
122
|
+
isStarred,
|
|
97
123
|
deleteThread,
|
|
98
124
|
moveThread,
|
|
99
125
|
toggleStar,
|
|
@@ -2,6 +2,28 @@ import { threadDetailOperationsListThreadMessagesOptions } from "@remit/api-http
|
|
|
2
2
|
import type { RemitImapThreadMessageResponse } from "@remit/api-http-client/types.gen.ts";
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
|
|
5
|
+
const NO_MESSAGES: RemitImapThreadMessageResponse[] = [];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The messages a conversation holds, on the key the reading pane already uses.
|
|
9
|
+
*
|
|
10
|
+
* The single owner of `GET /threads/{threadId}/messages` for the client's
|
|
11
|
+
* hooks: everything that needs the conversation resolves off this one cache
|
|
12
|
+
* entry rather than a round trip of its own. A `threadId` of `undefined` asks
|
|
13
|
+
* for nothing.
|
|
14
|
+
*/
|
|
15
|
+
export const useThreadConversation = (
|
|
16
|
+
threadId: string | undefined,
|
|
17
|
+
): RemitImapThreadMessageResponse[] => {
|
|
18
|
+
const { data } = useQuery({
|
|
19
|
+
...threadDetailOperationsListThreadMessagesOptions({
|
|
20
|
+
path: { threadId: threadId ?? "" },
|
|
21
|
+
}),
|
|
22
|
+
enabled: Boolean(threadId),
|
|
23
|
+
});
|
|
24
|
+
return data?.items ?? NO_MESSAGES;
|
|
25
|
+
};
|
|
26
|
+
|
|
5
27
|
/**
|
|
6
28
|
* A thread's own row for the message the reader pointed at.
|
|
7
29
|
*
|
|
@@ -9,8 +31,7 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
9
31
|
* cross-folder search hit, or an address pasted into a fresh tab.
|
|
10
32
|
* `GET /threads/{threadId}/messages` returns the same row shape a listing does,
|
|
11
33
|
* `mailboxId` included, so the thread id is the whole address even though the
|
|
12
|
-
* mail is filed in some folder.
|
|
13
|
-
* this resolves off the same cache entry rather than a round trip of its own.
|
|
34
|
+
* mail is filed in some folder.
|
|
14
35
|
*
|
|
15
36
|
* A thread spans folders — the reader's own reply sits in Sent — so `messageId`
|
|
16
37
|
* picks the row they pointed at. With none, the newest message answers.
|
|
@@ -19,14 +40,7 @@ export const useThreadRow = (
|
|
|
19
40
|
threadId: string | undefined,
|
|
20
41
|
messageId: string | undefined,
|
|
21
42
|
): RemitImapThreadMessageResponse | undefined => {
|
|
22
|
-
const
|
|
23
|
-
...threadDetailOperationsListThreadMessagesOptions({
|
|
24
|
-
path: { threadId: threadId ?? "" },
|
|
25
|
-
}),
|
|
26
|
-
enabled: Boolean(threadId),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const items = data?.items ?? [];
|
|
43
|
+
const items = useThreadConversation(threadId);
|
|
30
44
|
const pointedAt = messageId
|
|
31
45
|
? items.find((item) => item.messageId === messageId)
|
|
32
46
|
: undefined;
|