carnet panel
This commit is contained in:
parent
1cd3b63d53
commit
dbaf0d4939
@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"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';
|
import { Search, BookOpen, Tag, Trash2, Star, Archive, X, Folder, FileText, Calendar, Heart, Users, LucideIcon, ChevronRight } from 'lucide-react';
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
@ -23,30 +23,18 @@ const FOLDER_CONFIG: Record<FolderType, FolderConfig> = {
|
|||||||
'Contacts': { icon: Users, order: 4 }
|
'Contacts': { icon: Users, order: 4 }
|
||||||
};
|
};
|
||||||
|
|
||||||
interface ContactGroup {
|
interface ContactFile {
|
||||||
name: string;
|
id: string;
|
||||||
contacts: string[];
|
filename: string;
|
||||||
|
basename: string;
|
||||||
|
lastmod: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Navigation({ nextcloudFolders, onFolderSelect }: NavigationProps) {
|
export default function Navigation({ nextcloudFolders, onFolderSelect }: NavigationProps) {
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
const [expandedGroups, setExpandedGroups] = useState<Set<string>>(new Set());
|
const [expandedContacts, setExpandedContacts] = useState(false);
|
||||||
const [contactGroups, setContactGroups] = useState<ContactGroup[]>([
|
const [contactFiles, setContactFiles] = useState<ContactFile[]>([]);
|
||||||
{ name: 'Family', contacts: [] },
|
const [isLoadingContacts, setIsLoadingContacts] = useState(false);
|
||||||
{ 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 getFolderIcon = (folder: string) => {
|
const getFolderIcon = (folder: string) => {
|
||||||
switch (folder) {
|
switch (folder) {
|
||||||
@ -70,6 +58,28 @@ export default function Navigation({ nextcloudFolders, onFolderSelect }: Navigat
|
|||||||
return orderA - orderB;
|
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 (
|
return (
|
||||||
<div className="flex flex-col h-full bg-carnet-sidebar">
|
<div className="flex flex-col h-full bg-carnet-sidebar">
|
||||||
{/* Search */}
|
{/* Search */}
|
||||||
@ -102,43 +112,42 @@ export default function Navigation({ nextcloudFolders, onFolderSelect }: Navigat
|
|||||||
return (
|
return (
|
||||||
<div key={folder}>
|
<div key={folder}>
|
||||||
<button
|
<button
|
||||||
onClick={() => onFolderSelect(folder)}
|
onClick={() => {
|
||||||
|
if (folder === 'Contacts') {
|
||||||
|
setExpandedContacts(!expandedContacts);
|
||||||
|
} else {
|
||||||
|
onFolderSelect(folder);
|
||||||
|
}
|
||||||
|
}}
|
||||||
className="w-full flex items-center space-x-2 px-3 py-2 text-sm rounded-md text-carnet-text-primary hover:bg-carnet-hover"
|
className="w-full flex items-center space-x-2 px-3 py-2 text-sm rounded-md text-carnet-text-primary hover:bg-carnet-hover"
|
||||||
>
|
>
|
||||||
<Icon className="h-4 w-4" />
|
<Icon className="h-4 w-4" />
|
||||||
<span>{folder}</span>
|
<span>{folder}</span>
|
||||||
|
{folder === 'Contacts' && (
|
||||||
|
<ChevronRight
|
||||||
|
className={`h-4 w-4 transition-transform ${
|
||||||
|
expandedContacts ? 'transform rotate-90' : ''
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</button>
|
</button>
|
||||||
{folder === 'Contacts' && (
|
{folder === 'Contacts' && expandedContacts && (
|
||||||
<div className="ml-4 mt-1 space-y-1">
|
<div className="ml-4 mt-1 space-y-1">
|
||||||
{contactGroups.map((group) => (
|
{isLoadingContacts ? (
|
||||||
<div key={group.name}>
|
<div className="px-3 py-2 text-sm text-carnet-text-muted">Chargement...</div>
|
||||||
|
) : contactFiles.length === 0 ? (
|
||||||
|
<div className="px-3 py-2 text-sm text-carnet-text-muted">Aucun contact</div>
|
||||||
|
) : (
|
||||||
|
contactFiles.map((file) => (
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleGroup(group.name)}
|
key={file.id}
|
||||||
className="w-full flex items-center space-x-2 px-3 py-2 text-sm rounded-md text-carnet-text-primary hover:bg-carnet-hover"
|
onClick={() => onFolderSelect(`Contacts/${file.basename}`)}
|
||||||
|
className="w-full flex items-center space-x-2 px-3 py-2 text-sm rounded-md text-carnet-text-muted hover:bg-carnet-hover"
|
||||||
>
|
>
|
||||||
<ChevronRight
|
<span>{file.basename.replace('.vcf', '')}</span>
|
||||||
className={`h-4 w-4 transition-transform ${
|
|
||||||
expandedGroups.has(group.name) ? 'transform rotate-90' : ''
|
|
||||||
}`}
|
|
||||||
/>
|
|
||||||
<Folder className="h-4 w-4" />
|
|
||||||
<span>{group.name}</span>
|
|
||||||
</button>
|
</button>
|
||||||
{expandedGroups.has(group.name) && (
|
))
|
||||||
<div className="ml-4 space-y-1">
|
)}
|
||||||
{group.contacts.map((contact) => (
|
|
||||||
<button
|
|
||||||
key={contact}
|
|
||||||
onClick={() => onFolderSelect(`${folder}/${group.name}/${contact}`)}
|
|
||||||
className="w-full flex items-center space-x-2 px-3 py-2 text-sm rounded-md text-carnet-text-muted hover:bg-carnet-hover"
|
|
||||||
>
|
|
||||||
<span>{contact}</span>
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user