widget courrier refactor

This commit is contained in:
alma 2026-01-15 23:47:35 +01:00
parent 75c7b6638f
commit 2df21f5d44

View File

@ -62,12 +62,26 @@ export function Email() {
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
if (data.accounts) { if (data.accounts) {
const loadedAccounts = data.accounts.map((acc: any) => ({ const loadedAccounts = data.accounts.map((acc: any) => {
id: acc.id || acc.email, // If no color is set, generate a consistent color based on account ID
email: acc.email, let accountColor = acc.color;
color: acc.color || '#0082c9' // Default color if not set if (!accountColor && acc.id) {
})); // Generate a color hash from accountId
console.log('[Email Widget] Loaded accounts:', loadedAccounts.map(acc => ({ let hash = 0;
for (let i = 0; i < acc.id.length; i++) {
hash = acc.id.charCodeAt(i) + ((hash << 5) - hash);
}
const hue = Math.abs(hash % 360);
accountColor = `hsl(${hue}, 70%, 50%)`;
}
return {
id: acc.id || acc.email,
email: acc.email,
color: accountColor || '#0082c9' // Fallback default color
};
});
console.log('[Email Widget] Loaded accounts with colors:', loadedAccounts.map(acc => ({
id: acc.id, id: acc.id,
email: acc.email, email: acc.email,
color: acc.color color: acc.color
@ -271,19 +285,35 @@ export function Email() {
</div> </div>
) : ( ) : (
<div className="space-y-3 max-h-[500px] overflow-y-auto pr-1 scrollbar-thin scrollbar-thumb-gray-200 scrollbar-track-transparent"> <div className="space-y-3 max-h-[500px] overflow-y-auto pr-1 scrollbar-thin scrollbar-thumb-gray-200 scrollbar-track-transparent">
{emails.map((email) => { {emails.map((email, index) => {
// Find the account color for this email using the accountId // Find the account color for this email using the accountId
const emailAccountId = (email as any).accountId; const emailAccountId = (email as any).accountId;
const account = emailAccountId ? accountMap.get(emailAccountId) : null; const account = emailAccountId ? accountMap.get(emailAccountId) : null;
const accountColor = account?.color || '#0082c9'; // Use account color, or generate a color based on accountId if not found
let accountColor = account?.color || '#0082c9';
// Debug log to verify account matching // If no color is set, generate a consistent color based on accountId
if (!account && emailAccountId) { if (!account?.color && emailAccountId) {
console.warn('[Email Widget] Account not found for email', { // Generate a color hash from accountId
let hash = 0;
for (let i = 0; i < emailAccountId.length; i++) {
hash = emailAccountId.charCodeAt(i) + ((hash << 5) - hash);
}
const hue = Math.abs(hash % 360);
accountColor = `hsl(${hue}, 70%, 50%)`;
}
// Debug log for first few emails
if (index < 3) {
console.log('[Email Widget] Email account mapping', {
emailId: email.id, emailId: email.id,
accountId: emailAccountId, emailAccountId,
availableAccountIds: Array.from(accountMap.keys()), accountFound: !!account,
accountEmail: (email as any)._accountEmail accountEmail: account?.email,
accountColor: account?.color,
finalColor: accountColor,
allAccountIds: Array.from(accountMap.keys()),
allAccounts: Array.from(accountMap.values()).map(a => ({ id: a.id, email: a.email, color: a.color }))
}); });
} }