diff --git a/components/carnet/notes-view.tsx b/components/carnet/notes-view.tsx index b6ccb588..d9f78c67 100644 --- a/components/carnet/notes-view.tsx +++ b/components/carnet/notes-view.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { Search, Plus, X, FileText, Calendar, Heart, Users } from 'lucide-react'; -import { format } from 'date-fns'; +import { format, parse } from 'date-fns'; import { fr } from 'date-fns/locale'; interface Note { @@ -61,7 +61,7 @@ export const NotesView: React.FC = ({ onNoteSelect, currentFolde }; const formatDate = (dateString: string) => { - return format(new Date(dateString), 'EEEE d MMM yyyy, HH:mm', { locale: fr }); + return format(new Date(dateString), 'EEEE d MMM yyyy', { locale: fr }); }; const getFolderIcon = (folder: string) => { @@ -79,6 +79,34 @@ export const NotesView: React.FC = ({ onNoteSelect, currentFolde } }; + 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 `${format(date, 'EEEE d MMM yyyy', { locale: fr })} - ${note.title.replace(dateMatch[1], '').trim()}`; + } + } + return note.title; + }; + + const sortNotes = (notes: Note[]) => { + if (currentFolder === 'Diary' || currentFolder === 'Health') { + return [...notes].sort((a, b) => { + // Try to extract dates from titles + 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(); + } + return 0; + }); + } + return notes; + }; + const Icon = getFolderIcon(currentFolder); return ( @@ -122,34 +150,31 @@ export const NotesView: React.FC = ({ onNoteSelect, currentFolde {/* Notes List */}
{loading ? ( -
-
-
+
Chargement...
) : notes.length === 0 ? ( -
-

Aucune note trouvée

-
+
Aucune note
) : ( - notes.map((note) => ( -
onNoteSelect?.(note)} - > -
-
- - {note.title} - +
    + {sortNotes(notes).map((note) => ( +
  • onNoteSelect?.(note)} + className="p-4 hover:bg-carnet-hover cursor-pointer" + > +
    + +
    +
    + {formatNoteTitle(note)} +
    +
    + {formatDate(note.lastModified)} +
    +
    -
    - {formatDate(note.lastModified)} - - {note.size} bytes -
    -
-
- )) + + ))} + )}