diff --git a/src/App.tsx b/src/App.tsx index fdea363f..4631ceb3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import CssBaseline from "@mui/material/CssBaseline"; import Typography from "@mui/material/Typography"; import Box from "@mui/material/Box"; import CrmDashboard from "./crm/CrmDashboard"; +import TodoApp from "./todo/TodoApp"; function NotFound() { return ( @@ -31,7 +32,8 @@ export default function App() { - } /> + } /> + } /> } /> diff --git a/src/todo/TodoApp.tsx b/src/todo/TodoApp.tsx new file mode 100644 index 00000000..3c429b1e --- /dev/null +++ b/src/todo/TodoApp.tsx @@ -0,0 +1,194 @@ +import * as React from 'react'; +import { + Box, + Container, + Paper, + TextField, + Button, + List, + ListItem, + ListItemText, + ListItemSecondaryAction, + IconButton, + Checkbox, + Typography, + Chip, + Stack, +} from '@mui/material'; +import DeleteIcon from '@mui/icons-material/Delete'; +import AddIcon from '@mui/icons-material/Add'; +import { AppTheme } from '../shared-theme/AppTheme'; + +interface Todo { + id: number; + text: string; + completed: boolean; +} + +type FilterType = 'all' | 'active' | 'completed'; + +function TodoAppContent() { + const [todos, setTodos] = React.useState([]); + const [inputValue, setInputValue] = React.useState(''); + const [filter, setFilter] = React.useState('all'); + + const handleAddTodo = () => { + if (inputValue.trim()) { + const newTodo: Todo = { + id: Date.now(), + text: inputValue.trim(), + completed: false, + }; + setTodos([...todos, newTodo]); + setInputValue(''); + } + }; + + const handleToggleTodo = (id: number) => { + setTodos( + todos.map((todo) => + todo.id === id ? { ...todo, completed: !todo.completed } : todo + ) + ); + }; + + const handleDeleteTodo = (id: number) => { + setTodos(todos.filter((todo) => todo.id !== id)); + }; + + const handleKeyPress = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + handleAddTodo(); + } + }; + + const filteredTodos = todos.filter((todo) => { + if (filter === 'active') return !todo.completed; + if (filter === 'completed') return todo.completed; + return true; + }); + + const activeTodosCount = todos.filter((todo) => !todo.completed).length; + + return ( + + + + Todo App + + + + setInputValue(e.target.value)} + onKeyPress={handleKeyPress} + size="medium" + /> + + + + + setFilter('all')} + color={filter === 'all' ? 'primary' : 'default'} + variant={filter === 'all' ? 'filled' : 'outlined'} + /> + setFilter('active')} + color={filter === 'active' ? 'primary' : 'default'} + variant={filter === 'active' ? 'filled' : 'outlined'} + /> + setFilter('completed')} + color={filter === 'completed' ? 'primary' : 'default'} + variant={filter === 'completed' ? 'filled' : 'outlined'} + /> + + + {filteredTodos.length === 0 ? ( + + + {filter === 'completed' && todos.length > 0 + ? 'No completed tasks yet' + : filter === 'active' && todos.length > 0 + ? 'No active tasks' + : 'No tasks yet. Add one above!'} + + + ) : ( + + {filteredTodos.map((todo) => ( + + handleToggleTodo(todo.id)} + color="primary" + /> + + + handleDeleteTodo(todo.id)} + color="error" + > + + + + + ))} + + )} + + {todos.length > 0 && ( + + + {activeTodosCount} {activeTodosCount === 1 ? 'task' : 'tasks'} remaining + + + )} + + + ); +} + +export default function TodoApp() { + return ( + + + + ); +}