@remit/web-client 0.0.349 → 0.0.351

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.
@@ -45,6 +45,7 @@ export function CheckAgainProvider({ children }) {
45
45
  const [failures, setFailures] = useState(new Map());
46
46
  const runningRef = useRef(false);
47
47
  const stopRef = useRef(false);
48
+ const startRef = useRef(undefined);
48
49
  const settle = useCallback((targets) => {
49
50
  invalidateThreadListQueries(queryClient, threadListCacheKeys(targets.map((target) => target.mailboxId)));
50
51
  for (const threadId of new Set(targets.map((t) => t.threadId))) {
@@ -99,9 +100,13 @@ export function CheckAgainProvider({ children }) {
99
100
  }
100
101
  if (!showPanel) {
101
102
  for (const failure of outcome.failures) {
103
+ const retryTarget = failure.retryable
104
+ ? targets.find((target) => target.messageId === failure.messageId)
105
+ : undefined;
102
106
  pushError({
103
107
  title: "Couldn't check this message again",
104
108
  detail: `${failure.subject}: ${CHECK_AGAIN_FAILURE_SENTENCES[failure.code]}`,
109
+ onRetry: retryTarget && (() => startRef.current?.([retryTarget], false)),
105
110
  });
106
111
  }
107
112
  return;
@@ -142,6 +147,7 @@ export function CheckAgainProvider({ children }) {
142
147
  runningRef.current = false;
143
148
  });
144
149
  }, [run, pushError]);
150
+ startRef.current = start;
145
151
  const checkAgain = useCallback((requests, options) => {
146
152
  start([...requests], options.panel);
147
153
  }, [start]);
@@ -4,6 +4,7 @@ import { NavSidebar } from "@remit/ui";
4
4
  import { useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
5
5
  import { useCallback, useMemo } from "react";
6
6
  import { useTranslation } from "react-i18next";
7
+ import { useLabelUnreadCounts } from "../../hooks/useCollectionThreads";
7
8
  import { useLabelList } from "../../hooks/useLabels";
8
9
  import { folderFailure } from "../../lib/folder-failure";
9
10
  import { buildMailboxRoleMap, labelForMailbox, shouldShowUnreadBadgeForRole, } from "../../lib/folder-roles";
@@ -60,6 +61,17 @@ function toNavMailbox(mb, role, t) {
60
61
  failure: folderFailure(mb),
61
62
  };
62
63
  }
64
+ function toNavLabels(labels, unreadByLabel) {
65
+ return labels.map((label) => {
66
+ const unseen = unreadByLabel.get(label.labelId) ?? 0;
67
+ return {
68
+ id: labelNavId(label.labelId),
69
+ name: label.name,
70
+ color: label.color,
71
+ unseen: unseen > 0 ? unseen : undefined,
72
+ };
73
+ });
74
+ }
63
75
  /**
64
76
  * Pane 1 of the 4-pane shell. Data bridge that fetches mailboxes per account,
65
77
  * maps them onto the kit's NavAccount shape, and renders each entry as a real
@@ -85,20 +97,9 @@ export function MailSidebarAdapter({ accounts, onMailboxSelect, variant = "deskt
85
97
  // before its label is known. A failed label list leaves the tree whole.
86
98
  const { labels, isPending: labelsPending, isError: labelsFailed, } = useLabelList(accounts[0]?.accountId);
87
99
  const labelsSettled = !labelsPending || labelsFailed;
88
- const navLabels = useMemo(() => {
89
- const unseenByMailbox = new Map(mailboxQueries.flatMap((query) => (query.data?.items ?? []).map((mb) => [mb.mailboxId, mb.unseenCount])));
90
- return labels.map((label) => {
91
- const unseen = label.folders.reduce((sum, folder) => folder.state === "Missing"
92
- ? sum
93
- : sum + (unseenByMailbox.get(folder.mailboxId) ?? 0), 0);
94
- return {
95
- id: labelNavId(label.labelId),
96
- name: label.name,
97
- color: label.color,
98
- unseen: unseen > 0 ? unseen : undefined,
99
- };
100
- });
101
- }, [labels, mailboxQueries]);
100
+ const labelIds = useMemo(() => labels.map((label) => label.labelId), [labels]);
101
+ const unreadByLabel = useLabelUnreadCounts(labelIds);
102
+ const navLabels = useMemo(() => toNavLabels(labels, unreadByLabel), [labels, unreadByLabel]);
102
103
  const { data: outboxResponse } = useQuery(outboxOperationsListOutboxMessagesOptions());
103
104
  const outboxPendingCount = useMemo(() => (outboxResponse?.items ?? []).filter((item) => isOutboxListRow(item.status)).length, [outboxResponse?.items]);
104
105
  const navAccounts = useMemo(() => {
@@ -4,6 +4,7 @@ export interface PushErrorInput {
4
4
  title: string;
5
5
  detail?: string;
6
6
  action?: ErrorBannerAction;
7
+ onRetry?: () => void;
7
8
  /**
8
9
  * The error being reported, when there is one. Pass it: a banner is a soft
9
10
  * surface, and `pushError` uses this to refuse errors that are not soft —
@@ -65,5 +65,6 @@ export const buildEntry = (input, id, now) => ({
65
65
  title: input.title,
66
66
  detail: input.detail,
67
67
  action: input.action,
68
+ onRetry: input.onRetry,
68
69
  createdAt: now,
69
70
  });
@@ -41,4 +41,9 @@ export declare function useCollectionThreads(collection: ThreadCollection, crite
41
41
  * shows no number rather than a made-up one.
42
42
  */
43
43
  export declare function useCollectionUnreadCount(collection: ThreadCollection, criteria?: CollectionCriteria): number | undefined;
44
+ /**
45
+ * Each label's unread count, from the request the label list's header makes,
46
+ * so a sidebar badge and the list it opens count the same conversations.
47
+ */
48
+ export declare function useLabelUnreadCounts(labelIds: readonly string[]): ReadonlyMap<string, number>;
44
49
  export {};
@@ -25,7 +25,7 @@
25
25
  */
26
26
  import { unifiedThreadOperationsListAllThreadsQueryKey } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
27
27
  import { unifiedThreadOperationsListAllThreads } from "@remit/api-http-client/sdk.gen.ts";
28
- import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
28
+ import { useInfiniteQuery, useQueries, useQuery } from "@tanstack/react-query";
29
29
  import { useMemo } from "react";
30
30
  // The collection and `order` are the view itself, not a criterion, so they are
31
31
  // set last: no chip can widen the listing past the collection or reorder it.
@@ -81,13 +81,32 @@ export function useCollectionThreads(collection, criteria = {}) {
81
81
  * shows no number rather than a made-up one.
82
82
  */
83
83
  export function useCollectionUnreadCount(collection, criteria = {}) {
84
+ const { data } = useQuery(unreadCountOptions(collection, criteria));
85
+ return data?.count;
86
+ }
87
+ /**
88
+ * Each label's unread count, from the request the label list's header makes,
89
+ * so a sidebar badge and the list it opens count the same conversations.
90
+ */
91
+ export function useLabelUnreadCounts(labelIds) {
92
+ const counts = useQueries({
93
+ queries: labelIds.map((labelId) => unreadCountOptions({ labelId })),
94
+ combine: countsOf,
95
+ });
96
+ return useMemo(() => new Map(labelIds.flatMap((labelId, index) => {
97
+ const count = counts[index];
98
+ return count === undefined ? [] : [[labelId, count]];
99
+ })), [labelIds, counts]);
100
+ }
101
+ const countsOf = (results) => results.map((result) => result.data?.count);
102
+ function unreadCountOptions(collection, criteria = {}) {
84
103
  const query = {
85
104
  ...collectionQuery(collection, criteria),
86
105
  unread: true,
87
106
  count: true,
88
107
  results: false,
89
108
  };
90
- const { data } = useQuery({
109
+ return {
91
110
  queryKey: unifiedThreadOperationsListAllThreadsQueryKey({ query }),
92
111
  queryFn: async () => {
93
112
  const { data: page } = await unifiedThreadOperationsListAllThreads({
@@ -97,6 +116,5 @@ export function useCollectionUnreadCount(collection, criteria = {}) {
97
116
  return page;
98
117
  },
99
118
  staleTime: 60_000,
100
- });
101
- return data?.count;
119
+ };
102
120
  }
@@ -9,9 +9,8 @@ export declare const Route: import("@tanstack/router-core").Route<import("@tanst
9
9
  }>>;
10
10
  }, z.core.$strip>, import("@tanstack/router-core").ResolveParams<"/senders">, import("@tanstack/router-core").AnyContext, import("@tanstack/router-core").AnyContext, import("@tanstack/router-core").AnyContext, {}, undefined, unknown, unknown, unknown, unknown, undefined>;
11
11
  type SenderGroup = (typeof SENDER_GROUPS)[number];
12
- type SearchGroup = Exclude<SenderGroup, "vip">;
13
12
  export declare function SearchGroupPane({ group, query, onCount, }: {
14
- group: SearchGroup;
13
+ group: SenderGroup;
15
14
  query: string;
16
15
  onCount?: (matched: number, total: number | null) => void;
17
16
  }): import("react").JSX.Element;
@@ -3,12 +3,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  * Senders & Rules — 2-pane page: rule groups left, dense filterable
4
4
  * sender table right. Built to scale to hundreds of flagged senders.
5
5
  *
6
- * Backend gap (#427): there is no "list all addresses with flag X" endpoint.
7
- * VIP group: served from GET /me/vip-suggestions (suggested-to-promote list).
8
- * Muted / Blocked / Never in Spam groups: users search by name/email to find
9
- * flagged senders via GET /addresses/search; results are filtered client-side
10
- * on the flag, because the search takes no flag filter (spam spec gap 1).
11
- * The real flagged-address query endpoint is tracked as a backend issue.
6
+ * VIP, Blocked and Never in Spam list their whole group from
7
+ * GET /addresses/search with the `flag` filter. Muted has no server-side
8
+ * filter, so its senders are found by searching and filtered on the flag here.
12
9
  */
13
10
  import { addressDetailOperationsUpdateAddressMutation, addressOperationsSearchAddressesOptions, meOperationsListVipSuggestionsOptions, meOperationsListVipSuggestionsQueryKey, } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
14
11
  import { Button, ErrorState, Input, Kbd, SenderFlagRow, SenderGroupSwitch, SettingsShell, } from "@remit/ui";
@@ -36,7 +33,9 @@ const groupLabels = {
36
33
  blocked: "Blocked (reported)",
37
34
  neverSpam: "Never in Spam",
38
35
  };
36
+ const FLAGGED_GROUP_LIMIT = 500;
39
37
  const groupNouns = {
38
+ vip: "VIP",
40
39
  muted: "muted",
41
40
  blocked: "blocked",
42
41
  neverSpam: "never-in-spam",
@@ -45,7 +44,7 @@ const flagOf = (address, group) => address.flags?.[group];
45
44
  /* ------------------------------------------------------------------ */
46
45
  /* VIP group: served from suggestions endpoint */
47
46
  /* ------------------------------------------------------------------ */
48
- function VipGroupPane({ query, onCount, }) {
47
+ function VipGroupPane({ query }) {
49
48
  const { data, isPending, isError, error } = useQuery(meOperationsListVipSuggestionsOptions());
50
49
  const queryClient = useQueryClient();
51
50
  const addMutation = useMutation({
@@ -54,6 +53,9 @@ function VipGroupPane({ query, onCount, }) {
54
53
  queryClient.invalidateQueries({
55
54
  queryKey: meOperationsListVipSuggestionsQueryKey(),
56
55
  });
56
+ queryClient.invalidateQueries({
57
+ queryKey: [{ _id: "addressOperationsSearchAddresses" }],
58
+ });
57
59
  },
58
60
  });
59
61
  const suggestions = data?.suggestions ?? [];
@@ -62,9 +64,6 @@ function VipGroupPane({ query, onCount, }) {
62
64
  ? suggestions.filter((s) => (s.displayName ?? "").toLowerCase().includes(q) ||
63
65
  s.normalizedEmail.toLowerCase().includes(q))
64
66
  : suggestions;
65
- useEffect(() => {
66
- onCount?.(filtered.length, suggestions.length);
67
- }, [onCount, filtered.length, suggestions.length]);
68
67
  if (isPending) {
69
68
  return (_jsx("div", { className: "px-row-inset py-3 text-sm text-fg-subtle animate-pulse", children: "Loading VIP suggestions\u2026" }));
70
69
  }
@@ -93,15 +92,20 @@ function VipGroupPane({ query, onCount, }) {
93
92
  }, children: "Add VIP" }) }, s.addressId)))] }));
