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