carnet panel contact
This commit is contained in:
parent
643afb5567
commit
23d9e0aed5
@ -394,30 +394,56 @@ export default function CarnetPage() {
|
|||||||
|
|
||||||
const { content } = await response.json();
|
const { content } = await response.json();
|
||||||
|
|
||||||
// Split the content into individual vCards and clean up empty lines
|
// Split the content into individual vCards
|
||||||
const vcards = content.split('BEGIN:VCARD')
|
const vcards = content.split('BEGIN:VCARD')
|
||||||
.filter(section => section.trim())
|
.filter(section => section.trim())
|
||||||
.map(section => section.trim());
|
.map(section => 'BEGIN:VCARD' + section.trim());
|
||||||
|
|
||||||
// Update or add the contact
|
// Update or add the contact
|
||||||
let updatedVcards: string[] = [];
|
let updatedVcards: string[] = [];
|
||||||
let contactUpdated = false;
|
let contactUpdated = false;
|
||||||
|
|
||||||
for (const section of vcards) {
|
for (const vcard of vcards) {
|
||||||
const vcard = parseVCard('BEGIN:VCARD' + section);
|
const parsed = parseVCard(vcard);
|
||||||
if (vcard.uid?.[0]?.value === contact.id) {
|
if (parsed.uid?.[0]?.value === contact.id) {
|
||||||
// Replace the existing contact
|
// Replace the existing contact
|
||||||
updatedVcards.push(generateVCardContent(contact));
|
const newVcard = [
|
||||||
|
'BEGIN:VCARD',
|
||||||
|
'VERSION:3.0',
|
||||||
|
`UID:${contact.id}`,
|
||||||
|
`FN:${contact.fullName || ''}`,
|
||||||
|
...(contact.email ? [`EMAIL;TYPE=INTERNET:${contact.email}`] : []),
|
||||||
|
...(contact.phone ? [`TEL;TYPE=CELL:${contact.phone}`] : []),
|
||||||
|
...(contact.organization ? [`ORG:${contact.organization}`] : []),
|
||||||
|
...(contact.address ? [`ADR:${contact.address}`] : []),
|
||||||
|
...(contact.notes ? [`NOTE:${contact.notes}`] : []),
|
||||||
|
...(contact.group ? [`CATEGORIES:${contact.group}`] : []),
|
||||||
|
'END:VCARD'
|
||||||
|
].join('\n');
|
||||||
|
updatedVcards.push(newVcard);
|
||||||
contactUpdated = true;
|
contactUpdated = true;
|
||||||
} else {
|
} else {
|
||||||
// Keep the existing contact
|
// Keep the existing contact
|
||||||
updatedVcards.push('BEGIN:VCARD' + section);
|
updatedVcards.push(vcard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If contact wasn't found, add it as new
|
// If contact wasn't found, add it as new
|
||||||
if (!contactUpdated) {
|
if (!contactUpdated) {
|
||||||
updatedVcards.push(generateVCardContent(contact));
|
const newVcard = [
|
||||||
|
'BEGIN:VCARD',
|
||||||
|
'VERSION:3.0',
|
||||||
|
`UID:${contact.id}`,
|
||||||
|
`FN:${contact.fullName || ''}`,
|
||||||
|
...(contact.email ? [`EMAIL;TYPE=INTERNET:${contact.email}`] : []),
|
||||||
|
...(contact.phone ? [`TEL;TYPE=CELL:${contact.phone}`] : []),
|
||||||
|
...(contact.organization ? [`ORG:${contact.organization}`] : []),
|
||||||
|
...(contact.address ? [`ADR:${contact.address}`] : []),
|
||||||
|
...(contact.notes ? [`NOTE:${contact.notes}`] : []),
|
||||||
|
...(contact.group ? [`CATEGORIES:${contact.group}`] : []),
|
||||||
|
'END:VCARD'
|
||||||
|
].join('\n');
|
||||||
|
updatedVcards.push(newVcard);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join all vCards back together with proper spacing
|
// Join all vCards back together with proper spacing
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user