diff --git a/package.json b/package.json index df19e4a..f433acb 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "@reduxjs/toolkit": "^1.6.2", "react": "^17.0.2", "react-dom": "^17.0.2", - "react-redux": "^7.2.5" + "react-redux": "^7.2.5", + "react-transition-group": "^4.4.2" }, "private": "true" } diff --git a/src/components/EmptyList.tsx b/src/components/EmptyList.tsx index f93c8b5..5756294 100644 --- a/src/components/EmptyList.tsx +++ b/src/components/EmptyList.tsx @@ -7,8 +7,7 @@ import InboxIcon from "@mui/icons-material/Inbox"; export const EmptyList: React.FC = () => ( theme.spacing(1), - paddingBottom: (theme) => theme.spacing(3), + paddingBottom: (theme) => theme.spacing(2), textAlign: "center", }} > diff --git a/src/components/TodoList.tsx b/src/components/TodoList.tsx index d198178..c1e38e8 100644 --- a/src/components/TodoList.tsx +++ b/src/components/TodoList.tsx @@ -1,26 +1,43 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import List from "@mui/material/List"; import Paper from "@mui/material/Paper"; +import Collapse from "@mui/material/Collapse"; + +import { TransitionGroup } from "react-transition-group"; import { TodoItem } from "./TodoItem"; import { useAppSelector } from "../hooks"; import { EmptyList } from "./EmptyList"; +import { isTaskItem, TaskItemT } from "../types"; export const TodoList: React.FC = () => { const tasks = useAppSelector((state) => state.todo.tasks); + const [list, setList] = useState([]); + + useEffect(() => { + if (tasks.length) setList(tasks); + else setList([{}]); + }, [tasks]); + return ( - {tasks.length ? ( - - {tasks.map((task, index) => ( - - ))} - - ) : ( - - )} + + + {list.map((task, index) => + isTaskItem(task) ? ( + + + + ) : ( + + + + ) + )} + + ); }; diff --git a/src/types.ts b/src/types.ts index 05f36bd..4febd4c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,3 +3,7 @@ export type TaskItemT = { text: string; done: boolean; }; + +export const isTaskItem = (el: TaskItemT | {}): el is TaskItemT => { + return "id" in el && "text" in el && "done" in el; +};