carnet panel contact
This commit is contained in:
parent
b7f889e011
commit
e4a93b8443
@ -178,11 +178,17 @@ export default function CarnetPage() {
|
|||||||
fetchNotes();
|
fetchNotes();
|
||||||
}, [selectedFolder]);
|
}, [selectedFolder]);
|
||||||
|
|
||||||
const parseVCard = (content: string): Contact | null => {
|
const parseVCard = (content: string): Contact[] => {
|
||||||
try {
|
try {
|
||||||
console.log('Raw VCF content:', content);
|
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> = {
|
const contact: Partial<Contact> = {
|
||||||
id: Math.random().toString(36).substr(2, 9),
|
id: Math.random().toString(36).substr(2, 9),
|
||||||
@ -261,9 +267,10 @@ export default function CarnetPage() {
|
|||||||
|
|
||||||
console.log('Final contact object:', contact);
|
console.log('Final contact object:', contact);
|
||||||
return contact as Contact;
|
return contact as Contact;
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error parsing VCF content:', 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)}`);
|
const contentResponse = await fetch(`/api/nextcloud/files/content?path=${encodeURIComponent(webdavPath)}`);
|
||||||
if (contentResponse.ok) {
|
if (contentResponse.ok) {
|
||||||
const content = await contentResponse.text();
|
const content = await contentResponse.text();
|
||||||
const contact = parseVCard(content);
|
const contacts = parseVCard(content);
|
||||||
if (contact) {
|
return contacts.map(contact => ({
|
||||||
return {
|
|
||||||
...contact,
|
...contact,
|
||||||
group: folder
|
group: folder
|
||||||
};
|
}));
|
||||||
}
|
}
|
||||||
}
|
return [];
|
||||||
return null;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching VCF content:', 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) {
|
} catch (error) {
|
||||||
console.error('Error fetching contacts:', error);
|
console.error('Error fetching contacts:', error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user