carnet panel contact

This commit is contained in:
alma 2025-04-20 22:26:54 +02:00
parent 15ca9e1fd5
commit 4e0da5b39c

View File

@ -200,7 +200,7 @@ export default function CarnetPage() {
}
};
const fetchContacts = async (folder: string): Promise<Contact[]> => {
const fetchContacts = async (folder: string) => {
try {
setIsLoadingContacts(true);
@ -210,10 +210,10 @@ export default function CarnetPage() {
if (response.ok) {
const { content } = await response.json();
const contacts = parseVCardContent(content);
return contacts.map(contact => ({
setContacts(contacts.map(contact => ({
...contact,
group: folder.replace('.vcf', '')
}));
})));
}
} else {
// If not a VCF file, list all VCF files in the folder
@ -244,13 +244,12 @@ export default function CarnetPage() {
);
// Flatten the array of contact arrays
return parsedContacts.flat().filter(Boolean);
setContacts(parsedContacts.flat().filter(Boolean));
}
}
return [];
} catch (error) {
console.error('Error fetching contacts:', error);
return [];
setContacts([]);
} finally {
setIsLoadingContacts(false);
}
@ -443,9 +442,8 @@ export default function CarnetPage() {
throw new Error('Failed to save contact');
}
// Refresh only the contacts list without reloading the page
const updatedContacts = await fetchContacts(selectedFolder);
setContacts(updatedContacts);
// Refresh the contacts list
await fetchContacts(selectedFolder);
// Update the selected contact if it was edited
if (contactUpdated) {