diff --git a/app/carnet/page.tsx b/app/carnet/page.tsx index 7ea7de07..b6b47e40 100644 --- a/app/carnet/page.tsx +++ b/app/carnet/page.tsx @@ -200,7 +200,7 @@ export default function CarnetPage() { } }; - const fetchContacts = async (folder: string): Promise => { + 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) {