@@ -4,6 +4,10 @@ import Image from "next/image";
44import styles from "./check-list.module.css" ;
55import notCheck from "../../../public/not_check.svg" ;
66import checkedIcon from "../../../public/checked.svg" ;
7+ import { useState } from "react" ;
8+ import useCompleteTodo from "@/hooks/useCompleteTodo" ;
9+ import { TodoDetailData } from "@/types" ;
10+ import Spinner from "../loading/spinner" ;
711
812export default function CheckList ( {
913 id,
@@ -14,6 +18,12 @@ export default function CheckList({
1418 name : string ;
1519 isCompleted : boolean ;
1620} ) {
21+ const [ task , setTask ] = useState < TodoDetailData | null > ( null ) ;
22+ const { isLoading } = useCompleteTodo ( id , task ) ;
23+ const onClickSetTask = ( ) => {
24+ setTask ( { name, memo : "" , imageUrl : "" , isCompleted : ! isCompleted } ) ;
25+ } ;
26+
1727 return (
1828 < div
1929 className = {
@@ -22,13 +32,22 @@ export default function CheckList({
2232 : styles . check_list_container
2333 }
2434 >
25- < Image
26- className = { styles . check_btn }
27- src = { isCompleted ? checkedIcon : notCheck }
28- width = { 32 }
29- height = { 32 }
30- alt = { isCompleted ? "완료" : "미완료" }
31- />
35+ < button
36+ type = "button"
37+ onClick = { onClickSetTask }
38+ disabled = { isLoading ? true : false }
39+ >
40+ { isLoading ? (
41+ < Spinner />
42+ ) : (
43+ < Image
44+ src = { isCompleted ? checkedIcon : notCheck }
45+ width = { 32 }
46+ height = { 32 }
47+ alt = { isCompleted ? "완료" : "미완료" }
48+ />
49+ ) }
50+ </ button >
3251 < p > { name } </ p >
3352 </ div >
3453 ) ;
0 commit comments