@remit/web-client 0.0.349 → 0.0.350

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
  }
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.350",
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.241",
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",