mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-02 08:07:11 +00:00
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:
@@ -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).
|
||||||
|
|||||||
@@ -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)'\)/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user