fix: give user folders in the move sheet a folder icon even when their name looks like a system folder (bulwarkmail/webmail#1235)

This commit is contained in:
Linus Rath
2026-10-31 04:01:54 +01:00
parent 7772da8463
commit a4d3891140
2 changed files with 22 additions and 10 deletions
+15 -10
View File
@@ -13,19 +13,24 @@ import { buildMailboxTree, flattenVisible, type MailboxNode } from '../lib/mailb
import { useSheetDrag } from '../lib/use-sheet-drag';
import { useLocaleStore } from '../stores/locale-store';
import { localizeMailboxName } from '../lib/mailbox-label';
import { mailboxIconKind, type MailboxIconKind } from '../lib/mailbox-icon';
import type { Mailbox } from '../api/types';
import { MODAL_ORIENTATIONS } from '../lib/modal-orientations';
import { useSheetInsets } from '../lib/use-layout';
function moveTargetIcon(role: string | null | undefined, name: string): AppIcon {
const lower = name.toLowerCase();
if (role === 'inbox' || lower.includes('inbox')) return Inbox;
if (role === 'sent' || lower.includes('sent')) return Send;
if (role === 'drafts' || lower.includes('draft')) return FileIcon;
if (role === 'trash' || lower.includes('trash') || lower.includes('deleted')) return Trash2;
if (role === 'junk' || role === 'spam' || lower.includes('junk') || lower.includes('spam')) return Ban;
if (role === 'archive' || lower.includes('archive')) return Archive;
return Folder;
// By role only, like the sidebar (mailboxIconKind, #1235): a user folder
// named "web/sentry" is not the Sent folder.
const MOVE_TARGET_ICONS: Partial<Record<MailboxIconKind, AppIcon>> = {
inbox: Inbox,
sent: Send,
drafts: FileIcon,
trash: Trash2,
junk: Ban,
archive: Archive,
};
function moveTargetIcon(role: string | null | undefined): AppIcon {
return MOVE_TARGET_ICONS[mailboxIconKind(role, false, false)] ?? Folder;
}
interface MoveSheetProps {
@@ -106,7 +111,7 @@ export function MoveSheet({
</View>
<ScrollView>
{visibleNodes.map((node) => {
const Icon = moveTargetIcon(node.role, node.name);
const Icon = moveTargetIcon(node.role);
const isCurrent = node.id === currentMailboxId;
// A shared account's header is a grouping row, not a folder, and
// Drafts is never a move target (the webmail excludes it too).
+7
View File
@@ -25,4 +25,11 @@ describe('mailboxIconKind', () => {
expect(source).toContain('mailboxIconKind(');
expect(source).not.toMatch(/lower\.includes\('(?:sent|inbox|draft|trash|junk|archive|star)'\)/);
});
// The move sheet still guessed from the name (#1235 fixed only the sidebar).
it('is what the move sheet uses too, with no guess from the folder name', () => {
const source = readFileSync(path.join(process.cwd(), 'src/components/MoveSheet.tsx'), 'utf8');
expect(source).toContain('mailboxIconKind(');
expect(source).not.toMatch(/\.includes\('(?:sent|inbox|draft|trash|deleted|junk|spam|archive)'\)/);
});
});