Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | 88x 88x 88x 88x 88x 88x 9x 79x 77x 3x 74x 72x 57x 55x 4x 51x 1x 50x 2x 2x 2x 2x 2x 2x 13x 13x 13x 13x 7x 7x 7x 7x 7x 10x 7x 7x 7x 7x 7x 7x 7x 7x 6x 6x 6x 7x 489x 489x 489x 1x 1x 489x 3x 7x 1x 1x 1x 539x 88x 88x 5x 5x 1x | import { type ReactNode, useCallback, useEffect, useState } from "react";
import type { GlobalSyncStatus, Identity, Label } from "../api";
import {
ArchiveIcon,
ComposeIcon,
DraftIcon,
InboxIcon,
MailAllIcon,
MoonIcon,
RefreshIcon,
SearchIcon,
SendIcon,
SettingsIcon,
SpamIcon,
StarIcon,
SunIcon,
TrashIcon,
UnreadIcon,
} from "./Icons";
import { LABEL_ICONS, LabelManager } from "./LabelManager";
function labelIcon(label: Label): ReactNode {
const cls = "w-4 h-4 flex-shrink-0";
Iif (label.icon) {
const IconComponent = LABEL_ICONS[label.icon];
if (IconComponent) return <IconComponent className={cls} />;
}
const segments = label.name.split("/");
const name = (segments[segments.length - 1] ?? label.name).toLowerCase();
Iif (name === "inbox") return <InboxIcon className={cls} />;
if (name === "sent" || name === "sent mail" || name === "sent items")
return <SendIcon className={cls} />;
if (name === "drafts" || name === "draft") return <DraftIcon className={cls} />;
if (name === "trash" || name === "deleted" || name === "deleted items")
return <TrashIcon className={cls} />;
if (name === "junk" || name === "spam") return <SpamIcon className={cls} />;
if (name === "archive" || name === "all mail") return <ArchiveIcon className={cls} />;
if (name === "starred" || name === "flagged") return <StarIcon className={cls} filled />;
if (label.source === "connector") {
return (
<svg className={cls} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<title>Identity</title>
<path d="M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2" />
<circle cx="12" cy="7" r="4" />
</svg>
);
}
if (label.color) {
return (
<span
className="w-3 h-3 rounded-full flex-shrink-0"
style={{ backgroundColor: label.color }}
/>
);
}
return (
<svg className={cls} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<title>Label</title>
<path d="M20.59 13.41l-7.17 7.17a2 2 0 01-2.83 0L2 12V2h10l8.59 8.59a2 2 0 010 2.82z" />
<line x1="7" y1="7" x2="7.01" y2="7" />
</svg>
);
}
/** Sentinel label ID for the "All Mail" virtual view */
export const ALL_MAIL_LABEL_ID = -1;
/** Sentinel label ID for the "Unread" virtual view */
export const UNREAD_LABEL_ID = -2;
/** Sentinel label ID for the promoted "Inbox" virtual view */
export const INBOX_LABEL_ID = -3;
/** Sentinel label ID for the unified cross-identity inbox view */
export const UNIFIED_INBOX_LABEL_ID = -4;
/** Sentinel label ID for the unified cross-identity All Mail view */
export const UNIFIED_ALL_MAIL_LABEL_ID = -5;
/** Sentinel label ID for the unified cross-identity Unread view */
export const UNIFIED_UNREAD_LABEL_ID = -6;
interface SidebarProps {
identities: Identity[];
labels: Label[];
selectedLabelId: number | null;
filterLabelIds: number[];
onSelectLabel: (id: number) => void;
onToggleFilterLabel: (id: number) => void;
onClearFilter: () => void;
onCompose: () => void;
onSearch: (query: string) => void;
onSettings: () => void;
onSyncNow?: () => void;
dark: boolean;
onToggleDark: () => void;
syncing?: boolean;
syncError?: string | null;
syncStatus?: GlobalSyncStatus | null;
onLabelsChanged?: () => void;
allMailCount?: { total: number; unread: number } | null;
unreadCount?: { total: number } | null;
inboxLabel?: Label | null;
unifiedInboxCount?: { total: number; unread: number } | null;
unifiedAllMailCount?: { total: number; unread: number } | null;
unifiedUnreadCount?: { total: number } | null;
}
/** Formats a duration in ms as "M:SS" — fixed-width to prevent layout jumps */
function formatDuration(ms: number): string {
const secs = Math.floor(ms / 1000);
const mins = Math.floor(secs / 60);
const rem = secs % 60;
return `${mins}:${String(rem).padStart(2, "0")}`;
}
/** Shows real-time sync progress details, ticking elapsed time once per second */
function SyncProgressDetail({ syncStatus }: { syncStatus: GlobalSyncStatus }) {
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
const interval = setInterval(() => setNow(Date.now()), 1000);
return () => clearInterval(interval);
}, []);
// Aggregate progress across all identities
const identityStatuses = Object.values(syncStatus);
const running = identityStatuses.filter((a) => a.running);
Iif (running.length === 0) return null;
// Show progress for first running identity (most users have one)
const activeSync = running[0];
Iif (!activeSync) return null;
const progress = activeSync.progress;
const elapsedMs = progress ? now - progress.startedAt : 0;
const elapsedStr = formatDuration(elapsedMs);
let estimatedStr: string | null = null;
if (
progress &&
progress.foldersCompleted > 0 &&
progress.totalFolders > progress.foldersCompleted
) {
const msPerFolder = elapsedMs / progress.foldersCompleted;
const remaining = msPerFolder * (progress.totalFolders - progress.foldersCompleted);
estimatedStr = formatDuration(remaining);
}
return (
<div className="px-4 py-3 text-xs space-y-1.5 bg-stork-50 dark:bg-stork-950">
{progress ? (
<>
{progress.currentFolder && (
<div className="flex items-start gap-1.5">
<span className="text-stork-500 dark:text-stork-400 shrink-0">Folder:</span>
<span
className="text-stork-700 dark:text-stork-300 truncate font-medium"
title={progress.currentFolder}
>
{progress.currentFolder}
</span>
</div>
)}
{progress.totalFolders > 0 && (
<div className="space-y-1">
<div className="flex justify-between text-stork-600 dark:text-stork-400">
<span>
{progress.foldersCompleted} of {progress.totalFolders} folders
</span>
<span>
{Math.round((progress.foldersCompleted / progress.totalFolders) * 100)}%
</span>
</div>
<div className="w-full h-1 bg-stork-200 dark:bg-stork-800 rounded-full overflow-hidden">
<div
className="h-full bg-stork-500 dark:bg-stork-400 rounded-full transition-all duration-500"
style={{
width: `${Math.round((progress.foldersCompleted / progress.totalFolders) * 100)}%`,
}}
/>
</div>
</div>
)}
{progress.messagesNew > 0 && (
<div className="text-stork-600 dark:text-stork-400">
{progress.messagesNew} new {progress.messagesNew === 1 ? "message" : "messages"} found
</div>
)}
<div className="flex justify-between text-stork-500 dark:text-stork-500 whitespace-nowrap tabular-nums">
<span>{elapsedStr} elapsed</span>
{estimatedStr && <span>~{estimatedStr} left</span>}
</div>
</>
) : (
<div className="text-stork-600 dark:text-stork-400">Connecting to server…</div>
)}
{running.length > 1 && (
<div className="text-stork-500 dark:text-stork-500">+{running.length - 1} more syncing</div>
)}
</div>
);
}
export function Sidebar({
identities,
labels,
selectedLabelId,
filterLabelIds,
onSelectLabel,
onToggleFilterLabel,
onCompose,
onSearch,
onSettings,
onSyncNow,
dark,
onToggleDark,
syncing,
syncError,
syncStatus,
onLabelsChanged,
allMailCount,
unreadCount,
inboxLabel,
unifiedInboxCount,
unifiedAllMailCount,
unifiedUnreadCount,
}: SidebarProps) {
const [contextMenu, setContextMenu] = useState<{
label: Label;
position: { x: number; y: number };
} | null>(null);
const [syncDetailOpen, setSyncDetailOpen] = useState(false);
const handleLabelContextMenu = useCallback((e: React.MouseEvent, label: Label) => {
e.preventDefault();
setContextMenu({ label, position: { x: e.clientX, y: e.clientY } });
}, []);
return (
<aside className="w-64 flex-shrink-0 bg-gray-50 dark:bg-gray-900 border-r border-gray-200 dark:border-gray-800 flex flex-col h-full">
{/* Logo + compose */}
<div className="p-4 border-b border-gray-200 dark:border-gray-800">
<div className="flex items-center gap-2 mb-3">
<span className="text-xl font-bold text-stork-600 dark:text-stork-400">Stork</span>
<span className="text-xs text-gray-400">Mail</span>
</div>
<button
type="button"
onClick={onCompose}
className="w-full py-2 px-4 bg-stork-600 hover:bg-stork-700 text-white rounded-lg font-medium text-sm transition-colors flex items-center justify-center gap-2"
>
<ComposeIcon className="w-4 h-4" />
Compose
</button>
</div>
{/* Search button — opens the search panel */}
<div className="px-4 pt-3">
<button
type="button"
onClick={() => onSearch("")}
className="w-full flex items-center gap-2 py-1.5 pl-3 pr-2 bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-md text-sm text-gray-400 transition-colors"
>
<SearchIcon className="w-3.5 h-3.5 flex-shrink-0" />
<span className="flex-1 text-left">Search mail…</span>
<kbd className="text-xs bg-gray-200 dark:bg-gray-700 px-1 rounded">/</kbd>
</button>
</div>
{/* Mirror mode nag — removed, sync_delete_from_server is on connectors now */}
{false /* mirror mode nag removed — sync_delete_from_server is on connectors now */ && (
<div className="mx-4 mt-3 px-3 py-2 rounded-md bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 text-xs text-amber-700 dark:text-amber-400">
<button type="button" onClick={onSettings} className="text-left w-full">
<span className="font-medium">Mirror mode active.</span> Actions in Stork don't sync
back to your provider. <span className="underline">Switch to Connector mode</span> when
you're ready to commit.
</button>
</div>
)}
{/* Sync indicator — clickable to show verbose progress */}
{syncing && (
<div className="border-b border-gray-200 dark:border-gray-800">
<button
type="button"
onClick={() => setSyncDetailOpen((v) => !v)}
className="w-full px-4 py-2 flex items-center gap-2 text-xs text-stork-600 dark:text-stork-400 hover:bg-stork-50 dark:hover:bg-stork-950 transition-colors"
title="Click for sync details"
>
<svg
className="w-3.5 h-3.5 animate-spin flex-shrink-0"
viewBox="0 0 24 24"
fill="none"
role="img"
aria-label="Syncing"
>
<title>Syncing</title>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
/>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
/>
</svg>
<span className="flex-1 text-left">Syncing mail…</span>
<svg
className={`w-3 h-3 flex-shrink-0 transition-transform ${syncDetailOpen ? "rotate-180" : ""}`}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
>
<title>{syncDetailOpen ? "Hide details" : "Show details"}</title>
<polyline points="6 9 12 15 18 9" />
</svg>
</button>
{syncDetailOpen && syncStatus && <SyncProgressDetail syncStatus={syncStatus} />}
</div>
)}
{/* Sync error indicator — shown when not syncing but last sync failed */}
{!syncing && syncError && (
<div className="border-b border-gray-200 dark:border-gray-800 px-4 py-2">
<div className="flex items-start gap-2 text-xs text-red-600 dark:text-red-400">
<svg
className="w-3.5 h-3.5 flex-shrink-0 mt-0.5"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
role="img"
aria-label="Sync error"
>
<title>Sync error</title>
<circle cx="12" cy="12" r="10" />
<line x1="12" y1="8" x2="12" y2="12" />
<line x1="12" y1="16" x2="12.01" y2="16" />
</svg>
<div className="flex-1 min-w-0">
<span className="font-medium">Sync failed</span>
<p className="text-red-500 dark:text-red-500 truncate mt-0.5" title={syncError}>
{syncError}
</p>
</div>
</div>
</div>
)}
{/* Navigation — promoted views + label list */}
<nav className="flex-1 overflow-y-auto px-2 py-3">
{/* Promoted views: Inbox, Unread, All Mail
In multi-identity mode these are unified (cross-identity) views.
In single-identity mode they filter to that identity. */}
{labels.length > 0 && (
<>
<button
type="button"
onClick={() =>
onSelectLabel(identities.length > 1 ? UNIFIED_INBOX_LABEL_ID : INBOX_LABEL_ID)
}
className={`w-full flex items-center gap-2 px-3 py-1.5 rounded-md text-sm transition-colors ${
selectedLabelId === INBOX_LABEL_ID || selectedLabelId === UNIFIED_INBOX_LABEL_ID
? "bg-stork-100 dark:bg-stork-950 text-stork-700 dark:text-stork-300 font-medium"
: "text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800"
}`}
>
<InboxIcon className="w-4 h-4 flex-shrink-0" />
<span className="truncate">Inbox</span>
{identities.length > 1 ? (
unifiedInboxCount && unifiedInboxCount.unread > 0 ? (
<span className="ml-auto text-xs font-medium text-stork-600 dark:text-stork-400 bg-stork-100 dark:bg-stork-900 px-1.5 py-0.5 rounded-full">
{unifiedInboxCount.unread}
</span>
) : null
) : inboxLabel && inboxLabel.unread_count > 0 ? (
<span className="ml-auto text-xs font-medium text-stork-600 dark:text-stork-400 bg-stork-100 dark:bg-stork-900 px-1.5 py-0.5 rounded-full">
{inboxLabel.unread_count}
</span>
) : null}
</button>
<button
type="button"
onClick={() =>
onSelectLabel(identities.length > 1 ? UNIFIED_UNREAD_LABEL_ID : UNREAD_LABEL_ID)
}
className={`w-full flex items-center gap-2 px-3 py-1.5 rounded-md text-sm transition-colors ${
selectedLabelId === UNREAD_LABEL_ID || selectedLabelId === UNIFIED_UNREAD_LABEL_ID
? "bg-stork-100 dark:bg-stork-950 text-stork-700 dark:text-stork-300 font-medium"
: "text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800"
}`}
>
<UnreadIcon className="w-4 h-4 flex-shrink-0" />
<span className="truncate">Unread</span>
{identities.length > 1 ? (
unifiedUnreadCount && unifiedUnreadCount.total > 0 ? (
<span className="ml-auto text-xs font-medium text-stork-600 dark:text-stork-400 bg-stork-100 dark:bg-stork-900 px-1.5 py-0.5 rounded-full">
{unifiedUnreadCount.total}
</span>
) : null
) : unreadCount && unreadCount.total > 0 ? (
<span className="ml-auto text-xs font-medium text-stork-600 dark:text-stork-400 bg-stork-100 dark:bg-stork-900 px-1.5 py-0.5 rounded-full">
{unreadCount.total}
</span>
) : null}
</button>
<button
type="button"
onClick={() =>
onSelectLabel(identities.length > 1 ? UNIFIED_ALL_MAIL_LABEL_ID : ALL_MAIL_LABEL_ID)
}
className={`w-full flex items-center gap-2 px-3 py-1.5 rounded-md text-sm transition-colors ${
selectedLabelId === ALL_MAIL_LABEL_ID ||
selectedLabelId === UNIFIED_ALL_MAIL_LABEL_ID
? "bg-stork-100 dark:bg-stork-950 text-stork-700 dark:text-stork-300 font-medium"
: "text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800"
}`}
>
<MailAllIcon className="w-4 h-4 flex-shrink-0" />
<span className="truncate">All Mail</span>
{identities.length > 1 ? (
unifiedAllMailCount && unifiedAllMailCount.unread > 0 ? (
<span className="ml-auto text-xs font-medium text-stork-600 dark:text-stork-400 bg-stork-100 dark:bg-stork-900 px-1.5 py-0.5 rounded-full">
{unifiedAllMailCount.unread}
</span>
) : null
) : allMailCount && allMailCount.unread > 0 ? (
<span className="ml-auto text-xs font-medium text-stork-600 dark:text-stork-400 bg-stork-100 dark:bg-stork-900 px-1.5 py-0.5 rounded-full">
{allMailCount.unread}
</span>
) : null}
</button>
<div className="my-2 mx-3 border-t border-gray-200 dark:border-gray-700" />
</>
)}
{/* All labels — top-level Inbox excluded (promoted above). Identity labels appear inline with person icon. */}
{labels
.filter((l) => l.name.toUpperCase() !== "INBOX")
.map((label) => {
const active = label.id === selectedLabelId || filterLabelIds.includes(label.id);
return (
<button
key={label.id}
type="button"
onClick={(e) => {
Iif (e.metaKey || e.ctrlKey) {
onToggleFilterLabel(label.id);
} else {
onSelectLabel(label.id);
}
}}
onContextMenu={(e) => handleLabelContextMenu(e, label)}
className={`w-full flex items-center gap-2 px-3 py-1.5 rounded-md text-sm transition-colors ${
active
? "bg-stork-100 dark:bg-stork-950 text-stork-700 dark:text-stork-300 font-medium"
: "text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800"
}`}
title="Click to view · Cmd/Ctrl+click to add to filter"
>
{labelIcon(label)}
<span className="truncate">{label.name}</span>
{label.unread_count > 0 && (
<span className="ml-auto text-xs font-medium text-stork-600 dark:text-stork-400 bg-stork-100 dark:bg-stork-900 px-1.5 py-0.5 rounded-full">
{label.unread_count}
</span>
)}
</button>
);
})}
{labels.length === 0 && (
<p className="text-xs text-gray-400 px-3 py-2">
{syncing ? "Waiting for initial sync…" : "No labels yet"}
</p>
)}
{/* Label management — create button + context menu + edit/delete */}
{onLabelsChanged && (
<LabelManager
onLabelsChanged={onLabelsChanged}
contextMenu={contextMenu}
onContextMenuClose={() => setContextMenu(null)}
/>
)}
</nav>
{/* Footer controls */}
<div className="p-3 border-t border-gray-200 dark:border-gray-800 flex items-center justify-between">
<button
type="button"
onClick={onToggleDark}
className="text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors flex items-center gap-1.5"
title="Toggle dark mode"
>
{dark ? (
<>
<SunIcon className="w-3.5 h-3.5" /> Light
</>
) : (
<>
<MoonIcon className="w-3.5 h-3.5" /> Dark
</>
)}
</button>
<div className="flex items-center gap-1">
{onSyncNow && (
<button
type="button"
onClick={onSyncNow}
disabled={syncing}
className="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 disabled:opacity-40 transition-colors"
title={syncing ? "Sync in progress…" : "Sync now"}
>
<RefreshIcon className={`w-4 h-4${syncing ? " animate-spin" : ""}`} />
</button>
)}
<button
type="button"
onClick={onSettings}
className="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors"
title="Settings"
>
<SettingsIcon className="w-4 h-4" />
</button>
</div>
</div>
</aside>
);
}
|