94
93
  }
95
94
  /* ------------------------------------------------------------------ */
96
- /* Muted / Blocked groups: search-based (backend gap noted) */
95
+ /* Flag groups: listed through the address search */
97
96
  /* ------------------------------------------------------------------ */
98
97
  export function SearchGroupPane({ group, query, onCount, }) {
99
98
  const debouncedQ = useDebouncedValue(query.trim(), 300);
100
99
  const queryClient = useQueryClient();
101
100
  const [retryId, setRetryId] = useState(null);
102
- const enabled = debouncedQ.length >= 2;
101
+ const trustFlag = group === "muted" ? undefined : group;
102
+ const enabled = trustFlag !== undefined || debouncedQ.length >= 2;
103
103
  const searchOptions = addressOperationsSearchAddressesOptions({
104
- query: { q: debouncedQ, limit: 50 },
104
+ query: {
105
+ q: debouncedQ,
106
+ limit: trustFlag ? FLAGGED_GROUP_LIMIT : 50,
107
+ flag: trustFlag,
108
+ },
105
109
  });
106
110
  const { data, isPending, isError, error } = useQuery({
107
111
  ...searchOptions,
@@ -113,15 +117,14 @@ export function SearchGroupPane({ group, query, onCount, }) {
113
117
  queryClient.invalidateQueries({ queryKey: searchOptions.queryKey });
114
118
  },
115
119
  });
116
- const items = (data?.items ?? []).filter((a) => flagOf(a, group)?.value ?? false);
120
+ const items = trustFlag
121
+ ? (data?.items ?? [])
122
+ : (data?.items ?? []).filter((a) => flagOf(a, group)?.value ?? false);
117
123
  useEffect(() => {
118
- // Total flagged count is unknown (no list-all-flagged endpoint), so the
119
- // group rail shows the live matched-row count while a search is active.
120
- onCount?.(enabled ? items.length : 0, null);
121
- }, [onCount, enabled, items.length]);
124
+ onCount?.(enabled ? items.length : 0, trustFlag ? items.length : null);
125
+ }, [onCount, enabled, items.length, trustFlag]);
122
126
  if (!enabled) {
123
- // Backend gap: no list-all-flagged endpoint; prompt user to search.
124
- return (_jsxs("div", { className: "px-row-inset py-5 text-sm text-fg-subtle space-y-2", children: [_jsxs("p", { children: ["Type 2+ characters to search ", groupNouns[group], " senders by name or address."] }), _jsxs("p", { className: "text-2xs text-fg-subtle", children: ["Note: a dedicated flagged-address list endpoint is in the backlog. Press ", _jsx(Kbd, { children: "m" }), " on any message to mute its sender; ", _jsx(Kbd, { children: "b" }), " to block."] })] }));
127
+ return (_jsxs("div", { className: "px-row-inset py-5 text-sm text-fg-subtle space-y-2", children: [_jsxs("p", { children: ["Type 2+ characters to search ", groupNouns[group], " senders by name or address."] }), _jsxs("p", { className: "text-2xs text-fg-subtle", children: ["Press ", _jsx(Kbd, { children: "m" }), " on any message to mute its sender; ", _jsx(Kbd, { children: "b" }), " to block."] })] }));
125
128
  }
