-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
63 lines (56 loc) · 1.89 KB
/
Copy pathApp.tsx
File metadata and controls
63 lines (56 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react';
import { Todo } from './types';
import useLocalStorage from './hooks/useLocalStorage';
import Header from './components/Header';
import TodoForm from './components/TodoForm';
import TodoItem from './components/TodoItem';
const App: React.FC = () => {
const [todos, setTodos] = useLocalStorage<Todo[]>('todos', []);
const addTodo = (text: string) => {
const newTodo: Todo = {
id: crypto.randomUUID(),
text,
completed: false,
};
setTodos([newTodo, ...todos]);
};
const toggleTodo = (id: string) => {
setTodos(
todos.map((todo) =>
todo.id === id ? { ...todo, completed: !todo.completed } : todo
)
);
};
const deleteTodo = (id: string) => {
setTodos(todos.filter((todo) => todo.id !== id));
};
return (
<div className="min-h-screen bg-slate-900 bg-gradient-to-br from-indigo-900/50 via-slate-900 to-purple-900/50 text-white antialiased overflow-x-hidden">
<main className="container mx-auto max-w-2xl px-4 py-8">
<Header />
<TodoForm addTodo={addTodo} />
<div className="space-y-4">
{todos.length > 0 ? (
todos.map((todo) => (
<TodoItem
key={todo.id}
todo={todo}
toggleTodo={toggleTodo}
deleteTodo={deleteTodo}
/>
))
) : (
<div className="text-center py-16 px-6 bg-slate-800/20 rounded-xl border border-dashed border-slate-700">
<p className="text-xl text-slate-400">Your cosmic journey is clear.</p>
<p className="text-slate-500 mt-2">Add a task to begin your next adventure!</p>
</div>
)}
</div>
</main>
<footer className="text-center py-6 text-slate-500 text-sm">
<p>Crafted in a forgotten dimension.</p>
</footer>
</div>
);
};
export default App;