@remit/web-client 0.0.186 → 0.0.187

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/web-client",
3
- "version": "0.0.186",
3
+ "version": "0.0.187",
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": {
@@ -2,7 +2,6 @@ import {
2
2
  messageBulkOperationsUpdateFlagsMutation,
3
3
  threadDetailOperationsListThreadMessagesQueryKey,
4
4
  } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
5
- import type { RemitImapThreadMessageResponse } from "@remit/api-http-client/types.gen.ts";
6
5
  import { useMutation, useQueryClient } from "@tanstack/react-query";
7
6
  import { useNavigate } from "@tanstack/react-router";
8
7
  import {
@@ -32,29 +31,13 @@ import {
32
31
  patchThreadListQueries,
33
32
  restoreThreadListQueries,
34
33
  snapshotThreadListQueries,
35
- type ThreadListSnapshotEntry,
34
+ type ThreadMessagesData,
35
+ type ThreadMutationContext,
36
36
  threadListCacheKeys,
37
37
  } from "@/lib/thread-list-cache";
38
38
  import { useOpenThreadPath, useRetainOpenPanels } from "@/routing";
39
39
  import { MoveToTrigger } from "./MoveToTrigger";
40
40
 
41
- interface ThreadMessagesData {
42
- items: RemitImapThreadMessageResponse[];
43
- [key: string]: unknown;
44
- }
45
-
46
- interface SnapshotEntry<T> {
47
- queryKey: readonly unknown[];
48
- data: T;
49
- }
50
-
51
- interface MarkUnreadContext {
52
- threadMessagesPrefix: readonly unknown[];
53
- listPrefixes: ReadonlyArray<readonly unknown[]>;
54
- previousThreadMessages: SnapshotEntry<ThreadMessagesData>[];
55
- previousThreadsList: ThreadListSnapshotEntry[];
56
- }
57
-
58
41
  interface MessageActionMenuProps {
59
42
  messageId: string;
60
43
  threadId: string;
@@ -109,7 +92,7 @@ export const MessageActionMenu = ({
109
92
 
110
93
  const { mutate: updateFlags, isPending: isUpdatingFlags } = useMutation({
111
94
  ...messageBulkOperationsUpdateFlagsMutation(),
112
- onMutate: async (variables): Promise<MarkUnreadContext> => {
95
+ onMutate: async (variables): Promise<ThreadMutationContext> => {
113
96
  const isReadNext = variables.body.isRead ?? true;
114
97
  const targetIds = new Set(variables.body.messageIds ?? []);
115
98
 
@@ -16,7 +16,8 @@ import {
16
16
  patchThreadListQueries,
17
17
  restoreThreadListQueries,
18
18
  snapshotThreadListQueries,
19
- type ThreadListSnapshotEntry,
19
+ type ThreadMessagesData,
20
+ type ThreadMutationContext,
20
21
  threadListCacheKeys,
21
22
  } from "@/lib/thread-list-cache";
22
23
 
@@ -39,23 +40,6 @@ interface UseDeleteMessagesOptions {
39
40
  onAfterOptimisticRemove?: (messageIds: string[]) => void;
40
41
  }
41
42
 
42
- interface ThreadMessagesData {
43
- items: RemitImapThreadMessageResponse[];
44
- [key: string]: unknown;
45
- }
46
-
47
- interface SnapshotEntry<T> {
48
- queryKey: readonly unknown[];
49
- data: T;
50
- }
51
-
52
- interface DeleteContext {
53
- threadMessagesPrefix: readonly unknown[];
54
- listPrefixes: ReadonlyArray<readonly unknown[]>;
55
- previousThreadMessages: SnapshotEntry<ThreadMessagesData>[];
56
- previousThreadsList: ThreadListSnapshotEntry[];
57
- }
58
-
59
43
  /**
60
44
  * Pure helper: drop the messages in `messageIds` from a single page's items.
61
45
  *
@@ -94,7 +78,7 @@ export const useDeleteMessages = ({
94
78
 
95
79
  const { mutateAsync, isPending } = useMutation({
96
80
  ...messageBulkOperationsDeleteMessagesMutation(),
97
- onMutate: async (variables): Promise<DeleteContext> => {
81
+ onMutate: async (variables): Promise<ThreadMutationContext> => {
98
82
  const messageIds = new Set(variables.body.messageIds ?? []);
99
83
 
100
84
  const threadMessagesPrefix = threadId
@@ -16,7 +16,8 @@ import {
16
16
  patchThreadListQueries,
17
17
  restoreThreadListQueries,
18
18
  snapshotThreadListQueries,
19
- type ThreadListSnapshotEntry,
19
+ type ThreadMessagesData,
20
+ type ThreadMutationContext,
20
21
  threadListCacheKeys,
21
22
  } from "@/lib/thread-list-cache";
22
23
 
@@ -28,23 +29,6 @@ interface UseMarkAsReadOptions {
28
29
  accountId?: string;
29
30
  }
30
31
 
31
- interface ThreadMessagesData {
32
- items: RemitImapThreadMessageResponse[];
33
- [key: string]: unknown;
34
- }
35
-
36
- interface SnapshotEntry<T> {
37
- queryKey: readonly unknown[];
38
- data: T;
39
- }
40
-
41
- interface MarkAsReadContext {
42
- threadMessagesPrefix: readonly unknown[];
43
- listPrefixes: ReadonlyArray<readonly unknown[]>;
44
- previousThreadMessages: SnapshotEntry<ThreadMessagesData>[];
45
- previousThreadsList: ThreadListSnapshotEntry[];
46
- }
47
-
48
32
  /**
49
33
  * Dwell before a message the user is viewing is marked read. A glance closed
50
34
  * within this window leaves it unread (#140). Applied by the single shared
@@ -145,7 +129,7 @@ export const useMarkAsRead = ({
145
129
  const { mutate: markAsRead } = useMutation({
146
130
  ...messageBulkOperationsUpdateFlagsMutation(),
147
131
  meta: softErrorMeta,
148
- onMutate: async (variables): Promise<MarkAsReadContext> => {
132
+ onMutate: async (variables): Promise<ThreadMutationContext> => {
149
133
  const messageIds = new Set(variables.body.messageIds ?? []);
150
134
  const isRead = variables.body.isRead ?? true;
151
135
 
@@ -15,7 +15,8 @@ import {
15
15
  patchThreadListQueries,
16
16
  restoreThreadListQueries,
17
17
  snapshotThreadListQueries,
18
- type ThreadListSnapshotEntry,
18
+ type ThreadMessagesData,
19
+ type ThreadMutationContext,
19
20
  threadListCacheKeys,
20
21
  } from "@/lib/thread-list-cache";
21
22
 
@@ -31,23 +32,6 @@ interface UseMoveMessagesOptions {
31
32
  onAfterOptimisticRemove?: (messageIds: string[]) => void;
32
33
  }
33
34
 
34
- interface ThreadMessagesData {
35
- items: RemitImapThreadMessageResponse[];
36
- [key: string]: unknown;
37
- }
38
-
39
- interface SnapshotEntry<T> {
40
- queryKey: readonly unknown[];
41
- data: T;
42
- }
43
-
44
- interface MoveContext {
45
- threadMessagesPrefix: readonly unknown[];
46
- listPrefixes: ReadonlyArray<readonly unknown[]>;
47
- previousThreadMessages: SnapshotEntry<ThreadMessagesData>[];
48
- previousThreadsList: ThreadListSnapshotEntry[];
49
- }
50
-
51
35
  /**
52
36
  * Pure helper: drop the messages in `messageIds` from a single page's items.
53
37
  *
@@ -73,7 +57,7 @@ export const useMoveMessages = ({
73
57
 
74
58
  const { mutateAsync, isPending, isError } = useMutation({
75
59
  ...messageBulkOperationsMoveMessagesMutation(),
76
- onMutate: async (variables): Promise<MoveContext> => {
60
+ onMutate: async (variables): Promise<ThreadMutationContext> => {
77
61
  const messageIds = new Set(variables.body.messageIds ?? []);
78
62
 
79
63
  const threadMessagesPrefix = threadId
@@ -13,7 +13,8 @@ import {
13
13
  patchThreadListQueries,
14
14
  restoreThreadListQueries,
15
15
  snapshotThreadListQueries,
16
- type ThreadListSnapshotEntry,
16
+ type ThreadMessagesData,
17
+ type ThreadMutationContext,
17
18
  threadListCacheKeys,
18
19
  } from "@/lib/thread-list-cache";
19
20
 
@@ -48,23 +49,6 @@ export const resolveMailboxForMessage = (
48
49
  messages?.find((message) => message.messageId === messageId)?.mailboxId ??
49
50
  fallbackMailboxId;
50
51
 
51
- interface ThreadMessagesData {
52
- items: RemitImapThreadMessageResponse[];
53
- [key: string]: unknown;
54
- }
55
-
56
- interface SnapshotEntry<T> {
57
- queryKey: readonly unknown[];
58
- data: T;
59
- }
60
-
61
- interface ToggleStarContext {
62
- threadMessagesPrefix: readonly unknown[];
63
- listPrefixes: ReadonlyArray<readonly unknown[]>;
64
- previousThreadMessages: SnapshotEntry<ThreadMessagesData>[];
65
- previousThreadsList: ThreadListSnapshotEntry[];
66
- }
67
-
68
52
  export const toggleStarsInItems = (
69
53
  items: RemitImapThreadMessageResponse[],
70
54
  messageId: string,
@@ -84,7 +68,7 @@ export const useToggleStar = ({
84
68
 
85
69
  const { mutate, isPending, variables } = useMutation({
86
70
  ...messageOperationsUpdateMessageFlagsMutation(),
87
- onMutate: async (vars): Promise<ToggleStarContext> => {
71
+ onMutate: async (vars): Promise<ThreadMutationContext> => {
88
72
  const messageId = vars.path.messageId;
89
73
  const nextStarred = vars.body.isStarred ?? false;
90
74
 
@@ -11,19 +11,15 @@ import type {
11
11
  import { useMutation, useQueryClient } from "@tanstack/react-query";
12
12
  import { useErrorBanners } from "@/components/ui/ErrorBannerProvider";
13
13
  import { buildMutationErrorBanner } from "@/components/ui/error-banners";
14
+ import type { SnapshotEntry } from "@/lib/thread-list-cache";
14
15
 
15
16
  interface UseToggleTrustedOptions {
16
17
  messageId: string;
17
18
  }
18
19
 
19
- interface SnapshotEntry {
20
- queryKey: readonly unknown[];
21
- data: RemitImapDescribeMessageResponse;
22
- }
23
-
24
20
  interface ToggleTrustedContext {
25
21
  describePrefix: readonly unknown[];
26
- previous: SnapshotEntry[];
22
+ previous: SnapshotEntry<RemitImapDescribeMessageResponse>[];
27
23
  }
28
24
 
29
25
  export const buildTrustedFlag = (
@@ -7,9 +7,31 @@ import type { RemitImapThreadMessageResponse } from "@remit/api-http-client/type
7
7
  import type { QueryClient } from "@tanstack/react-query";
8
8
  import { patchThreadListCache, type ThreadListCache } from "./thread-cache.js";
9
9
 
10
- export interface ThreadListSnapshotEntry {
10
+ export interface SnapshotEntry<T> {
11
11
  queryKey: readonly unknown[];
12
- data: ThreadListCache;
12
+ data: T;
13
+ }
14
+
15
+ export type ThreadListSnapshotEntry = SnapshotEntry<ThreadListCache>;
16
+
17
+ /** A cached page of one thread's messages, as the thread-detail endpoint serves it. */
18
+ export interface ThreadMessagesData {
19
+ items: RemitImapThreadMessageResponse[];
20
+ [key: string]: unknown;
21
+ }
22
+
23
+ /**
24
+ * The rollback state an optimistic thread mutation captures in `onMutate`.
25
+ *
26
+ * The shape belongs to the snapshot/restore helpers below rather than to any
27
+ * one mutation, so mark-read, star, delete and move all carry the same one
28
+ * (#868).
29
+ */
30
+ export interface ThreadMutationContext {
31
+ threadMessagesPrefix: readonly unknown[];
32
+ listPrefixes: ReadonlyArray<readonly unknown[]>;
33
+ previousThreadMessages: SnapshotEntry<ThreadMessagesData>[];
34
+ previousThreadsList: ThreadListSnapshotEntry[];
13
35
  }
14
36
 
15
37
  /**