From e85c4d948e3bf175c70d917245dd0a6af3067964 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 16 Apr 2025 17:41:14 +0200 Subject: [PATCH] Neah version mail widget? --- components/email.tsx | 50 ++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/components/email.tsx b/components/email.tsx index 217a390..75a5b95 100644 --- a/components/email.tsx +++ b/components/email.tsx @@ -11,12 +11,12 @@ import { fr } from 'date-fns/locale/fr'; interface Email { id: string; subject: string; - sender: { - name: string; - email: string; - }; + from: string; + fromName?: string; date: string; - isUnread: boolean; + read: boolean; + starred: boolean; + folder: string; } interface EmailResponse { @@ -51,46 +51,22 @@ export function Email() { throw new Error(errorData.error || 'Failed to fetch emails'); } - const rawText = await response.text(); - console.log('Raw API Response:', rawText); - - let data; - try { - data = JSON.parse(rawText); - console.log('Parsed API Response:', data); - } catch (parseError) { - console.error('JSON Parse Error:', parseError); - throw new Error('Invalid JSON response from server'); - } + const data = await response.json(); + console.log('Parsed API Response:', data); if (data.error) { throw new Error(data.error); } - let emailsArray = []; - if (Array.isArray(data)) { - emailsArray = data; - } else if (data.messages && Array.isArray(data.messages)) { - emailsArray = data.messages; - } else if (data.emails && Array.isArray(data.emails)) { - emailsArray = data.emails; - } else { - console.error('Unexpected data structure:', data); - throw new Error('Invalid response format: emails data not found'); - } - - const validatedEmails = emailsArray.map(email => ({ + const validatedEmails = data.emails.map((email: any) => ({ id: email.id || Date.now().toString(), - accountId: email.accountId || 1, + subject: email.subject || '(No subject)', from: email.from || '', fromName: email.fromName || email.from?.split('@')[0] || 'Unknown', - to: email.to || '', - subject: email.subject || '(No subject)', - body: email.body || '', date: email.date || new Date().toISOString(), read: !!email.read, starred: !!email.starred, - category: email.category || 'inbox' + folder: email.folder || 'INBOX' })); console.log('Processed emails:', validatedEmails); @@ -213,11 +189,11 @@ export function Email() { onClick={() => mailUrl && window.open(mailUrl, '_blank')} >
- - {email.sender.name} + + {email.fromName || email.from}
- {email.isUnread && } + {!email.read && } {formatDate(email.date)}