-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
325 lines (302 loc) · 13.4 KB
/
index.html
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Luxury Todo App</title>
<!-- React Development -->
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<!-- Babel -->
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Custom styles -->
<link rel="stylesheet" href="styles.css">
<style>
html, body {
margin: 0;
padding: 0;
min-height: 100vh;
background-color: var(--color-background);
color: var(--color-text);
transition: background-color 0.3s ease, color 0.3s ease;
}
.dark {
background-color: #1a1a1a;
color: #ffffff;
}
.todo-item {
transition: all 0.3s ease;
}
.todo-item:hover {
transform: translateX(5px);
}
.status-badge {
padding: 4px 8px;
border-radius: 12px;
font-size: 0.8rem;
}
.status-todo { background-color: #b76e79; }
.status-in-process { background-color: #9d8664; }
.status-completed {
background-color: #7c9a92;
text-decoration: line-through;
}
.tab {
padding: 8px 16px;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
}
.tab.active {
background-color: #b76e79;
color: white;
}
.icon-button {
cursor: pointer;
padding: 5px;
border-radius: 50%;
transition: all 0.2s ease;
position: relative;
}
.icon-button:hover {
transform: scale(1.1);
}
.tooltip {
visibility: hidden;
position: absolute;
background-color: #333;
color: white;
padding: 5px 10px;
border-radius: 6px;
font-size: 12px;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
opacity: 0;
transition: opacity 0.3s;
}
.icon-button:hover .tooltip {
visibility: visible;
opacity: 1;
}
.completing {
animation: complete 0.5s forwards;
}
@keyframes complete {
0% {
transform: scale(1);
}
100% {
transform: scale(0.9);
}
}
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const { useState, useEffect } = React;
const initialTodos = (() => {
try {
const saved = localStorage.getItem('todos');
return saved ? JSON.parse(saved) : [];
} catch (e) {
console.error('Error loading todos:', e);
return [];
}
})();
function App() {
const [todos, setTodos] = useState(initialTodos);
const [inputValue, setInputValue] = useState('');
const [filter, setFilter] = useState('all');
const [priority, setPriority] = useState('medium');
const [darkMode, setDarkMode] = useState(false);
useEffect(() => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
setDarkMode(true);
document.documentElement.setAttribute('data-theme', 'dark');
} else {
document.documentElement.setAttribute('data-theme', 'light');
}
}, []);
useEffect(() => {
document.documentElement.setAttribute('data-theme', darkMode ? 'dark' : 'light');
localStorage.setItem('theme', darkMode ? 'dark' : 'light');
localStorage.setItem('todos', JSON.stringify(todos));
}, [todos, darkMode]);
const addTodo = (e) => {
e.preventDefault();
if (!inputValue.trim()) return;
const newTodo = {
id: Date.now(),
text: inputValue,
status: 'todo',
priority: priority,
createdAt: new Date().toISOString()
};
setTodos([...todos, newTodo]);
setInputValue('');
};
const updateTodoStatus = (id, newStatus) => {
const todoIndex = todos.findIndex(todo => todo.id === id);
if (todoIndex === -1) return;
const todoElement = document.querySelector(`[data-todo-id="${id}"]`);
if (newStatus === 'completed') {
todoElement.classList.add('completing');
setTimeout(() => {
setTodos(prevTodos => {
const newTodos = [...prevTodos];
newTodos[todoIndex] = { ...newTodos[todoIndex], status: newStatus };
localStorage.setItem('todos', JSON.stringify(newTodos));
return newTodos;
});
}, 500);
} else {
setTodos(prevTodos => {
const newTodos = [...prevTodos];
newTodos[todoIndex] = { ...newTodos[todoIndex], status: newStatus };
localStorage.setItem('todos', JSON.stringify(newTodos));
return newTodos;
});
}
};
const deleteTodo = (id) => {
setTodos(todos.filter(todo => todo.id !== id));
};
const getStatusIcon = (status) => {
switch(status) {
case 'todo':
return <i className="fas fa-circle text-gray-400"></i>;
case 'in-process':
return <i className="fas fa-spinner fa-spin text-yellow-500"></i>;
case 'completed':
return <i className="fas fa-check-circle text-green-500"></i>;
default:
return null;
}
};
const filteredTodos = todos
.filter(todo => filter === 'all' ? true : todo.status === filter)
.sort((a, b) => {
const statusOrder = {
'in-process': 0,
'todo': 1,
'completed': 2
};
return statusOrder[a.status] - statusOrder[b.status];
})
.sort((a, b) => {
const priorityOrder = { high: 1, medium: 2, low: 3 };
return priorityOrder[a.priority] - priorityOrder[b.priority];
});
return (
<div className="container mx-auto px-4 py-8 max-w-2xl">
<div className="flex justify-between items-center mb-8">
<h1 className="text-3xl font-bold">Luxury Todo App</h1>
<button
className="icon-button"
onClick={() => setDarkMode(!darkMode)}
>
<i className={`fas fa-${darkMode ? 'sun' : 'moon'} text-xl`}></i>
<span className="tooltip">Toggle {darkMode ? 'Light' : 'Dark'} Mode</span>
</button>
</div>
<form onSubmit={addTodo} className="todo-form">
<div className="flex flex-wrap gap-4">
<input
type="text"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder="Add a new task..."
className="flex-1 p-2 border rounded dark:bg-gray-700 dark:border-gray-600"
/>
<select
value={priority}
onChange={(e) => setPriority(e.target.value)}
className="p-2 border rounded dark:bg-gray-700 dark:border-gray-600"
>
<option value="high">High</option>
<option value="medium">Medium</option>
<option value="low">Low</option>
</select>
<button
type="submit"
className="icon-button bg-rose-500 text-white px-4 py-2 rounded hover:bg-rose-600"
>
<i className="fas fa-plus"></i>
<span className="tooltip">Add Task</span>
</button>
</div>
</form>
<div className="flex gap-4 mb-6">
{['all', 'todo', 'in-process', 'completed'].map(tab => (
<button
key={tab}
onClick={() => setFilter(tab)}
className={`tab ${filter === tab ? 'active' : ''}`}
>
{tab === 'all' ? 'All' : tab.charAt(0).toUpperCase() + tab.slice(1)}
</button>
))}
</div>
<div className="space-y-4">
{filteredTodos.map(todo => (
<div key={todo.id}
data-todo-id={todo.id}
className={`todo-item ${todo.status} p-4 rounded-lg flex justify-between items-center`}>
<div className="flex-1">
<p className="text-lg font-medium mb-2">{todo.text}</p>
<div className="todo-metadata text-sm">
<span className="status-badge mr-2">{todo.status}</span>
<span className="priority-badge">{todo.priority} priority</span>
</div>
</div>
<div className="flex items-center">
{todo.status !== 'completed' && (
<button
onClick={() => updateTodoStatus(todo.id, 'completed')}
className="status-button complete-button"
title="Mark as Completed">
<i className="fas fa-check"></i>
</button>
)}
{todo.status !== 'in-process' && (
<button
onClick={() => updateTodoStatus(todo.id, 'in-process')}
className="status-button process-button"
title="Mark as In Process">
<i className="fas fa-spinner"></i>
</button>
)}
<select
value={todo.priority}
onChange={(e) => updateTodoPriority(todo.id, e.target.value)}
className="ml-2 p-2 rounded-md">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
<button
onClick={() => deleteTodo(todo.id)}
className="delete-button"
title="Delete Task">
<i className="fas fa-trash-alt"></i>
</button>
</div>
</div>
))}
</div>
</div>
);
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
</script>
</body>
</html>