"use client"; import React, { useState, useEffect } from 'react'; import { Search, Plus, X, FileText, Calendar, Heart, Users } from 'lucide-react'; import { format, parse } from 'date-fns'; import { fr } from 'date-fns/locale'; const FOLDER_DISPLAY_NAMES: Record = { 'Notes': 'Bloc-notes', 'Diary': 'Journal', 'Health': 'Carnet de santé', 'Contacts': 'Carnet d\'adresses' }; interface Note { id: string; title: string; content: string; lastModified: string; type: string; mime: string; etag: string; } interface NotesViewProps { notes: Note[]; onNoteSelect?: (note: Note) => void; currentFolder?: string; onNewNote?: () => void; loading?: boolean; onDeleteNote?: (note: Note) => void; } export const NotesView: React.FC = ({ notes, onNoteSelect, currentFolder = 'Notes', onNewNote, loading = false, onDeleteNote }) => { const [searchQuery, setSearchQuery] = useState(''); const [hoveredNote, setHoveredNote] = useState(null); const [noteToDelete, setNoteToDelete] = useState(null); const formatDate = (dateString: string) => { return format(new Date(dateString), 'EEEE d MMM yyyy', { locale: fr }); }; const getFolderIcon = (folder: string) => { switch (folder) { case 'Notes': return FileText; case 'Diary': return Calendar; case 'Health': return Heart; case 'Contacts': return Users; default: return FileText; } }; const formatNoteTitle = (note: Note) => { if (currentFolder === 'Diary' || currentFolder === 'Health') { // Try to extract date from title (format: YYYY-MM-DD) const dateMatch = note.title.match(/^(\d{4}-\d{2}-\d{2})/); if (dateMatch) { const date = parse(dateMatch[1], 'yyyy-MM-dd', new Date()); return note.title.replace(dateMatch[1], '').trim(); } } return note.title; }; const sortNotes = (notes: Note[]) => { return [...notes].sort((a, b) => { if (currentFolder === 'Diary' || currentFolder === 'Health') { // For Diary and Health, sort by date in title first const dateA = a.title.match(/^(\d{4}-\d{2}-\d{2})/); const dateB = b.title.match(/^(\d{4}-\d{2}-\d{2})/); if (dateA && dateB) { return new Date(dateB[1]).getTime() - new Date(dateA[1]).getTime(); } } // For all folders, sort by lastModified date return new Date(b.lastModified).getTime() - new Date(a.lastModified).getTime(); }); }; const Icon = getFolderIcon(currentFolder); return (
{/* Confirmation Dialog */} {noteToDelete && (

Supprimer la note

Êtes-vous sûr de vouloir supprimer la note "{noteToDelete.title}" ? Cette action est irréversible.

)} {/* Header with New Note Button */}

{FOLDER_DISPLAY_NAMES[currentFolder] || currentFolder}

setSearchQuery(e.target.value)} placeholder="Rechercher des notes..." className="w-full pl-9 pr-4 py-2 bg-white border border-carnet-border rounded-md text-sm text-carnet-text-primary placeholder-carnet-text-muted focus:outline-none focus:ring-1 focus:ring-primary" /> {searchQuery && ( )}
{/* Notes List */}
{loading ? (
Chargement...
) : notes.length === 0 ? (
Aucune note
) : (
    {sortNotes(notes).map((note) => (
  • setHoveredNote(note.id)} onMouseLeave={() => setHoveredNote(null)} className="p-4 hover:bg-carnet-hover cursor-pointer group" >
    onNoteSelect?.(note)} >
    {currentFolder === 'Diary' || currentFolder === 'Health' ? ( <>
    {formatDate(note.lastModified)}
    {formatNoteTitle(note)}
    ) : ( <>
    {note.title}
    {formatDate(note.lastModified)}
    )}
    {currentFolder === 'Notes' && hoveredNote === note.id && ( )}
  • ))}
)}
); };