carnet panel contact
This commit is contained in:
parent
b7f889e011
commit
e4a93b8443
@ -178,11 +178,17 @@ export default function CarnetPage() {
|
||||
fetchNotes();
|
||||
}, [selectedFolder]);
|
||||
|
||||
const parseVCard = (content: string): Contact | null => {
|
||||
const parseVCard = (content: string): Contact[] => {
|
||||
try {
|
||||
console.log('Raw VCF content:', content);
|
||||
const lines = content.split('\n').filter(line => line.trim());
|
||||
console.log('Parsed lines:', lines);
|
||||
|
||||
// Split the content into individual vCards
|
||||
const vcardSections = content.split('BEGIN:VCARD').filter(section => section.trim());
|
||||
console.log('Found vCard sections:', vcardSections.length);
|
||||
|
||||
return vcardSections.map(section => {
|
||||
const lines = section.split('\n').filter(line => line.trim());
|
||||
console.log('Processing vCard section with lines:', lines.length);
|
||||
|
||||
const contact: Partial<Contact> = {
|
||||
id: Math.random().toString(36).substr(2, 9),
|
||||
@ -261,9 +267,10 @@ export default function CarnetPage() {
|
||||
|
||||
console.log('Final contact object:', contact);
|
||||
return contact as Contact;
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error parsing VCF content:', error);
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
@ -284,23 +291,22 @@ export default function CarnetPage() {
|
||||
const contentResponse = await fetch(`/api/nextcloud/files/content?path=${encodeURIComponent(webdavPath)}`);
|
||||
if (contentResponse.ok) {
|
||||
const content = await contentResponse.text();
|
||||
const contact = parseVCard(content);
|
||||
if (contact) {
|
||||
return {
|
||||
const contacts = parseVCard(content);
|
||||
return contacts.map(contact => ({
|
||||
...contact,
|
||||
group: folder
|
||||
};
|
||||
}));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return [];
|
||||
} catch (error) {
|
||||
console.error('Error fetching VCF content:', error);
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
setContacts(parsedContacts.filter(Boolean));
|
||||
// Flatten the array of contact arrays
|
||||
setContacts(parsedContacts.flat().filter(Boolean));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching contacts:', error);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user