@open-workspace/email 0.3.0 → 0.4.0
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/README.md +22 -22
- package/alchemy/index.ts +273 -0
- package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
- package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
- package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/_journal.json +20 -0
- package/drizzle/mailbox/migrations.js +12 -0
- package/index.ts +3 -1
- package/migrations/{0000_email.sql → 0000_dry_moon_knight.sql} +26 -20
- package/migrations/meta/0000_snapshot.json +125 -109
- package/migrations/meta/_journal.json +2 -2
- package/package.json +74 -68
- package/shared/attachment-preview.ts +37 -27
- package/shared/folder-order.ts +106 -0
- package/shared/mail-authentication.ts +8 -3
- package/shared/mail-feedback.ts +18 -25
- package/shared/mail-headers.ts +114 -39
- package/shared/mail-import.ts +38 -0
- package/shared/mail-path.ts +42 -0
- package/shared/mail-received.ts +174 -31
- package/shared/mail-remote.ts +59 -2
- package/shared/mail-sender-intel.ts +22 -4
- package/shared/mail.ts +77 -28
- package/shared/module.ts +33 -0
- package/shared/office-preview.ts +14 -2
- package/shared/pdfjs-assets.ts +35 -0
- package/shared/permissions.ts +73 -0
- package/shared/webhooks.ts +41 -0
- package/src/admin/blocked-senders.tsx +189 -0
- package/src/client.tsx +97 -0
- package/src/lib/mail-api.ts +9 -0
- package/src/mail/attachment-preview-dialog.tsx +161 -0
- package/src/mail/blocked-senders.tsx +138 -0
- package/src/mail/compose-window-chrome.tsx +194 -0
- package/src/mail/compose-window.tsx +486 -0
- package/src/mail/composer-asset-bookmarks.ts +409 -0
- package/src/mail/composer-asset.tsx +229 -0
- package/src/mail/composer-attachment-list.tsx +138 -0
- package/src/mail/composer-editor-document.ts +65 -0
- package/src/mail/composer-editor.tsx +284 -0
- package/src/mail/composer-linked-attachment-text.ts +12 -0
- package/src/mail/composer-recipient-fields.tsx +165 -0
- package/src/mail/composer-recipients.ts +208 -0
- package/src/mail/composer-session.ts +562 -0
- package/src/mail/composer-toolbar.tsx +303 -0
- package/src/mail/composer-upload-client.ts +105 -0
- package/src/mail/composer-upload-progress.ts +53 -0
- package/src/mail/conversation-list.tsx +550 -0
- package/src/mail/conversation-loading-skeleton.tsx +119 -0
- package/src/mail/conversation-message.tsx +346 -0
- package/src/mail/conversation-reply.tsx +470 -0
- package/src/mail/conversation-selection-toolbar.tsx +322 -0
- package/src/mail/conversation-view.tsx +437 -0
- package/src/mail/delivery-indicator.tsx +272 -0
- package/src/mail/email-html-body.tsx +203 -0
- package/src/mail/folder-glyph.tsx +46 -0
- package/src/mail/folder-manager.tsx +532 -0
- package/src/mail/format-bytes.ts +7 -0
- package/src/mail/mail-app-bar.tsx +253 -0
- package/src/mail/mail-background.tsx +12 -0
- package/src/mail/mail-dock.tsx +137 -0
- package/src/mail/mail-folders.ts +44 -0
- package/src/mail/mail-layout.css +236 -0
- package/src/mail/mail-location.ts +73 -0
- package/src/mail/mail-mailbox-sheet.tsx +275 -0
- package/src/mail/mail-nav-rail.tsx +129 -0
- package/src/mail/mail-nav.tsx +324 -0
- package/src/mail/mail-prefetch.ts +59 -0
- package/src/mail/mail-primitives.tsx +66 -0
- package/src/mail/mail-queries.ts +209 -0
- package/src/mail/mail-query-cache.ts +486 -0
- package/src/mail/mail-seed.ts +47 -0
- package/src/mail/mail-shell.tsx +126 -0
- package/src/mail/mailbox-ai-settings.tsx +185 -0
- package/src/mail/mailbox-realtime.tsx +251 -0
- package/src/mail/mailbox-route.tsx +15 -0
- package/src/mail/message-actions.tsx +353 -0
- package/src/mail/message-attachments.tsx +200 -0
- package/src/mail/message-format.ts +75 -0
- package/src/mail/message-header.tsx +260 -0
- package/src/mail/message-translation.tsx +225 -0
- package/src/mail/original-message-sheet.tsx +619 -0
- package/src/mail/original-message.ts +191 -0
- package/src/mail/outbound-notification.ts +53 -0
- package/src/mail/pane-splitter.tsx +117 -0
- package/src/mail/pdf-preview-toolbar.tsx +152 -0
- package/src/mail/pdf-preview.css +44 -0
- package/src/mail/pdf-preview.tsx +156 -0
- package/src/mail/pdf-translation-layout.ts +95 -0
- package/src/mail/print-message.ts +92 -0
- package/src/mail/reader-pane.tsx +535 -0
- package/src/mail/recipient-combobox.tsx +335 -0
- package/src/mail/recipient-field-row.tsx +34 -0
- package/src/mail/reply-to-warning.tsx +50 -0
- package/src/mail/sanitize-email-html.ts +430 -0
- package/src/mail/sender-actions.tsx +149 -0
- package/src/mail/sender-authentication.tsx +485 -0
- package/src/mail/sender-dialogs.tsx +384 -0
- package/src/mail/sender-security.tsx +545 -0
- package/src/mail/toolbar-tooltip.tsx +29 -0
- package/src/mail/translation-html.ts +49 -0
- package/src/mail/translation-language.ts +21 -0
- package/src/mail/types.ts +53 -0
- package/src/mail/unread-document-indicator.tsx +60 -0
- package/src/mail/use-compose-submission.ts +208 -0
- package/src/mail/use-composer-attachment-preflight.ts +184 -0
- package/src/mail/use-composer-submission.ts +117 -0
- package/src/mail/use-conversation-selection.ts +186 -0
- package/src/mail/use-mail-controller.ts +427 -0
- package/src/mail/use-mail-data.ts +279 -0
- package/src/mail/use-mail-safety.ts +155 -0
- package/src/mail/use-mail-send.ts +142 -0
- package/src/mail/use-pdf-translation-overlay.ts +156 -0
- package/src/mail/use-pdf-translation.ts +100 -0
- package/src/mail/use-pdf-viewer.ts +215 -0
- package/src/mail/use-reply-submission.ts +114 -0
- package/src/mail/use-sanitized-email-html.ts +20 -0
- package/src/mail/use-visible-message-read.ts +138 -0
- package/src/pwa/push-subscription.ts +151 -0
- package/src/settings/mail-apps-page.tsx +235 -0
- package/src/settings/notifications-page.tsx +291 -0
- package/worker/admin/blocked-sender-routes.ts +166 -0
- package/worker/admin/schemas.ts +11 -0
- package/worker/bindings.d.ts +14 -10
- package/worker/db/schema.ts +63 -40
- package/worker/jmap/eventsource.ts +84 -16
- package/worker/jmap/methods.ts +1630 -524
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +140 -56
- package/worker/jmap/routes.ts +366 -105
- package/worker/mail/access.ts +258 -21
- package/worker/mail/ai-classification.ts +36 -20
- package/worker/mail/ai-translation.ts +13 -6
- package/worker/mail/auth-headers.ts +395 -137
- package/worker/mail/bimi.ts +200 -73
- package/worker/mail/bootstrap.ts +79 -0
- package/worker/mail/capped-body.ts +36 -0
- package/worker/mail/classification-signals.ts +35 -25
- package/worker/mail/conversation-cursor.ts +30 -19
- package/worker/mail/delivery-events.ts +88 -62
- package/worker/mail/delivery-facts.ts +46 -10
- package/worker/mail/demo-routes.ts +34 -10
- package/worker/mail/doh.ts +62 -23
- package/worker/mail/downloads.ts +75 -40
- package/worker/mail/edge-cache.ts +155 -0
- package/worker/mail/header-metadata.ts +88 -22
- package/worker/mail/impersonation.ts +160 -38
- package/worker/mail/import-routes.ts +313 -0
- package/worker/mail/inbound-delivery.ts +19 -9
- package/worker/mail/inbound-threading.ts +18 -8
- package/worker/mail/inbound.ts +82 -40
- package/worker/mail/ip-intel.ts +110 -27
- package/worker/mail/isolate-cache.ts +35 -0
- package/worker/mail/link-domains.ts +29 -7
- package/worker/mail/mailbox-deletion.ts +10 -4
- package/worker/mail/mailbox-directory.ts +16 -6
- package/worker/mail/mailing-list.ts +94 -39
- package/worker/mail/message-security.ts +90 -15
- package/worker/mail/message-view.ts +18 -6
- package/worker/mail/office-conversion.ts +31 -9
- package/worker/mail/office-preview-container.ts +40 -13
- package/worker/mail/office-preview-queue.ts +76 -32
- package/worker/mail/org-domain.ts +8 -1
- package/worker/mail/outbound-content.ts +71 -26
- package/worker/mail/outbound-delivery.ts +31 -17
- package/worker/mail/outbound-service.ts +48 -30
- package/worker/mail/outbound-threading.ts +30 -17
- package/worker/mail/outbound.ts +97 -70
- package/worker/mail/outgoing-context.ts +25 -15
- package/worker/mail/participants.ts +44 -29
- package/worker/mail/push-notifications.ts +271 -173
- package/worker/mail/quote-parser.ts +21 -10
- package/worker/mail/r2-presigned-urls.ts +31 -25
- package/worker/mail/receive.ts +23 -11
- package/worker/mail/recipients.ts +6 -1
- package/worker/mail/remote-proxy.ts +187 -31
- package/worker/mail/remote-routes.ts +87 -0
- package/worker/mail/remote-token.ts +104 -0
- package/worker/mail/repeat.ts +19 -0
- package/worker/mail/reply-plan.ts +62 -33
- package/worker/mail/rfc.ts +32 -7
- package/worker/mail/routes.ts +870 -541
- package/worker/mail/safety-routes.ts +328 -200
- package/worker/mail/schemas.ts +84 -105
- package/worker/mail/search.ts +1 -0
- package/worker/mail/security-settings.ts +41 -9
- package/worker/mail/sender-intel.ts +206 -51
- package/worker/mail/spamhaus.ts +92 -45
- package/worker/mail/unsubscribe.ts +76 -18
- package/worker/mail/uploads.ts +126 -93
- package/worker/mail/webhook-source.ts +35 -12
- package/worker/mail/workspace-safety.ts +97 -38
- package/worker/mailbox/demo-html.ts +7 -7
- package/worker/mailbox/demo-seed.ts +10 -44
- package/worker/mailbox/demo.ts +595 -225
- package/worker/mailbox/email-index.ts +53 -0
- package/worker/mailbox/folder-model.ts +53 -17
- package/worker/mailbox/import-placement.ts +88 -0
- package/worker/mailbox/inbox-counts.ts +106 -0
- package/worker/mailbox/index.ts +1734 -721
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +8 -6
- package/worker/mailbox/office-preview-jobs.ts +56 -25
- package/worker/mailbox/schema.ts +87 -66
- package/worker/mailbox/senders.ts +176 -70
- package/worker/mcp/mail-action-tools.ts +128 -87
- package/worker/mcp/mail-compose-tools.ts +133 -82
- package/worker/mcp/mail-query-tools.ts +120 -71
- package/worker/mcp/mail-safety-tools.ts +321 -248
- package/worker/mcp/schemas.ts +43 -0
- package/worker/mcp/tools.ts +13 -10
- package/worker/module.ts +43 -18
- package/worker/sql.d.ts +8 -0
- package/alchemy.ts +0 -142
- package/containers/office-preview/Dockerfile +0 -10
- package/shared/mail-rules.ts +0 -156
- package/worker/admin/report-routes.ts +0 -164
- package/worker/mail/reported-messages.ts +0 -68
- package/worker/mailbox/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Dialog,
|
|
4
|
+
DialogClose,
|
|
5
|
+
DialogContent,
|
|
6
|
+
DialogDescription,
|
|
7
|
+
DialogFooter,
|
|
8
|
+
DialogHeader,
|
|
9
|
+
DialogTitle,
|
|
10
|
+
DialogTrigger,
|
|
11
|
+
Input,
|
|
12
|
+
Tabs,
|
|
13
|
+
TabsContent,
|
|
14
|
+
TabsList,
|
|
15
|
+
TabsTrigger,
|
|
16
|
+
TooltipProvider,
|
|
17
|
+
responseJson,
|
|
18
|
+
} from "@open-workspace/core/ui";
|
|
19
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
20
|
+
import {
|
|
21
|
+
ArrowDown,
|
|
22
|
+
ArrowUp,
|
|
23
|
+
Check,
|
|
24
|
+
Folder,
|
|
25
|
+
FolderCog,
|
|
26
|
+
LoaderCircle,
|
|
27
|
+
Pencil,
|
|
28
|
+
Plus,
|
|
29
|
+
ShieldBan,
|
|
30
|
+
Sparkles,
|
|
31
|
+
Trash2,
|
|
32
|
+
X,
|
|
33
|
+
} from "lucide-react";
|
|
34
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
35
|
+
import type { FormEvent } from "react";
|
|
36
|
+
import { toast } from "sonner";
|
|
37
|
+
|
|
38
|
+
import {
|
|
39
|
+
folderOrderPositions,
|
|
40
|
+
moveFolderInOrder,
|
|
41
|
+
} from "../../shared/folder-order";
|
|
42
|
+
import { mailApi } from "../lib/mail-api";
|
|
43
|
+
import { BlockedSendersManager } from "./blocked-senders";
|
|
44
|
+
import { FolderGlyph } from "./folder-glyph";
|
|
45
|
+
import { orderedFolders } from "./mail-folders";
|
|
46
|
+
import { foldersQuery } from "./mail-queries";
|
|
47
|
+
import { MailboxAiSettings } from "./mailbox-ai-settings";
|
|
48
|
+
import { ToolbarTooltip } from "./toolbar-tooltip";
|
|
49
|
+
import type { MailFolder } from "./types";
|
|
50
|
+
|
|
51
|
+
type FolderOperation =
|
|
52
|
+
| { type: "create"; name: string }
|
|
53
|
+
| { type: "rename"; folderId: string; name: string }
|
|
54
|
+
| { type: "delete"; folderId: string };
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The "Folders & AI sorting" dialog with its own trigger button. With
|
|
58
|
+
* `controlled`, the caller opens it and no trigger is drawn, e.g. from the
|
|
59
|
+
* gear at the end of the phone's dock.
|
|
60
|
+
*/
|
|
61
|
+
export function FolderManager({
|
|
62
|
+
mailboxId,
|
|
63
|
+
activeFolderId,
|
|
64
|
+
folders,
|
|
65
|
+
onSelectFolder,
|
|
66
|
+
controlled,
|
|
67
|
+
}: {
|
|
68
|
+
mailboxId: string;
|
|
69
|
+
activeFolderId: string;
|
|
70
|
+
folders: MailFolder[];
|
|
71
|
+
onSelectFolder: (folderId: string) => void;
|
|
72
|
+
controlled?: { open: boolean; onOpenChange: (open: boolean) => void };
|
|
73
|
+
}) {
|
|
74
|
+
const client = useQueryClient();
|
|
75
|
+
|
|
76
|
+
// Every folder but Inbox, which stays first: system folders move too, but keep their names.
|
|
77
|
+
const orderable = orderedFolders(folders).filter(
|
|
78
|
+
(folder) => folder.id !== "inbox"
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const hasCustomFolders = orderable.some((folder) => folder.kind === "custom");
|
|
82
|
+
const [ownOpen, setOwnOpen] = useState(false);
|
|
83
|
+
const open = controlled ? controlled.open : ownOpen;
|
|
84
|
+
const setOpen = controlled ? controlled.onOpenChange : setOwnOpen;
|
|
85
|
+
const [newName, setNewName] = useState("");
|
|
86
|
+
const [editingId, setEditingId] = useState<string | null>(null);
|
|
87
|
+
const [editingName, setEditingName] = useState("");
|
|
88
|
+
|
|
89
|
+
const [deleteCandidate, setDeleteCandidate] = useState<MailFolder | null>(
|
|
90
|
+
null
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const [section, setSection] = useState("folders");
|
|
94
|
+
|
|
95
|
+
const mutation = useMutation({
|
|
96
|
+
mutationFn: async (operation: FolderOperation) => {
|
|
97
|
+
if (operation.type === "create") {
|
|
98
|
+
return responseJson(
|
|
99
|
+
await mailApi.api.mail.mailboxes[":id"].folders.$post({
|
|
100
|
+
param: { id: mailboxId },
|
|
101
|
+
json: { name: operation.name },
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (operation.type === "rename") {
|
|
107
|
+
return responseJson(
|
|
108
|
+
await mailApi.api.mail.mailboxes[":id"].folders[":folderId"].$patch({
|
|
109
|
+
param: { id: mailboxId, folderId: operation.folderId },
|
|
110
|
+
json: { name: operation.name },
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return responseJson(
|
|
116
|
+
await mailApi.api.mail.mailboxes[":id"].folders[":folderId"].$delete({
|
|
117
|
+
param: { id: mailboxId, folderId: operation.folderId },
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
},
|
|
121
|
+
onSuccess: async (_result, operation) => {
|
|
122
|
+
if (operation.type === "create") {
|
|
123
|
+
setNewName("");
|
|
124
|
+
toast.success("Folder created");
|
|
125
|
+
} else if (operation.type === "rename") {
|
|
126
|
+
setEditingId(null);
|
|
127
|
+
toast.success("Folder renamed");
|
|
128
|
+
} else if (operation.type === "delete") {
|
|
129
|
+
setDeleteCandidate(null);
|
|
130
|
+
|
|
131
|
+
if (operation.folderId === activeFolderId) onSelectFolder("inbox");
|
|
132
|
+
toast.success("Folder deleted; its conversations moved to Inbox");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
await Promise.all([
|
|
136
|
+
client.invalidateQueries({ queryKey: ["folders", mailboxId] }),
|
|
137
|
+
client.invalidateQueries({ queryKey: ["conversations", mailboxId] }),
|
|
138
|
+
]);
|
|
139
|
+
},
|
|
140
|
+
onError: async (error) => {
|
|
141
|
+
toast.error(error.message);
|
|
142
|
+
await client.invalidateQueries({ queryKey: ["folders", mailboxId] });
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const folderQueryKey = foldersQuery(mailboxId).queryKey;
|
|
147
|
+
const reorderKey = ["folder-order", mailboxId];
|
|
148
|
+
|
|
149
|
+
// Moves show at once and queue one after another, so the arrows stay
|
|
150
|
+
// enabled (and keep keyboard focus) while earlier moves are saving.
|
|
151
|
+
const reorder = useMutation({
|
|
152
|
+
mutationKey: reorderKey,
|
|
153
|
+
scope: { id: `folder-order:${mailboxId}` },
|
|
154
|
+
mutationFn: async (folderIds: string[]) =>
|
|
155
|
+
responseJson(
|
|
156
|
+
await mailApi.api.mail.mailboxes[":id"].folders.order.$put({
|
|
157
|
+
param: { id: mailboxId },
|
|
158
|
+
json: { folderIds },
|
|
159
|
+
})
|
|
160
|
+
),
|
|
161
|
+
onMutate: async (folderIds) => {
|
|
162
|
+
await client.cancelQueries({ queryKey: folderQueryKey });
|
|
163
|
+
|
|
164
|
+
const positions = new Map(
|
|
165
|
+
folderOrderPositions(folderIds).map((item) => [item.id, item.sortOrder])
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
client.setQueryData(
|
|
169
|
+
folderQueryKey,
|
|
170
|
+
(data) =>
|
|
171
|
+
data && {
|
|
172
|
+
...data,
|
|
173
|
+
folders: data.folders.map((folder) => ({
|
|
174
|
+
...folder,
|
|
175
|
+
sortOrder: positions.get(folder.id) ?? folder.sortOrder,
|
|
176
|
+
})),
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
},
|
|
180
|
+
onError: (error) => {
|
|
181
|
+
// A conflict means this client's folder list is stale; the refresh below brings the real order back.
|
|
182
|
+
toast.error(error.message);
|
|
183
|
+
},
|
|
184
|
+
onSettled: async () => {
|
|
185
|
+
if (client.isMutating({ mutationKey: reorderKey }) > 1) return;
|
|
186
|
+
await client.invalidateQueries({ queryKey: folderQueryKey });
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
function createFolder(event: FormEvent) {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
const name = newName.trim();
|
|
193
|
+
|
|
194
|
+
if (name) mutation.mutate({ type: "create", name });
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function renameFolder(event: FormEvent, folderId: string) {
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
const name = editingName.trim();
|
|
200
|
+
|
|
201
|
+
if (name) mutation.mutate({ type: "rename", folderId, name });
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// A moved row's arrow keeps focus, so the keyboard can press it again; at
|
|
205
|
+
// either end, where that arrow turns off, focus goes to the other one.
|
|
206
|
+
const folderList = useRef<HTMLDivElement>(null);
|
|
207
|
+
|
|
208
|
+
const [moved, setMoved] = useState<{
|
|
209
|
+
folderId: string;
|
|
210
|
+
direction: -1 | 1;
|
|
211
|
+
} | null>(null);
|
|
212
|
+
|
|
213
|
+
// Where the moved folder is now: the arrows re-render there.
|
|
214
|
+
const movedIndex = moved
|
|
215
|
+
? orderable.findIndex((folder) => folder.id === moved.folderId)
|
|
216
|
+
: -1;
|
|
217
|
+
|
|
218
|
+
const lastIndex = orderable.length - 1;
|
|
219
|
+
|
|
220
|
+
useLayoutEffect(() => {
|
|
221
|
+
const focus = document.activeElement;
|
|
222
|
+
|
|
223
|
+
// Only when the move dropped focus or it is still on the list, never away from elsewhere.
|
|
224
|
+
if (
|
|
225
|
+
!moved ||
|
|
226
|
+
(focus && focus !== document.body && !folderList.current?.contains(focus))
|
|
227
|
+
) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// The first and last rows can't move further up or down.
|
|
232
|
+
const atEnd =
|
|
233
|
+
moved.direction === -1 ? movedIndex === 0 : movedIndex === lastIndex;
|
|
234
|
+
|
|
235
|
+
const direction = atEnd ? -moved.direction : moved.direction;
|
|
236
|
+
|
|
237
|
+
const target = folderList.current?.querySelector<HTMLButtonElement>(
|
|
238
|
+
`[data-move="${CSS.escape(`${moved.folderId}:${direction}`)}"]`
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
if (target && !target.disabled && document.activeElement !== target) {
|
|
242
|
+
target.focus();
|
|
243
|
+
}
|
|
244
|
+
}, [moved, movedIndex, lastIndex]);
|
|
245
|
+
|
|
246
|
+
function moveFolder(folderId: string, direction: -1 | 1) {
|
|
247
|
+
const folderIds = moveFolderInOrder(folders, folderId, direction);
|
|
248
|
+
|
|
249
|
+
if (!folderIds) return;
|
|
250
|
+
setMoved({ folderId, direction });
|
|
251
|
+
reorder.mutate(folderIds);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<TooltipProvider delay={300}>
|
|
256
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
257
|
+
{controlled ? null : (
|
|
258
|
+
<ToolbarTooltip label="Manage folders and AI sorting" side="bottom">
|
|
259
|
+
<DialogTrigger
|
|
260
|
+
render={
|
|
261
|
+
<Button
|
|
262
|
+
type="button"
|
|
263
|
+
variant="ghost"
|
|
264
|
+
size="icon-sm"
|
|
265
|
+
className="shrink-0 rounded-full"
|
|
266
|
+
/>
|
|
267
|
+
}
|
|
268
|
+
>
|
|
269
|
+
<FolderCog />
|
|
270
|
+
<span className="sr-only">Manage folders and AI sorting</span>
|
|
271
|
+
</DialogTrigger>
|
|
272
|
+
</ToolbarTooltip>
|
|
273
|
+
)}
|
|
274
|
+
<DialogContent className="sm:max-w-xl">
|
|
275
|
+
<DialogHeader>
|
|
276
|
+
<DialogTitle>Folders & AI sorting</DialogTitle>
|
|
277
|
+
<DialogDescription>
|
|
278
|
+
Organization settings are shared with everyone who can access this
|
|
279
|
+
mailbox.
|
|
280
|
+
</DialogDescription>
|
|
281
|
+
</DialogHeader>
|
|
282
|
+
|
|
283
|
+
<Tabs
|
|
284
|
+
value={section}
|
|
285
|
+
onValueChange={(value) => setSection(String(value))}
|
|
286
|
+
>
|
|
287
|
+
<TabsList className="w-full">
|
|
288
|
+
<TabsTrigger value="folders">
|
|
289
|
+
<Folder />
|
|
290
|
+
Folders
|
|
291
|
+
</TabsTrigger>
|
|
292
|
+
<TabsTrigger value="blocked">
|
|
293
|
+
<ShieldBan />
|
|
294
|
+
Blocked
|
|
295
|
+
</TabsTrigger>
|
|
296
|
+
<TabsTrigger value="ai">
|
|
297
|
+
<Sparkles />
|
|
298
|
+
AI sorting
|
|
299
|
+
</TabsTrigger>
|
|
300
|
+
</TabsList>
|
|
301
|
+
|
|
302
|
+
<TabsContent value="folders" className="space-y-4 pt-2">
|
|
303
|
+
<form className="flex gap-2" onSubmit={createFolder}>
|
|
304
|
+
<Input
|
|
305
|
+
aria-label="New folder name"
|
|
306
|
+
maxLength={80}
|
|
307
|
+
placeholder="New folder name"
|
|
308
|
+
value={newName}
|
|
309
|
+
onChange={(event) => setNewName(event.target.value)}
|
|
310
|
+
/>
|
|
311
|
+
<Button
|
|
312
|
+
type="submit"
|
|
313
|
+
disabled={!newName.trim() || mutation.isPending}
|
|
314
|
+
>
|
|
315
|
+
{mutation.isPending &&
|
|
316
|
+
mutation.variables?.type === "create" ? (
|
|
317
|
+
<LoaderCircle className="animate-spin" />
|
|
318
|
+
) : (
|
|
319
|
+
<Plus />
|
|
320
|
+
)}
|
|
321
|
+
Add
|
|
322
|
+
</Button>
|
|
323
|
+
</form>
|
|
324
|
+
|
|
325
|
+
<div
|
|
326
|
+
ref={folderList}
|
|
327
|
+
className="border-border/70 max-h-[min(23rem,50vh)] overflow-y-auto border-y"
|
|
328
|
+
>
|
|
329
|
+
{orderable.map((folder, index) => (
|
|
330
|
+
<div
|
|
331
|
+
key={folder.id}
|
|
332
|
+
className="border-border/60 flex min-h-12 items-center gap-2 border-b px-1 py-2 last:border-b-0"
|
|
333
|
+
>
|
|
334
|
+
{editingId === folder.id ? (
|
|
335
|
+
<form
|
|
336
|
+
className="flex min-w-0 flex-1 items-center gap-2"
|
|
337
|
+
onSubmit={(event) => renameFolder(event, folder.id)}
|
|
338
|
+
>
|
|
339
|
+
<Input
|
|
340
|
+
autoFocus
|
|
341
|
+
aria-label={`Rename ${folder.name}`}
|
|
342
|
+
maxLength={80}
|
|
343
|
+
value={editingName}
|
|
344
|
+
onChange={(event) =>
|
|
345
|
+
setEditingName(event.target.value)
|
|
346
|
+
}
|
|
347
|
+
/>
|
|
348
|
+
<ToolbarTooltip label="Save name">
|
|
349
|
+
<Button
|
|
350
|
+
type="submit"
|
|
351
|
+
variant="ghost"
|
|
352
|
+
size="icon-sm"
|
|
353
|
+
disabled={!editingName.trim() || mutation.isPending}
|
|
354
|
+
>
|
|
355
|
+
<Check />
|
|
356
|
+
<span className="sr-only">Save name</span>
|
|
357
|
+
</Button>
|
|
358
|
+
</ToolbarTooltip>
|
|
359
|
+
<ToolbarTooltip label="Cancel rename">
|
|
360
|
+
<Button
|
|
361
|
+
type="button"
|
|
362
|
+
variant="ghost"
|
|
363
|
+
size="icon-sm"
|
|
364
|
+
disabled={mutation.isPending}
|
|
365
|
+
onClick={() => setEditingId(null)}
|
|
366
|
+
>
|
|
367
|
+
<X />
|
|
368
|
+
<span className="sr-only">Cancel rename</span>
|
|
369
|
+
</Button>
|
|
370
|
+
</ToolbarTooltip>
|
|
371
|
+
</form>
|
|
372
|
+
) : (
|
|
373
|
+
<>
|
|
374
|
+
<FolderGlyph
|
|
375
|
+
folder={folder}
|
|
376
|
+
className="text-muted-foreground ml-2 size-4 shrink-0"
|
|
377
|
+
/>
|
|
378
|
+
<span className="min-w-0 flex-1 truncate text-sm font-medium">
|
|
379
|
+
{folder.name}
|
|
380
|
+
</span>
|
|
381
|
+
<div className="flex shrink-0 items-center">
|
|
382
|
+
<ToolbarTooltip label="Move up">
|
|
383
|
+
<Button
|
|
384
|
+
type="button"
|
|
385
|
+
variant="ghost"
|
|
386
|
+
size="icon-sm"
|
|
387
|
+
data-move={`${folder.id}:-1`}
|
|
388
|
+
disabled={index === 0}
|
|
389
|
+
onClick={() => moveFolder(folder.id, -1)}
|
|
390
|
+
>
|
|
391
|
+
<ArrowUp />
|
|
392
|
+
<span className="sr-only">
|
|
393
|
+
Move {folder.name} up
|
|
394
|
+
</span>
|
|
395
|
+
</Button>
|
|
396
|
+
</ToolbarTooltip>
|
|
397
|
+
<ToolbarTooltip label="Move down">
|
|
398
|
+
<Button
|
|
399
|
+
type="button"
|
|
400
|
+
variant="ghost"
|
|
401
|
+
size="icon-sm"
|
|
402
|
+
data-move={`${folder.id}:1`}
|
|
403
|
+
disabled={index === orderable.length - 1}
|
|
404
|
+
onClick={() => moveFolder(folder.id, 1)}
|
|
405
|
+
>
|
|
406
|
+
<ArrowDown />
|
|
407
|
+
<span className="sr-only">
|
|
408
|
+
Move {folder.name} down
|
|
409
|
+
</span>
|
|
410
|
+
</Button>
|
|
411
|
+
</ToolbarTooltip>
|
|
412
|
+
{folder.kind === "custom" ? (
|
|
413
|
+
<>
|
|
414
|
+
<ToolbarTooltip label="Rename">
|
|
415
|
+
<Button
|
|
416
|
+
type="button"
|
|
417
|
+
variant="ghost"
|
|
418
|
+
size="icon-sm"
|
|
419
|
+
disabled={mutation.isPending}
|
|
420
|
+
onClick={() => {
|
|
421
|
+
setEditingId(folder.id);
|
|
422
|
+
setEditingName(folder.name);
|
|
423
|
+
}}
|
|
424
|
+
>
|
|
425
|
+
<Pencil />
|
|
426
|
+
<span className="sr-only">
|
|
427
|
+
Rename {folder.name}
|
|
428
|
+
</span>
|
|
429
|
+
</Button>
|
|
430
|
+
</ToolbarTooltip>
|
|
431
|
+
<ToolbarTooltip label="Delete">
|
|
432
|
+
<Button
|
|
433
|
+
type="button"
|
|
434
|
+
variant="ghost"
|
|
435
|
+
size="icon-sm"
|
|
436
|
+
className="text-destructive"
|
|
437
|
+
disabled={mutation.isPending}
|
|
438
|
+
onClick={() => {
|
|
439
|
+
setOpen(false);
|
|
440
|
+
setDeleteCandidate(folder);
|
|
441
|
+
}}
|
|
442
|
+
>
|
|
443
|
+
<Trash2 />
|
|
444
|
+
<span className="sr-only">
|
|
445
|
+
Delete {folder.name}
|
|
446
|
+
</span>
|
|
447
|
+
</Button>
|
|
448
|
+
</ToolbarTooltip>
|
|
449
|
+
</>
|
|
450
|
+
) : (
|
|
451
|
+
// System folders keep their names; the blanks keep the arrows in one column.
|
|
452
|
+
<span aria-hidden="true" className="w-16" />
|
|
453
|
+
)}
|
|
454
|
+
</div>
|
|
455
|
+
</>
|
|
456
|
+
)}
|
|
457
|
+
</div>
|
|
458
|
+
))}
|
|
459
|
+
</div>
|
|
460
|
+
<p className="text-muted-foreground text-xs leading-relaxed">
|
|
461
|
+
Inbox always comes first. Sent, Archive, Spam and Trash can move
|
|
462
|
+
but keep their names.
|
|
463
|
+
{hasCustomFolders
|
|
464
|
+
? null
|
|
465
|
+
: " Create a folder to organize Inbox conversations and give AI another destination."}
|
|
466
|
+
</p>
|
|
467
|
+
</TabsContent>
|
|
468
|
+
|
|
469
|
+
<TabsContent value="blocked" className="pt-2">
|
|
470
|
+
<BlockedSendersManager
|
|
471
|
+
mailboxId={mailboxId}
|
|
472
|
+
active={open && section === "blocked"}
|
|
473
|
+
/>
|
|
474
|
+
</TabsContent>
|
|
475
|
+
|
|
476
|
+
<TabsContent value="ai" keepMounted className="space-y-4 pt-2">
|
|
477
|
+
<MailboxAiSettings
|
|
478
|
+
mailboxId={mailboxId}
|
|
479
|
+
active={open && section === "ai"}
|
|
480
|
+
/>
|
|
481
|
+
</TabsContent>
|
|
482
|
+
</Tabs>
|
|
483
|
+
</DialogContent>
|
|
484
|
+
</Dialog>
|
|
485
|
+
|
|
486
|
+
<Dialog
|
|
487
|
+
open={Boolean(deleteCandidate)}
|
|
488
|
+
onOpenChange={(nextOpen) => {
|
|
489
|
+
if (!nextOpen) setDeleteCandidate(null);
|
|
490
|
+
}}
|
|
491
|
+
>
|
|
492
|
+
<DialogContent>
|
|
493
|
+
<DialogHeader>
|
|
494
|
+
<DialogTitle>Delete {deleteCandidate?.name}?</DialogTitle>
|
|
495
|
+
<DialogDescription>
|
|
496
|
+
The folder will disappear for everyone. Its conversations will
|
|
497
|
+
return to Inbox.
|
|
498
|
+
</DialogDescription>
|
|
499
|
+
</DialogHeader>
|
|
500
|
+
<DialogFooter>
|
|
501
|
+
<DialogClose
|
|
502
|
+
render={<Button type="button" variant="outline" />}
|
|
503
|
+
onClick={() => setOpen(true)}
|
|
504
|
+
>
|
|
505
|
+
Cancel
|
|
506
|
+
</DialogClose>
|
|
507
|
+
<Button
|
|
508
|
+
type="button"
|
|
509
|
+
variant="destructive"
|
|
510
|
+
disabled={mutation.isPending}
|
|
511
|
+
onClick={() => {
|
|
512
|
+
if (deleteCandidate) {
|
|
513
|
+
mutation.mutate({
|
|
514
|
+
type: "delete",
|
|
515
|
+
folderId: deleteCandidate.id,
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}}
|
|
519
|
+
>
|
|
520
|
+
{mutation.isPending ? (
|
|
521
|
+
<LoaderCircle className="animate-spin" />
|
|
522
|
+
) : (
|
|
523
|
+
<Trash2 />
|
|
524
|
+
)}
|
|
525
|
+
Delete folder
|
|
526
|
+
</Button>
|
|
527
|
+
</DialogFooter>
|
|
528
|
+
</DialogContent>
|
|
529
|
+
</Dialog>
|
|
530
|
+
</TooltipProvider>
|
|
531
|
+
);
|
|
532
|
+
}
|