From dbaf0d4939c7f74dbf39d876e0a7a1598addb03e Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 20 Apr 2025 19:04:52 +0200 Subject: [PATCH] carnet panel --- components/carnet/navigation.tsx | 107 +++++++++++++++++-------------- 1 file changed, 58 insertions(+), 49 deletions(-) diff --git a/components/carnet/navigation.tsx b/components/carnet/navigation.tsx index d07fe53a..a1f45945 100644 --- a/components/carnet/navigation.tsx +++ b/components/carnet/navigation.tsx @@ -1,6 +1,6 @@ "use client"; -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { Search, BookOpen, Tag, Trash2, Star, Archive, X, Folder, FileText, Calendar, Heart, Users, LucideIcon, ChevronRight } from 'lucide-react'; interface NavigationProps { @@ -23,30 +23,18 @@ const FOLDER_CONFIG: Record = { 'Contacts': { icon: Users, order: 4 } }; -interface ContactGroup { - name: string; - contacts: string[]; +interface ContactFile { + id: string; + filename: string; + basename: string; + lastmod: string; } export default function Navigation({ nextcloudFolders, onFolderSelect }: NavigationProps) { const [searchQuery, setSearchQuery] = useState(''); - const [expandedGroups, setExpandedGroups] = useState>(new Set()); - const [contactGroups, setContactGroups] = useState([ - { name: 'Family', contacts: [] }, - { name: 'Friends', contacts: [] }, - { name: 'Work', contacts: [] }, - { name: 'Other', contacts: [] } - ]); - - const toggleGroup = (groupName: string) => { - const newExpanded = new Set(expandedGroups); - if (newExpanded.has(groupName)) { - newExpanded.delete(groupName); - } else { - newExpanded.add(groupName); - } - setExpandedGroups(newExpanded); - }; + const [expandedContacts, setExpandedContacts] = useState(false); + const [contactFiles, setContactFiles] = useState([]); + const [isLoadingContacts, setIsLoadingContacts] = useState(false); const getFolderIcon = (folder: string) => { switch (folder) { @@ -70,6 +58,28 @@ export default function Navigation({ nextcloudFolders, onFolderSelect }: Navigat return orderA - orderB; }); + const fetchContactFiles = async () => { + try { + setIsLoadingContacts(true); + const response = await fetch('/api/nextcloud/files?folder=Contacts'); + if (response.ok) { + const files = await response.json(); + const vcfFiles = files.filter((file: any) => file.basename.endsWith('.vcf')); + setContactFiles(vcfFiles); + } + } catch (error) { + console.error('Error fetching contact files:', error); + } finally { + setIsLoadingContacts(false); + } + }; + + useEffect(() => { + if (expandedContacts) { + fetchContactFiles(); + } + }, [expandedContacts]); + return (
{/* Search */} @@ -102,43 +112,42 @@ export default function Navigation({ nextcloudFolders, onFolderSelect }: Navigat return (
- {folder === 'Contacts' && ( + {folder === 'Contacts' && expandedContacts && (
- {contactGroups.map((group) => ( -
+ {isLoadingContacts ? ( +
Chargement...
+ ) : contactFiles.length === 0 ? ( +
Aucun contact
+ ) : ( + contactFiles.map((file) => ( - {expandedGroups.has(group.name) && ( -
- {group.contacts.map((contact) => ( - - ))} -
- )} -
- ))} + )) + )}
)}