carnet panel contact

This commit is contained in:
alma 2025-04-20 21:58:28 +02:00
parent 6cef226948
commit add7e45af9

View File

@ -164,7 +164,9 @@ export default function CarnetPage() {
const parseVCard = (content: string): Contact[] => { const parseVCard = (content: string): Contact[] => {
try { try {
// Split the content into individual vCards
const vcards = content.split('BEGIN:VCARD').filter(section => section.trim()); const vcards = content.split('BEGIN:VCARD').filter(section => section.trim());
return vcards.map(section => { return vcards.map(section => {
const vcard = new VCard(); const vcard = new VCard();
vcard.parse('BEGIN:VCARD' + section); vcard.parse('BEGIN:VCARD' + section);
@ -179,7 +181,8 @@ export default function CarnetPage() {
const notes = vcard.getProperty('NOTE')?.value; const notes = vcard.getProperty('NOTE')?.value;
const group = vcard.getProperty('CATEGORIES')?.value; const group = vcard.getProperty('CATEGORIES')?.value;
return { // Create a clean contact object
const contact: Contact = {
id: uid || Math.random().toString(36).substr(2, 9), id: uid || Math.random().toString(36).substr(2, 9),
fullName: fullName || 'Unknown Contact', fullName: fullName || 'Unknown Contact',
email: email || '', email: email || '',
@ -189,6 +192,8 @@ export default function CarnetPage() {
notes: notes || '', notes: notes || '',
group: group || '' group: group || ''
}; };
return contact;
}); });
} catch (error) { } catch (error) {
console.error('Error parsing VCF content:', error); console.error('Error parsing VCF content:', error);
@ -199,6 +204,7 @@ export default function CarnetPage() {
const fetchContacts = async (folder: string) => { const fetchContacts = async (folder: string) => {
try { try {
setIsLoadingContacts(true); setIsLoadingContacts(true);
// First, check if we're looking at a specific VCF file // First, check if we're looking at a specific VCF file
if (folder.endsWith('.vcf')) { if (folder.endsWith('.vcf')) {
const response = await fetch(`/api/nextcloud/files/content?path=${encodeURIComponent(`/files/cube-${session?.user?.id}/Private/Contacts/${folder}`)}`); const response = await fetch(`/api/nextcloud/files/content?path=${encodeURIComponent(`/files/cube-${session?.user?.id}/Private/Contacts/${folder}`)}`);