carnet panel

This commit is contained in:
alma 2025-04-20 18:47:04 +02:00
parent dff3a24347
commit c9d483223d
2 changed files with 33 additions and 24 deletions

View File

@ -38,6 +38,7 @@ export default function CarnetPage() {
const [nextcloudFolders, setNextcloudFolders] = useState<string[]>([]);
const [selectedFolder, setSelectedFolder] = useState<string>('Notes');
const [notes, setNotes] = useState<Note[]>([]);
const [isLoadingNotes, setIsLoadingNotes] = useState(true);
// Panel widths state
const [navWidth, setNavWidth] = useState(220);
@ -114,6 +115,27 @@ export default function CarnetPage() {
}
}, [isSmallScreen, isMediumScreen]);
useEffect(() => {
const fetchNotes = async () => {
try {
setIsLoadingNotes(true);
const response = await fetch(`/api/nextcloud/files?folder=${selectedFolder}`);
if (!response.ok) {
throw new Error('Failed to fetch notes');
}
const data = await response.json();
setNotes(data);
} catch (error) {
console.error('Error fetching notes:', error);
setNotes([]);
} finally {
setIsLoadingNotes(false);
}
};
fetchNotes();
}, [selectedFolder]);
// Handle panel resizing
const handleNavResize = (e: MouseEvent) => {
if (!isDraggingNav) return;
@ -232,6 +254,8 @@ export default function CarnetPage() {
<>
<div className="flex-1 overflow-hidden">
<NotesView
notes={notes}
loading={isLoadingNotes}
onNoteSelect={handleNoteSelect}
currentFolder={selectedFolder}
onNewNote={handleNewNote}

View File

@ -16,36 +16,21 @@ interface Note {
}
interface NotesViewProps {
notes: Note[];
onNoteSelect?: (note: Note) => void;
currentFolder?: string;
onNewNote?: () => void;
loading?: boolean;
}
export const NotesView: React.FC<NotesViewProps> = ({ onNoteSelect, currentFolder = 'Notes', onNewNote }) => {
export const NotesView: React.FC<NotesViewProps> = ({
notes,
onNoteSelect,
currentFolder = 'Notes',
onNewNote,
loading = false
}) => {
const [searchQuery, setSearchQuery] = useState('');
const [notes, setNotes] = useState<Note[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchNotes = async () => {
try {
setLoading(true);
const response = await fetch(`/api/nextcloud/files?folder=${currentFolder}`);
if (!response.ok) {
throw new Error('Failed to fetch notes');
}
const data = await response.json();
setNotes(data);
} catch (err) {
console.error('Error fetching notes:', err);
setNotes([]);
} finally {
setLoading(false);
}
};
fetchNotes();
}, [currentFolder]);
const formatDate = (dateString: string) => {
return format(new Date(dateString), 'EEEE d MMM yyyy', { locale: fr });