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