@@ -12,75 +12,49 @@ import {
1212} from "../auth/index"
1313import {
1414 getEmotionColor ,
15- fetchEmotionType ,
16- EmotionTypeData
15+ fetchEmotionType
1716} from "../utils/emotionUtils"
1817import Calendar from "../components/Calendar"
19- import HeaderBar from "../components/HeaderBar"
20-
21- // 감정 타입 인터페이스 (공통 유틸리티 사용)
22- type EmotionType = EmotionTypeData ;
23-
24- // 시간대별 일기 데이터 구조 (타입 정의만 유지)
25- interface DiaryData {
26- morning ?: {
27- predictedEmotions : Array < { emotion : string , category : string , color : string } > ;
28- predictedText : string ;
29- actualEmotions : Array < { emotion : string , category : string , color : string } > ;
30- actualText : string ;
31- } ;
32- afternoon ?: {
33- predictedEmotions : Array < { emotion : string , category : string , color : string } > ;
34- predictedText : string ;
35- actualEmotions : Array < { emotion : string , category : string , color : string } > ;
36- actualText : string ;
37- } ;
38- evening ?: {
39- predictedEmotions : Array < { emotion : string , category : string , color : string } > ;
40- predictedText : string ;
41- actualEmotions : Array < { emotion : string , category : string , color : string } > ;
42- actualText : string ;
43- } ;
44- }
18+ import PageHeader from "../components/PageHeader"
19+ import {
20+ DiaryData ,
21+ DiaryTimeData ,
22+ TimeSlot ,
23+ TIME_PERIODS
24+ } from "../types/common"
25+ import {
26+ formatDate ,
27+ isToday ,
28+ isPastDate ,
29+ isCurrentMonth ,
30+ generateCalendarDays
31+ } from "../utils/dateUtils"
32+ import LoadingSpinner from "../components/LoadingSpinner"
33+ import ErrorMessage from "../components/ErrorMessage"
34+ import EmptyState from "../components/EmptyState"
35+ import TimeSlotSelector from "../components/TimeSlotSelector"
36+ import DiaryCard from "../components/DiaryCard"
37+
38+ // 공통 타입 사용
4539
4640export default function Present ( ) {
4741 const router = useRouter ( )
4842 const { selectedChild, isLoading } = useChild ( )
4943 const [ selectedDate , setSelectedDate ] = useState < string | null > ( null )
50- const [ selectedTimeSlot , setSelectedTimeSlot ] = useState < 'morning' | 'afternoon' | 'evening' > ( 'morning' )
44+ const [ selectedTimeSlot , setSelectedTimeSlot ] = useState < TimeSlot > ( 'morning' )
5145 const [ currentMonth , setCurrentMonth ] = useState ( new Date ( ) )
5246 const [ loading , setLoading ] = useState ( false )
5347 const [ error , setError ] = useState < string | null > ( null )
5448 const [ forecastData , setForecastData ] = useState < Record < string , any > > ( { } )
5549
5650
5751
58- const formatDate = ( date : Date ) => {
59- const year = date . getFullYear ( ) ;
60- const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
61- const day = String ( date . getDate ( ) ) . padStart ( 2 , '0' ) ;
62- return `${ year } -${ month } -${ day } ` ;
63- } ;
64-
65- const isToday = ( date : Date ) => {
66- const today = new Date ( ) ;
67- return date . toDateString ( ) === today . toDateString ( ) ;
68- } ;
69-
7052 const isTomorrow = ( date : Date ) => {
7153 const tomorrow = new Date ( ) ;
7254 tomorrow . setDate ( tomorrow . getDate ( ) + 1 ) ;
7355 return date . toDateString ( ) === tomorrow . toDateString ( ) ;
7456 } ;
7557
76- const isPastDate = ( date : Date ) => {
77- const today = new Date ( ) ;
78- today . setHours ( 0 , 0 , 0 , 0 ) ;
79- const compareDate = new Date ( date ) ;
80- compareDate . setHours ( 0 , 0 , 0 , 0 ) ;
81- return compareDate < today ;
82- } ;
83-
8458 const isMoreThanTwoDaysLater = ( date : Date ) => {
8559 const today = new Date ( ) ;
8660 today . setHours ( 0 , 0 , 0 , 0 ) ;
@@ -94,10 +68,6 @@ export default function Present() {
9468 return compareDate >= twoDaysLater ;
9569 } ;
9670
97- const isCurrentMonth = ( date : Date ) => {
98- return date . getMonth ( ) === currentMonth . getMonth ( ) ;
99- } ;
100-
10171 const hasDiary = ( date : Date ) => {
10272 const dateStr = formatDate ( date ) ;
10373 const diaryData = forecastData [ dateStr ] ;
@@ -259,7 +229,7 @@ export default function Present() {
259229 } ;
260230 } ;
261231
262- // 현재 달의 과거 날짜들에 대한 데이터 미리 로드
232+ // 현재 달의 과거 날짜들과 오늘 날짜에 대한 데이터 미리 로드
263233 useEffect ( ( ) => {
264234 if ( selectedChild ?. id && ! isLoading ) {
265235 const today = new Date ( ) ;
@@ -269,7 +239,7 @@ export default function Present() {
269239 const lastDay = new Date ( year , month + 1 , 0 ) ;
270240
271241 for ( let date = new Date ( firstDay ) ; date <= lastDay ; date . setDate ( date . getDate ( ) + 1 ) ) {
272- if ( isPastDate ( date ) ) {
242+ if ( isPastDate ( date ) || isToday ( date ) ) {
273243 const dateStr = formatDate ( date ) ;
274244 if ( ! forecastData [ dateStr ] ) {
275245 loadForecastData ( dateStr ) ;
@@ -293,14 +263,7 @@ export default function Present() {
293263 < Container >
294264 < div className = "flex flex-col items-start justify-start flex-grow w-full max-w-sm mx-auto mt-4" >
295265 { /* 상단바 */ }
296- < div className = "flex items-end justify-between w-full rounded-lg px-2 mb-6" >
297- < HeaderBar
298- childName = { selectedChild ?. name || '' }
299- inviteCode = { selectedChild ?. inviteCode }
300- showChildListButton = { false }
301- showSettingsButton = { true }
302- />
303- </ div >
266+ < PageHeader showLogo = { true } />
304267
305268 { /* 달력 컴포넌트 */ }
306269 < Calendar
0 commit comments