mail page ui correction maj compose 20 bis 15
This commit is contained in:
parent
9adc1e6228
commit
1ed9592bcb
@ -430,13 +430,14 @@ function cleanEmailContent(content: string): string {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, let's define our mail view types based on the actual IMAP folders
|
// Define the exact folder names from IMAP
|
||||||
type MailView = 'INBOX' | 'Sent' | 'Trash' | 'Spam' | 'Drafts' | 'Archives' | 'Archive' | 'starred';
|
type MailFolder = 'INBOX' | 'Sent' | 'Trash' | 'Spam' | 'Drafts' | 'Archives';
|
||||||
|
type MailView = MailFolder | 'starred';
|
||||||
|
|
||||||
// Update the sidebar navigation to use exact IMAP folder names
|
// Map the exact IMAP folders to our sidebar items
|
||||||
const sidebarNavItems = [
|
const sidebarNavItems = [
|
||||||
{
|
{
|
||||||
view: 'INBOX' as MailView, // Exact IMAP folder name
|
view: 'INBOX' as MailView,
|
||||||
label: 'Inbox',
|
label: 'Inbox',
|
||||||
icon: Inbox,
|
icon: Inbox,
|
||||||
folder: 'INBOX'
|
folder: 'INBOX'
|
||||||
@ -448,31 +449,31 @@ const sidebarNavItems = [
|
|||||||
folder: null // Special case for starred items
|
folder: null // Special case for starred items
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
view: 'Sent' as MailView, // Exact IMAP folder name
|
view: 'Sent' as MailView,
|
||||||
label: 'Sent',
|
label: 'Sent',
|
||||||
icon: Send,
|
icon: Send,
|
||||||
folder: 'Sent'
|
folder: 'Sent'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
view: 'Drafts' as MailView, // Exact IMAP folder name
|
view: 'Drafts' as MailView,
|
||||||
label: 'Drafts',
|
label: 'Drafts',
|
||||||
icon: Edit,
|
icon: Edit,
|
||||||
folder: 'Drafts'
|
folder: 'Drafts'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
view: 'Spam' as MailView, // Exact IMAP folder name
|
view: 'Spam' as MailView,
|
||||||
label: 'Spam',
|
label: 'Spam',
|
||||||
icon: AlertOctagon,
|
icon: AlertOctagon,
|
||||||
folder: 'Spam'
|
folder: 'Spam'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
view: 'Trash' as MailView, // Exact IMAP folder name
|
view: 'Trash' as MailView,
|
||||||
label: 'Trash',
|
label: 'Trash',
|
||||||
icon: Trash,
|
icon: Trash,
|
||||||
folder: 'Trash'
|
folder: 'Trash'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
view: 'Archives' as MailView, // Exact IMAP folder name
|
view: 'Archives' as MailView,
|
||||||
label: 'Archives',
|
label: 'Archives',
|
||||||
icon: Archive,
|
icon: Archive,
|
||||||
folder: 'Archives'
|
folder: 'Archives'
|
||||||
@ -487,7 +488,7 @@ export default function MailPage() {
|
|||||||
{ id: 1, name: 'Mail', email: 'alma@governance-labs.org', color: 'bg-blue-500' }
|
{ id: 1, name: 'Mail', email: 'alma@governance-labs.org', color: 'bg-blue-500' }
|
||||||
]);
|
]);
|
||||||
const [selectedAccount, setSelectedAccount] = useState<Account | null>(null);
|
const [selectedAccount, setSelectedAccount] = useState<Account | null>(null);
|
||||||
const [currentView, setCurrentView] = useState<MailView>('INBOX'); // Use exact IMAP folder name
|
const [currentView, setCurrentView] = useState<MailView>('INBOX');
|
||||||
const [showCompose, setShowCompose] = useState(false);
|
const [showCompose, setShowCompose] = useState(false);
|
||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||||
const [selectedEmails, setSelectedEmails] = useState<string[]>([]);
|
const [selectedEmails, setSelectedEmails] = useState<string[]>([]);
|
||||||
@ -519,29 +520,24 @@ export default function MailPage() {
|
|||||||
const [folders, setFolders] = useState<string[]>([]);
|
const [folders, setFolders] = useState<string[]>([]);
|
||||||
const [unreadCount, setUnreadCount] = useState(0);
|
const [unreadCount, setUnreadCount] = useState(0);
|
||||||
|
|
||||||
// Add this logging to see what data we're working with
|
// Debug logging for email distribution
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('All emails:', emails);
|
const emailsByFolder = emails.reduce((acc, email) => {
|
||||||
|
acc[email.folder] = (acc[email.folder] || 0) + 1;
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<string, number>);
|
||||||
|
|
||||||
|
console.log('Emails by folder:', emailsByFolder);
|
||||||
console.log('Current view:', currentView);
|
console.log('Current view:', currentView);
|
||||||
console.log('Selected account:', selectedAccount);
|
}, [emails, currentView]);
|
||||||
}, [emails, currentView, selectedAccount]);
|
|
||||||
|
|
||||||
// Update the filteredEmails logic to use exact folder names
|
// Update the filteredEmails logic
|
||||||
const filteredEmails = useMemo(() => {
|
const filteredEmails = useMemo(() => {
|
||||||
console.log('Filtering emails:', {
|
|
||||||
total: emails.length,
|
|
||||||
byFolder: emails.reduce((acc, email) => {
|
|
||||||
acc[email.folder] = (acc[email.folder] || 0) + 1;
|
|
||||||
return acc;
|
|
||||||
}, {} as Record<string, number>),
|
|
||||||
currentView
|
|
||||||
});
|
|
||||||
|
|
||||||
if (currentView === 'starred') {
|
if (currentView === 'starred') {
|
||||||
return emails.filter(email => email.starred);
|
return emails.filter(email => email.starred);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For all other views, use exact folder name matching
|
// For all other views, match exactly with the IMAP folder name
|
||||||
return emails.filter(email => email.folder === currentView);
|
return emails.filter(email => email.folder === currentView);
|
||||||
}, [emails, currentView]);
|
}, [emails, currentView]);
|
||||||
|
|
||||||
@ -579,7 +575,7 @@ export default function MailPage() {
|
|||||||
checkCredentials();
|
checkCredentials();
|
||||||
}, [router]);
|
}, [router]);
|
||||||
|
|
||||||
// Update the loadEmails function to preserve exact folder names
|
// Update the loadEmails function
|
||||||
const loadEmails = async () => {
|
const loadEmails = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -593,7 +589,7 @@ export default function MailPage() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('Raw email data:', data);
|
console.log('Raw email data:', data);
|
||||||
|
|
||||||
// Process the emails, keeping exact folder names
|
// Process emails keeping exact folder names
|
||||||
const processedEmails = data.emails.map((email: any) => ({
|
const processedEmails = data.emails.map((email: any) => ({
|
||||||
...email,
|
...email,
|
||||||
id: Number(email.id),
|
id: Number(email.id),
|
||||||
@ -604,10 +600,10 @@ export default function MailPage() {
|
|||||||
date: email.date || new Date().toISOString(),
|
date: email.date || new Date().toISOString(),
|
||||||
read: email.read || false,
|
read: email.read || false,
|
||||||
starred: email.starred || false,
|
starred: email.starred || false,
|
||||||
folder: email.folder // Keep exact folder name from IMAP
|
folder: email.folder // Keep exact IMAP folder name
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Update unread count for INBOX (note the exact folder name)
|
// Update unread count for INBOX
|
||||||
const unreadInboxEmails = processedEmails.filter(
|
const unreadInboxEmails = processedEmails.filter(
|
||||||
email => !email.read && email.folder === 'INBOX'
|
email => !email.read && email.folder === 'INBOX'
|
||||||
).length;
|
).length;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user