Pages corrections

This commit is contained in:
alma 2026-01-16 12:09:00 +01:00
parent d78e26914d
commit e96e4bbc5f

View File

@ -181,38 +181,53 @@ export default function CarnetPage() {
const parseVCardContent = (content: string): Contact[] => { const parseVCardContent = (content: string): Contact[] => {
try { try {
// Split the content into individual vCards console.log(`[parseVCardContent] Parsing VCF content, length: ${content.length}`);
const vcards = content.split('BEGIN:VCARD').filter(section => section.trim());
return vcards.map(section => { // Split the content into individual vCards
const vcard = parseVCard('BEGIN:VCARD' + section); // Handle both formats: BEGIN:VCARD\n... and BEGIN:VCARD\r\n...
const vcards = content.split(/BEGIN:VCARD/i).filter(section => section.trim());
// Extract contact properties with proper type handling console.log(`[parseVCardContent] Found ${vcards.length} vCard sections`);
const uid = vcard.uid?.[0]?.value;
const fullName = vcard.fn?.[0]?.value; const parsed = vcards.map((section, index) => {
const email = vcard.email?.[0]?.value; try {
const phone = vcard.tel?.[0]?.value; const vcardContent = 'BEGIN:VCARD' + section;
const organization = vcard.org?.[0]?.value; const vcard = parseVCard(vcardContent);
const address = vcard.adr?.[0]?.value;
const notes = vcard.note?.[0]?.value; // Extract contact properties with proper type handling
const group = vcard.categories?.[0]?.value; const uid = vcard.uid?.[0]?.value;
const fullName = vcard.fn?.[0]?.value;
// Create a clean contact object const email = vcard.email?.[0]?.value;
const contact: Contact = { const phone = vcard.tel?.[0]?.value;
id: uid || Math.random().toString(36).substr(2, 9), const organization = vcard.org?.[0]?.value;
fullName: fullName || 'Unknown Contact', const address = vcard.adr?.[0]?.value;
email: email || '', const notes = vcard.note?.[0]?.value;
phone: phone || '', const group = vcard.categories?.[0]?.value;
organization: organization || '',
address: address || '', console.log(`[parseVCardContent] Parsed contact ${index + 1}:`, { uid, fullName, email, phone });
notes: notes || '',
group: group || '' // Create a clean contact object
}; const contact: Contact = {
id: uid || Math.random().toString(36).substr(2, 9),
return contact; fullName: fullName || 'Unknown Contact',
}); email: email || '',
phone: phone || '',
organization: organization || '',
address: address || '',
notes: notes || '',
group: group || ''
};
return contact;
} catch (parseError) {
console.error(`[parseVCardContent] Error parsing vCard section ${index + 1}:`, parseError);
return null;
}
}).filter((contact): contact is Contact => contact !== null);
console.log(`[parseVCardContent] Successfully parsed ${parsed.length} contacts`);
return parsed;
} catch (error) { } catch (error) {
console.error('Error parsing VCF content:', error); console.error('[parseVCardContent] Error parsing VCF content:', error);
return []; return [];
} }
}; };
@ -283,18 +298,24 @@ export default function CarnetPage() {
// Flatten the array of contact arrays // Flatten the array of contact arrays
const allContacts = parsedContacts.flat().filter(Boolean); const allContacts = parsedContacts.flat().filter(Boolean);
console.log(`[fetchContacts] Total contacts parsed: ${allContacts.length}`); console.log(`[fetchContacts] Total contacts parsed: ${allContacts.length}`, allContacts);
setContacts(allContacts); setContacts(allContacts);
// Log state after setting
setTimeout(() => {
console.log(`[fetchContacts] Contacts state after setContacts:`, allContacts.length);
}, 100);
} else { } else {
console.error(`[fetchContacts] Failed to fetch files:`, response.status); console.error(`[fetchContacts] Failed to fetch files:`, response.status, await response.text().catch(() => ''));
setContacts([]); setContacts([]);
} }
} }
} catch (error) { } catch (error) {
console.error('Error fetching contacts:', error); console.error('[fetchContacts] Error fetching contacts:', error);
setContacts([]); setContacts([]);
} finally { } finally {
setIsLoadingContacts(false); setIsLoadingContacts(false);
console.log(`[fetchContacts] Finished loading contacts, isLoadingContacts set to false`);
} }
}; };
@ -793,12 +814,15 @@ export default function CarnetPage() {
<> <>
<div className="flex-1 overflow-hidden"> <div className="flex-1 overflow-hidden">
{selectedFolder === 'Contacts' ? ( {selectedFolder === 'Contacts' ? (
<ContactsView <>
contacts={contacts} {console.log(`[Render] Rendering ContactsView with ${contacts.length} contacts`, contacts)}
onContactSelect={handleContactSelect} <ContactsView
selectedContact={selectedContact} contacts={contacts}
loading={isLoadingNotes} onContactSelect={handleContactSelect}
/> selectedContact={selectedContact}
loading={isLoadingContacts}
/>
</>
) : ( ) : (
<NotesView <NotesView
notes={notes} notes={notes}