126
129
  if (isPending) {
127
130
  return (_jsx("div", { className: "px-row-inset py-3 text-sm text-fg-subtle animate-pulse", children: "Searching\u2026" }));
@@ -130,7 +133,9 @@ export function SearchGroupPane({ group, query, onCount, }) {
130
133
  return (_jsx("div", { className: "px-row-inset py-3", children: _jsx(ErrorState, { variant: "inline", title: "Search failed", error: error }) }));
131
134
  }
132
135
  if (items.length === 0) {
133
- return (_jsxs("p", { className: "px-row-inset py-5 text-sm text-fg-subtle", children: ["No ", groupNouns[group], " senders matching \u201C", debouncedQ, "\u201D."] }));
136
+ return (_jsx("p", { className: "px-row-inset py-5 text-sm text-fg-subtle", children: debouncedQ
137
+ ? `No ${groupNouns[group]} senders matching \u201c${debouncedQ}\u201d.`
138
+ : `No ${groupNouns[group]} senders yet.` }));
134
139
  }
135
140
  return (_jsx(_Fragment, { children: items.map((a) => {
136
141
  const flag = flagOf(a, group);
@@ -190,15 +195,8 @@ function SendersSettings() {
190
195
  });
191
196
  const [query, setQuery] = useState("");
192
197
  const [helpOpen, setHelpOpen] = useState(true);
193
- // Per-group counts for the rail + footer. VIP total is the suggestions
194
- // list size; muted/blocked have no list endpoint, so their total is null
195
- // (the rail shows the live matched-row count instead of a stale total).
196
198
  const [matched, setMatched] = useState(0);
197
- const [groupCounts, setGroupCounts] = useState({ vip: 0, muted: null, blocked: null, neverSpam: null });
198
- const handleVipCount = useCallback((m, total) => {
199
- setMatched(m);
200
- setGroupCounts((prev) => ({ ...prev, vip: total }));
201
- }, []);
199
+ const [groupCounts, setGroupCounts] = useState({ vip: null, muted: null, blocked: null, neverSpam: null });
202
200
  const handleSearchCount = useCallback((m, _total) => {
203
201
  setMatched(m);
204
202
  setGroupCounts((prev) => ({ ...prev, [group]: m }));
@@ -211,7 +209,7 @@ function SendersSettings() {
211
209
  id: g,
212
210
  label: groupLabels[g],
213
211
  count: groupCounts[g],
214
- })) }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("div", { className: "border-b border-line px-row-inset py-2", children: _jsx(Input, { icon: _jsx(Search, { className: "size-4" }), placeholder: `Filter ${groupLabels[group].toLowerCase()} by name or address`, className: "h-8 max-w-sm", value: query, onChange: (e) => setQuery(e.target.value) }) }), _jsx("div", { className: "min-h-0 flex-1 divide-y divide-line overflow-y-auto", children: group === "vip" ? (_jsx(VipGroupPane, { query: query, onCount: handleVipCount })) : (_jsx(SearchGroupPane, { group: group, query: query, onCount: handleSearchCount })) }), _jsxs("footer", { className: "flex items-center justify-between border-t border-line px-row-inset py-1 text-2xs text-fg-subtle", children: [_jsx("span", { children: total != null
212
+ })) }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("div", { className: "border-b border-line px-row-inset py-2", children: _jsx(Input, { icon: _jsx(Search, { className: "size-4" }), placeholder: `Filter ${groupLabels[group].toLowerCase()} by name or address`, className: "h-8 max-w-sm", value: query, onChange: (e) => setQuery(e.target.value) }) }), _jsxs("div", { className: "min-h-0 flex-1 divide-y divide-line overflow-y-auto", children: [_jsx(SearchGroupPane, { group: group, query: query, onCount: handleSearchCount }), group === "vip" && _jsx(VipGroupPane, { query: query })] }), _jsxs("footer", { className: "flex items-center justify-between border-t border-line px-row-inset py-1 text-2xs text-fg-subtle", children: [_jsx("span", { children: total != null
215
213
  ? `${matched} of ${total} flagged senders`
216
214
  : `${matched} flagged senders` }), _jsxs("span", { children: [_jsx(Kbd, { children: "j" }), " ", _jsx(Kbd, { children: "k" }), " navigate \u00B7 ", _jsx(Kbd, { children: "\u232B" }), " remove flag"] })] })] })] }) }));
217
215
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/web-client",
3
- "version": "0.0.349",
3
+ "version": "0.0.351",
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": {
@@ -91,7 +91,7 @@
91
91
  },
92
92
  "dependencies": {
93
93
  "@hookform/resolvers": "5.4.0",
94
- "@remit/ui": "0.0.240",
94
+ "@remit/ui": "0.0.242",
95
95
  "@tanstack/react-query": "5.101.2",
96
96
  "@tanstack/react-query-devtools": "5.101.2",
97
97
  "@tanstack/react-router": "1.170.18",