carnet panel contact 2
This commit is contained in:
parent
cce84ff69b
commit
5ae91adaec
@ -73,19 +73,33 @@ export default function CarnetPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchNextcloudFolders = async () => {
|
const fetchNextcloudFolders = async () => {
|
||||||
|
// Check cache first
|
||||||
|
if (foldersCache.current) {
|
||||||
|
const cacheAge = Date.now() - foldersCache.current.timestamp;
|
||||||
|
if (cacheAge < 5 * 60 * 1000) { // 5 minutes cache
|
||||||
|
setNextcloudFolders(foldersCache.current.folders);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/nextcloud/files?folder=Contacts');
|
const response = await fetch('/api/nextcloud/status');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch folders');
|
throw new Error('Failed to fetch Nextcloud folders');
|
||||||
}
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
// Filter for VCF files and extract basenames
|
const folders = data.folders || [];
|
||||||
const vcfFiles = data
|
|
||||||
.filter((file: any) => file.basename.endsWith('.vcf'))
|
// Update cache
|
||||||
.map((file: any) => file.basename.replace('.vcf', ''));
|
foldersCache.current = {
|
||||||
setNextcloudFolders(vcfFiles);
|
folders,
|
||||||
} catch (error) {
|
timestamp: Date.now()
|
||||||
console.error('Error fetching folders:', error);
|
};
|
||||||
|
|
||||||
|
setNextcloudFolders(folders);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching Nextcloud folders:', err);
|
||||||
|
setNextcloudFolders([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -547,45 +561,6 @@ export default function CarnetPage() {
|
|||||||
return formatVCard(vcard);
|
return formatVCard(vcard);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCreateGroup = async (groupName: string) => {
|
|
||||||
if (!session?.user?.id) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
// Create a new empty VCF file for the group
|
|
||||||
const basePath = `/files/cube-${session.user.id}/Private/Contacts`;
|
|
||||||
const vcfFile = `${groupName}.vcf`;
|
|
||||||
const path = `${basePath}/${vcfFile}`;
|
|
||||||
|
|
||||||
// Create an empty VCF file
|
|
||||||
const saveResponse = await fetch('/api/nextcloud/files', {
|
|
||||||
method: 'PUT',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
id: path,
|
|
||||||
title: vcfFile,
|
|
||||||
content: '', // Empty VCF file
|
|
||||||
folder: 'Contacts',
|
|
||||||
mime: 'text/vcard'
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!saveResponse.ok) {
|
|
||||||
throw new Error('Failed to create group');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refresh the folders list to show the new group
|
|
||||||
await fetchNextcloudFolders();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error creating group:', error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen items-center justify-center">
|
<div className="flex h-screen items-center justify-center">
|
||||||
@ -620,24 +595,6 @@ export default function CarnetPage() {
|
|||||||
{showNotes && (
|
{showNotes && (
|
||||||
<>
|
<>
|
||||||
<div className="flex-1 overflow-hidden">
|
<div className="flex-1 overflow-hidden">
|
||||||
<div className="flex justify-between items-center mb-4">
|
|
||||||
<h2 className="text-lg font-semibold">
|
|
||||||
{selectedFolder === 'Contacts' ? 'Contact Groups' : 'Content'}
|
|
||||||
</h2>
|
|
||||||
{selectedFolder === 'Contacts' && (
|
|
||||||
<button
|
|
||||||
onClick={() => {
|
|
||||||
const groupName = prompt('Enter group name:');
|
|
||||||
if (groupName) {
|
|
||||||
handleCreateGroup(groupName);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className="px-3 py-1 text-sm bg-blue-500 text-white rounded hover:bg-blue-600"
|
|
||||||
>
|
|
||||||
New Group
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{selectedFolder === 'Contacts' ? (
|
{selectedFolder === 'Contacts' ? (
|
||||||
<ContactsView
|
<ContactsView
|
||||||
contacts={contacts}
|
contacts={contacts}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user