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 { useSheetDrag } from '../lib/use-sheet-drag';
import { useLocaleStore } from '../stores/locale-store'; import { useLocaleStore } from '../stores/locale-store';
import { localizeMailboxName } from '../lib/mailbox-label'; import { localizeMailboxName } from '../lib/mailbox-label';
import { mailboxIconKind, type MailboxIconKind } from '../lib/mailbox-icon';
import type { Mailbox } from '../api/types'; import type { Mailbox } from '../api/types';
import { MODAL_ORIENTATIONS } from '../lib/modal-orientations'; import { MODAL_ORIENTATIONS } from '../lib/modal-orientations';
import { useSheetInsets } from '../lib/use-layout'; import { useSheetInsets } from '../lib/use-layout';
function moveTargetIcon(role: string | null | undefined, name: string): AppIcon { // By role only, like the sidebar (mailboxIconKind, #1235): a user folder
const lower = name.toLowerCase(); // named "web/sentry" is not the Sent folder.
if (role === 'inbox' || lower.includes('inbox')) return Inbox; const MOVE_TARGET_ICONS: Partial<Record<MailboxIconKind, AppIcon>> = {
if (role === 'sent' || lower.includes('sent')) return Send; inbox: Inbox,
if (role === 'drafts' || lower.includes('draft')) return FileIcon; sent: Send,
if (role === 'trash' || lower.includes('trash') || lower.includes('deleted')) return Trash2; drafts: FileIcon,
if (role === 'junk' || role === 'spam' || lower.includes('junk') || lower.includes('spam')) return Ban; trash: Trash2,
if (role === 'archive' || lower.includes('archive')) return Archive; junk: Ban,
return Folder; archive: Archive,
};
function moveTargetIcon(role: string | null | undefined): AppIcon {
return MOVE_TARGET_ICONS[mailboxIconKind(role, false, false)] ?? Folder;
} }
interface MoveSheetProps { interface MoveSheetProps {
@@ -106,7 +111,7 @@ export function MoveSheet({
</View> </View>
<ScrollView> <ScrollView>
{visibleNodes.map((node) => { {visibleNodes.map((node) => {
const Icon = moveTargetIcon(node.role, node.name); const Icon = moveTargetIcon(node.role);
const isCurrent = node.id === currentMailboxId; const isCurrent = node.id === currentMailboxId;
// A shared account's header is a grouping row, not a folder, and // A shared account's header is a grouping row, not a folder, and
// Drafts is never a move target (the webmail excludes it too). // 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).toContain('mailboxIconKind(');
expect(source).not.toMatch(/lower\.includes\('(?:sent|inbox|draft|trash|junk|archive|star)'\)/); 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)'\)/);
});
}); });