From a10660a27feca9d151d178ffe100fb35404ed34a Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 20 Apr 2025 22:17:07 +0200 Subject: [PATCH] carnet panel contact --- app/carnet/page.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/carnet/page.tsx b/app/carnet/page.tsx index b69defbf..3195ad1c 100644 --- a/app/carnet/page.tsx +++ b/app/carnet/page.tsx @@ -454,13 +454,16 @@ export default function CarnetPage() { } const { content } = await response.json(); - const contacts = parseVCardContent(content); - // Remove the contact - const updatedContacts = contacts.filter(c => c.id !== contact.id); + // Split the content into individual vCards and filter out the one to delete + const vcards = content.split('BEGIN:VCARD').filter(section => section.trim()); + const updatedVcards = vcards.filter(section => { + const vcard = parseVCard('BEGIN:VCARD' + section); + return vcard.uid?.[0]?.value !== contact.id; + }); - // Generate new VCF content - const vcfContent = updatedContacts.map(c => generateVCardContent(c)).join('\n'); + // Join the remaining vCards back together + const vcfContent = updatedVcards.map(section => 'BEGIN:VCARD' + section).join('\n'); // Save the updated VCF file const saveResponse = await fetch('/api/nextcloud/files', {