diff --git a/src/components/TodoItem/TodoItem.tsx b/src/components/TodoItem/TodoItem.tsx index 0b688e8a4..194f675f5 100644 --- a/src/components/TodoItem/TodoItem.tsx +++ b/src/components/TodoItem/TodoItem.tsx @@ -15,9 +15,10 @@ import { DispatchContext } from '../../Store'; type Props = { todo: Todo; + nodeRef: React.RefObject; }; -export const TodoItem: React.FC = ({ todo }) => { +export const TodoItem: React.FC = ({ todo, nodeRef }) => { const dispatch = useContext(DispatchContext); const [title, setTitle] = useState(todo.title); @@ -89,6 +90,7 @@ export const TodoItem: React.FC = ({ todo }) => { return (
diff --git a/src/components/TodoList/TodoList.tsx b/src/components/TodoList/TodoList.tsx index 3740ab413..a56eec368 100644 --- a/src/components/TodoList/TodoList.tsx +++ b/src/components/TodoList/TodoList.tsx @@ -1,4 +1,6 @@ -import { useContext, useMemo } from 'react'; +import React, { useContext, useEffect, useMemo, useState } from 'react'; +// eslint-disable-next-line import/no-extraneous-dependencies +import { TransitionGroup, CSSTransition } from 'react-transition-group'; import { StateContext } from '../../Store'; @@ -6,26 +8,46 @@ import { TodoItem } from '../TodoItem/TodoItem'; import { Filter } from '../../types/Filter'; export const TodoList = () => { + const [first, setFirst] = useState(true); const { todos, filter } = useContext(StateContext); + useEffect(() => { + setFirst(false); + }, []); + const filteredTodos = useMemo(() => { + if (first) { + return []; + } + switch (filter) { case Filter.all: return todos; - case Filter.active: return todos.filter(todo => !todo.completed); - case Filter.completed: return todos.filter(todo => todo.completed); } - }, [filter, todos]); + }, [filter, todos, first]); return (
- {filteredTodos.map(todo => ( - - ))} + + {filteredTodos.map(todo => { + const nodeRef = React.createRef(); + + return ( + + + + ); + })} +
); }; diff --git a/src/styles/todo-list.scss b/src/styles/todo-list.scss index fd5f6aa10..fc631c41c 100644 --- a/src/styles/todo-list.scss +++ b/src/styles/todo-list.scss @@ -98,3 +98,23 @@ opacity: 0.5; } } + +.item-enter { + max-height: 0; + overflow: hidden; +} + +.item-enter-active { + max-height: 58px; + transition: max-height 0.5s linear; +} + +.item-exit { + max-height: 58px; + overflow: hidden; +} + +.item-exit-active { + max-height: 0; + transition: max-height 0.5s linear; +}