import React, { useState, useEffect } from 'react'; import { Heart, Plus, Calendar, Trash2, ChevronLeft, Smile, Frown, Meh, Zap, CloudRain, Coffee, Search, BookOpen } from 'lucide-react'; // 감정 데이터 정의 const EMOTIONS = [ { id: 'happy', label: '행복해요', icon: Smile, color: 'text-yellow-500', bg: 'bg-yellow-50' }, { id: 'sad', label: '슬퍼요', icon: Frown, color: 'text-blue-500', bg: 'bg-blue-50' }, { id: 'neutral', label: '평온해요', icon: Meh, color: 'text-gray-500', bg: 'bg-gray-50' }, { id: 'excited', label: '설레요', icon: Zap, color: 'text-purple-500', bg: 'bg-purple-50' }, { id: 'depressed', label: '우울해요', icon: CloudRain, color: 'text-indigo-600', bg: 'bg-indigo-50' }, { id: 'tired', label: '피곤해요', icon: Coffee, color: 'text-orange-600', bg: 'bg-orange-50' }, ]; const App = () => { // 상태 관리 const [entries, setEntries] = useState([]); const [isAdding, setIsAdding] = useState(false); const [currentEntry, setCurrentEntry] = useState({ content: '', emotion: 'neutral', date: new Date().toISOString().split('T')[0] }); const [searchTerm, setSearchTerm] = useState(''); // 초기 샘플 데이터 useEffect(() => { const sampleData = [ { id: 1, date: '2024-05-15', emotion: 'happy', content: '오늘 친구들과 오랜만에 만나서 맛있는 점심을 먹었다. 날씨도 너무 좋아서 행복한 하루였다.' }, { id: 2, date: '2024-05-14', emotion: 'tired', content: '업무가 너무 많아서 퇴근이 늦어졌다. 집에 오자마자 침대에 눕고 싶었다.' } ]; setEntries(sampleData); }, []); // 새 일기 저장 const handleSaveEntry = () => { if (!currentEntry.content.trim()) return; const newEntry = { ...currentEntry, id: Date.now(), }; setEntries([newEntry, ...entries]); setIsAdding(false); setCurrentEntry({ content: '', emotion: 'neutral', date: new Date().toISOString().split('T')[0] }); }; // 일기 삭제 const handleDeleteEntry = (id) => { setEntries(entries.filter(entry => entry.id !== id)); }; // 필터링된 엔트리 const filteredEntries = entries.filter(entry => entry.content.toLowerCase().includes(searchTerm.toLowerCase()) ); return (
{/* 헤더 */}

마음 기록

오늘 당신의 마음은 어떤가요?

{!isAdding && ( )}
{isAdding ? ( /* 작성 폼 */

오늘의 일기 작성

{/* 날짜 선택 */}
setCurrentEntry({...currentEntry, date: e.target.value})} className="w-full pl-10 pr-4 py-2 border border-slate-200 rounded-lg focus:ring-2 focus:ring-indigo-500 outline-none" />
{/* 감정 선택 */}
{EMOTIONS.map((emo) => { const Icon = emo.icon; const isSelected = currentEntry.emotion === emo.id; return ( ); })}
{/* 본문 작성 */}