@@ -8,49 +8,22 @@ import ButtonSection from '@/components/home/ButtonSection';
88
99import { useEffect , useState } from 'react' ;
1010import { useAuthUser } from '@/hooks/useAuthUser' ;
11-
12- import {
13- Todo ,
14- fetchTodos ,
15- AddTodo ,
16- toggleTodoStatus ,
17- } from '@/services/home/todoService.service' ;
11+ import { useTodayPlanItems } from '@/hooks/useTodayPlanItems' ;
1812import { getProfile , Profile } from '@/services/home/profileService.service' ;
1913
2014const Page = ( ) => {
2115 // 현재 사용자 정보
2216 const { user : currentUser , authLoading } = useAuthUser ( ) ;
23-
2417 const [ profile , setProfile ] = useState < Profile | null > ( null ) ;
25- const [ todos , setTodos ] = useState < Todo [ ] > ( [ ] ) ;
2618 const [ error , setError ] = useState < string | null > ( null ) ;
2719
28- // 1. 할 일 목록 불러오기
29- const loadTodos = async ( uid : string ) => {
30- try {
31- setError ( null ) ;
32-
33- const fetchedTodos = await fetchTodos ( uid ) ;
34- setTodos ( fetchedTodos ) ;
35- } catch ( err ) {
36- console . error ( err ) ;
37- setError ( '데이터를 불러오는 데 실패하였습니다' ) ;
38- }
39- } ;
40-
41- // 3. 할 일 상태 토글
42- const handleToggleTodo = async ( id : string , currentStatus : boolean ) => {
43- if ( ! currentUser ) return ;
44- try {
45- setError ( null ) ;
46-
47- await toggleTodoStatus ( currentUser . uid , id , currentStatus ) ;
48- await loadTodos ( currentUser . uid ) ;
49- } catch ( err ) {
50- console . error ( err ) ;
51- setError ( '상태를 업데이트하는 데 실패하였습니다' ) ;
52- }
53- } ;
20+ const {
21+ items,
22+ loading : planLoading ,
23+ error : planError ,
24+ toggle,
25+ progressText,
26+ } = useTodayPlanItems ( currentUser ?. uid ) ;
5427
5528 // 사용자가 존재하면 데이터 불러옴
5629 useEffect ( ( ) => {
@@ -59,7 +32,6 @@ const Page = () => {
5932 try {
6033 const userProfile = await getProfile ( currentUser . uid ) ;
6134 setProfile ( userProfile ) ;
62- await loadTodos ( currentUser . uid ) ;
6335 } catch ( err ) {
6436 console . error ( err ) ;
6537 setError ( '프로필 정보를 불러오는 데 실패하였습니다' ) ;
@@ -96,6 +68,7 @@ const Page = () => {
9668 className = "grid grid-cols-1 gap-4 md:grid-cols-3"
9769 profile = { profile }
9870 uid = { currentUser . uid }
71+ progressText = { progressText }
9972 />
10073
10174 { /* 2-2. GraphSection */ }
@@ -104,7 +77,10 @@ const Page = () => {
10477 { /* 2-3. BottomSection */ }
10578 < BottomSection
10679 className = "grid grid-cols-1 gap-4 md:grid-cols-2"
107- uid = { currentUser . uid }
80+ items = { items }
81+ loading = { planLoading }
82+ error = { planError }
83+ onToggle = { toggle }
10884 />
10985
11086 { /* 3. ButtonSection */ }
0 commit comments