import React from 'react'; import { Note } from '../types'; interface NotesListProps { notes: Note[]; selectedNoteId: number | null; onSelectNote: (id: number) => void; onCreateNote: () => void; onDeleteNote: (note: Note) => void; onSync: () => void; onLogout: () => void; username: string; theme: 'light' | 'dark' | 'system'; onThemeChange: (theme: 'light' | 'dark' | 'system') => void; searchText: string; onSearchChange: (text: string) => void; showFavoritesOnly: boolean; onToggleFavorites: () => void; } export function NotesList({ notes, selectedNoteId, onSelectNote, onCreateNote, onDeleteNote, onSync, onLogout, username, theme, onThemeChange, searchText, onSearchChange, showFavoritesOnly, onToggleFavorites, }: NotesListProps) { const [isSyncing, setIsSyncing] = React.useState(false); const [deleteClickedId, setDeleteClickedId] = React.useState(null); const handleSync = async () => { setIsSyncing(true); await onSync(); setTimeout(() => setIsSyncing(false), 500); }; const handleDeleteClick = (note: Note, e: React.MouseEvent) => { e.stopPropagation(); if (deleteClickedId === note.id) { // Second click - actually delete onDeleteNote(note); setDeleteClickedId(null); } else { // First click - show confirmation state setDeleteClickedId(note.id); // Reset after 3 seconds setTimeout(() => setDeleteClickedId(null), 3000); } }; const formatDate = (timestamp: number) => { const date = new Date(timestamp * 1000); const now = new Date(); const diff = now.getTime() - date.getTime(); const minutes = Math.floor(diff / 60000); const hours = Math.floor(diff / 3600000); const days = Math.floor(diff / 86400000); if (minutes < 1) return 'just now'; if (minutes < 60) return `${minutes}m ago`; if (hours < 24) return `${hours}h ago`; if (days < 7) return `${days}d ago`; return date.toLocaleDateString(); }; const getPreview = (content: string) => { const lines = content.split('\n').filter(l => l.trim()); return lines.slice(1, 3).join(' ').substring(0, 100); }; return (

Notes

onSearchChange(e.target.value)} placeholder="Search notes..." className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent" />
{notes.length} notes
{notes.length === 0 ? (

No notes found

) : ( notes.map((note) => (
onSelectNote(note.id)} className={`p-3 border-b border-gray-200 dark:border-gray-700 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors group ${ note.id === selectedNoteId ? 'bg-blue-50 dark:bg-gray-800 border-l-4 border-l-blue-500' : '' }`} >
{note.favorite && ( )}

{note.title || 'Untitled'}

{deleteClickedId === note.id && ( Click again to delete )}
{formatDate(note.modified)}
{getPreview(note.content) && (

{getPreview(note.content)}

)}
)) )}
{/* User Info and Logout */}
{username.charAt(0).toUpperCase()}
{username}
{/* Theme Toggle */}
Theme
); }