carnet panel contact
This commit is contained in:
parent
20d38dd8ea
commit
c6a8b4729f
@ -9,6 +9,7 @@ import { Editor } from "@/components/carnet/editor";
|
|||||||
import { PanelResizer } from "@/components/carnet/panel-resizer";
|
import { PanelResizer } from "@/components/carnet/panel-resizer";
|
||||||
import { useMediaQuery } from "@/hooks/use-media-query";
|
import { useMediaQuery } from "@/hooks/use-media-query";
|
||||||
import { ContactsView } from '@/components/carnet/contacts-view';
|
import { ContactsView } from '@/components/carnet/contacts-view';
|
||||||
|
import { X, Menu } from "lucide-react";
|
||||||
|
|
||||||
// Layout modes
|
// Layout modes
|
||||||
export enum PaneLayout {
|
export enum PaneLayout {
|
||||||
@ -139,10 +140,29 @@ export default function CarnetPage() {
|
|||||||
throw new Error('Failed to fetch notes');
|
throw new Error('Failed to fetch notes');
|
||||||
}
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setNotes(data);
|
if (selectedFolder === 'Contacts') {
|
||||||
|
// For contacts, parse the VCF files
|
||||||
|
const parsedContacts = await Promise.all(
|
||||||
|
data.map(async (file: any) => {
|
||||||
|
const contentResponse = await fetch(`/api/nextcloud/files/content?id=${file.filename}`);
|
||||||
|
if (contentResponse.ok) {
|
||||||
|
const content = await contentResponse.text();
|
||||||
|
return parseVCard(content);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
setContacts(parsedContacts.filter(Boolean));
|
||||||
|
} else {
|
||||||
|
setNotes(data);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching notes:', error);
|
console.error('Error fetching data:', error);
|
||||||
setNotes([]);
|
if (selectedFolder === 'Contacts') {
|
||||||
|
setContacts([]);
|
||||||
|
} else {
|
||||||
|
setNotes([]);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoadingNotes(false);
|
setIsLoadingNotes(false);
|
||||||
}
|
}
|
||||||
@ -343,17 +363,12 @@ export default function CarnetPage() {
|
|||||||
{/* Navigation Panel */}
|
{/* Navigation Panel */}
|
||||||
{showNav && (
|
{showNav && (
|
||||||
<>
|
<>
|
||||||
<div
|
<div className="flex-none" style={{ width: navWidth }}>
|
||||||
className="flex flex-col h-full bg-carnet-sidebar"
|
|
||||||
style={{ width: `${navWidth}px` }}
|
|
||||||
>
|
|
||||||
<Navigation
|
<Navigation
|
||||||
nextcloudFolders={nextcloudFolders}
|
nextcloudFolders={nextcloudFolders}
|
||||||
onFolderSelect={handleFolderSelect}
|
onFolderSelect={handleFolderSelect}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Navigation Resizer */}
|
|
||||||
<PanelResizer
|
<PanelResizer
|
||||||
isDragging={isDraggingNav}
|
isDragging={isDraggingNav}
|
||||||
onDragStart={() => setIsDraggingNav(true)}
|
onDragStart={() => setIsDraggingNav(true)}
|
||||||
@ -363,7 +378,7 @@ export default function CarnetPage() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Notes Panel */}
|
{/* Notes/Contacts Panel */}
|
||||||
{showNotes && (
|
{showNotes && (
|
||||||
<>
|
<>
|
||||||
<div className="flex-1 overflow-hidden">
|
<div className="flex-1 overflow-hidden">
|
||||||
@ -372,7 +387,7 @@ export default function CarnetPage() {
|
|||||||
contacts={contacts}
|
contacts={contacts}
|
||||||
onContactSelect={setSelectedContact}
|
onContactSelect={setSelectedContact}
|
||||||
selectedContact={selectedContact}
|
selectedContact={selectedContact}
|
||||||
loading={isLoadingContacts}
|
loading={isLoadingNotes}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<NotesView
|
<NotesView
|
||||||
@ -406,28 +421,26 @@ export default function CarnetPage() {
|
|||||||
// Refresh the notes list
|
// Refresh the notes list
|
||||||
fetch(`/api/nextcloud/files?folder=${selectedFolder}`)
|
fetch(`/api/nextcloud/files?folder=${selectedFolder}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(updatedNotes => setNotes(updatedNotes))
|
.then(updatedNotes => {
|
||||||
.catch(error => console.error('Error refreshing notes:', error));
|
if (selectedFolder === 'Contacts') {
|
||||||
|
setContacts(updatedNotes);
|
||||||
|
} else {
|
||||||
|
setNotes(updatedNotes);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => console.error('Error refreshing data:', error));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile Navigation Toggle */}
|
{/* Mobile Navigation Toggle */}
|
||||||
{isMobile && (
|
{isMobile && (
|
||||||
<div className="fixed bottom-4 right-4 flex space-x-2">
|
<button
|
||||||
<button
|
onClick={() => setShowNav(!showNav)}
|
||||||
className="p-2 rounded-full bg-primary text-white"
|
className="fixed bottom-4 right-4 bg-primary text-white p-3 rounded-full shadow-lg"
|
||||||
onClick={() => setShowNav(!showNav)}
|
>
|
||||||
>
|
{showNav ? <X className="h-6 w-6" /> : <Menu className="h-6 w-6" />}
|
||||||
{showNav ? 'Hide Nav' : 'Show Nav'}
|
</button>
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className="p-2 rounded-full bg-primary text-white"
|
|
||||||
onClick={() => setShowNotes(!showNotes)}
|
|
||||||
>
|
|
||||||
{showNotes ? 'Hide Notes' : 'Show Notes'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user