@@ -15,75 +15,82 @@ const numberOfTodos = (no_of_todos) => {
15
15
export default function Footer ( ) {
16
16
17
17
const [ status , setStatus ] = useState ( "All" ) ;
18
+ const [ colors , setColors ] = useState ( [ ] ) ;
18
19
19
- const { data :todos , isSuccess} = useGetTodosQuery ( status ) ;
20
+ const { data :todos , isSuccess} = useGetTodosQuery ( { status : status , colors : colors } ) ;
20
21
21
22
// const filters = useSelector((state) => state.filters);
22
23
23
24
const todosRemaining = isSuccess && todos . filter ( ( todo ) => ! todo . completed ) . length ;
24
25
// const { status, colors } = filters;
25
26
26
27
const handleStatusChange = ( statusName ) => {
28
+ console . log ( statusName ) ;
27
29
setStatus ( statusName ) ;
28
30
} ;
29
31
30
- // const handleColorChange = (color) => {
31
- // if (colors.includes(color)) {
32
- // dispatch(colorChanged(color, "removed"));
33
- // } else {
34
- // dispatch(colorChanged(color, "added"));
35
- // }
36
- // };
32
+ const handleColorChange = ( color ) => {
33
+ if ( colors . includes ( color ) ) {
34
+ // remove color
35
+ setColors ( ( ) => {
36
+ return [ ...colors ] . filter ( existingColor => existingColor !== color )
37
+ } )
38
+ } else {
39
+ // add color...
40
+ const newColors = [ ...colors , color ] ;
41
+ setColors ( newColors ) ;
42
+ }
43
+ } ;
37
44
38
45
return (
39
46
< div className = "mt-4 flex justify-between text-xs text-gray-500" >
40
47
< p > { numberOfTodos ( todosRemaining ) } left</ p >
41
48
< ul className = "flex space-x-1 items-center text-xs" >
42
49
< li
43
- // className={`cursor-pointer ${
44
- // status === "All" && "font-bold"
45
- // }` }
50
+ className = { `cursor-pointer ${
51
+ status === "All" && "font-bold"
52
+ } `}
46
53
onClick = { ( ) => handleStatusChange ( "All" ) }
47
54
>
48
55
All
49
56
</ li >
50
57
< li > |</ li >
51
58
< li
52
- // className={`cursor-pointer ${
53
- // status === "Incomplete" && "font-bold"
54
- // }` }
59
+ className = { `cursor-pointer ${
60
+ status === "Incomplete" && "font-bold"
61
+ } `}
55
62
onClick = { ( ) => handleStatusChange ( "Incomplete" ) }
56
63
>
57
64
Incomplete
58
65
</ li >
59
66
< li > |</ li >
60
67
< li
61
- // className={`cursor-pointer ${
62
- // status === "Complete" && "font-bold"
63
- // }` }
68
+ className = { `cursor-pointer ${
69
+ status === "Complete" && "font-bold"
70
+ } `}
64
71
onClick = { ( ) => handleStatusChange ( "Complete" ) }
65
72
>
66
73
Complete
67
74
</ li >
68
75
< li > </ li >
69
76
< li > </ li >
70
77
< li
71
- // className={`h-3 w-3 border-2 border-green-500 md:hover:bg-green-500 rounded-full cursor-pointer ${
72
- // colors.includes("green") && "bg-green-500"
73
- // }` }
74
- // onClick={() => handleColorChange("green")}
78
+ className = { `h-3 w-3 border-2 border-green-500 md:hover:bg-green-500 rounded-full cursor-pointer ${
79
+ colors . includes ( "green" ) && "bg-green-500"
80
+ } `}
81
+ onClick = { ( ) => handleColorChange ( "green" ) }
75
82
> </ li >
76
83
< li
77
- // className={`h-3 w-3 border-2 border-red-500 md:hover:bg-red-500 rounded-full cursor-pointer ${
78
- // colors.includes("red") && "bg-red-500"
79
- // }` }
80
- // onClick={() => handleColorChange("red")}
84
+ className = { `h-3 w-3 border-2 border-red-500 md:hover:bg-red-500 rounded-full cursor-pointer ${
85
+ colors . includes ( "red" ) && "bg-red-500"
86
+ } `}
87
+ onClick = { ( ) => handleColorChange ( "red" ) }
81
88
> </ li >
82
89
< li
83
- // className={`h-3 w-3 border-2 border-yellow-500 md:hover:bg-yellow-500 rounded-full cursor-pointer ${
84
- // colors.includes("yellow") && "bg-yellow-500"
85
- // }` }
86
- // onClick={() => handleColorChange("yellow")}
90
+ className = { `h-3 w-3 border-2 border-yellow-500 md:hover:bg-yellow-500 rounded-full cursor-pointer ${
91
+ colors . includes ( "yellow" ) && "bg-yellow-500"
92
+ } `}
93
+ onClick = { ( ) => handleColorChange ( "yellow" ) }
87
94
> </ li >
88
95
</ ul >
89
96
</ div >
0 commit comments