Added animations to task list
This commit is contained in:
parent
3a8411af91
commit
67b2dcc051
@ -19,7 +19,8 @@
|
|||||||
"@reduxjs/toolkit": "^1.6.2",
|
"@reduxjs/toolkit": "^1.6.2",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^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"
|
"private": "true"
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@ import InboxIcon from "@mui/icons-material/Inbox";
|
|||||||
export const EmptyList: React.FC = () => (
|
export const EmptyList: React.FC = () => (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
padding: (theme) => theme.spacing(1),
|
paddingBottom: (theme) => theme.spacing(2),
|
||||||
paddingBottom: (theme) => theme.spacing(3),
|
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -1,26 +1,43 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
import List from "@mui/material/List";
|
import List from "@mui/material/List";
|
||||||
import Paper from "@mui/material/Paper";
|
import Paper from "@mui/material/Paper";
|
||||||
|
import Collapse from "@mui/material/Collapse";
|
||||||
|
|
||||||
|
import { TransitionGroup } from "react-transition-group";
|
||||||
|
|
||||||
import { TodoItem } from "./TodoItem";
|
import { TodoItem } from "./TodoItem";
|
||||||
import { useAppSelector } from "../hooks";
|
import { useAppSelector } from "../hooks";
|
||||||
import { EmptyList } from "./EmptyList";
|
import { EmptyList } from "./EmptyList";
|
||||||
|
import { isTaskItem, TaskItemT } from "../types";
|
||||||
|
|
||||||
export const TodoList: React.FC = () => {
|
export const TodoList: React.FC = () => {
|
||||||
const tasks = useAppSelector((state) => state.todo.tasks);
|
const tasks = useAppSelector((state) => state.todo.tasks);
|
||||||
|
|
||||||
|
const [list, setList] = useState<TaskItemT[] | {}[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (tasks.length) setList(tasks);
|
||||||
|
else setList([{}]);
|
||||||
|
}, [tasks]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper variant="outlined">
|
<Paper variant="outlined">
|
||||||
{tasks.length ? (
|
|
||||||
<List>
|
<List>
|
||||||
{tasks.map((task, index) => (
|
<TransitionGroup>
|
||||||
<TodoItem key={task.id} task={task} index={index} />
|
{list.map((task, index) =>
|
||||||
))}
|
isTaskItem(task) ? (
|
||||||
</List>
|
<Collapse key={task.id}>
|
||||||
|
<TodoItem task={task} index={index} />
|
||||||
|
</Collapse>
|
||||||
) : (
|
) : (
|
||||||
|
<Collapse key={"empty"}>
|
||||||
<EmptyList />
|
<EmptyList />
|
||||||
|
</Collapse>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
|
</TransitionGroup>
|
||||||
|
</List>
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -3,3 +3,7 @@ export type TaskItemT = {
|
|||||||
text: string;
|
text: string;
|
||||||
done: boolean;
|
done: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isTaskItem = (el: TaskItemT | {}): el is TaskItemT => {
|
||||||
|
return "id" in el && "text" in el && "done" in el;
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user