-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManager.tsx
More file actions
335 lines (309 loc) · 13.1 KB
/
Copy pathTaskManager.tsx
File metadata and controls
335 lines (309 loc) · 13.1 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
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
326
327
328
329
330
331
332
333
334
335
import React, { useState } from 'react'
import { useApp } from '../contexts/AppContext'
import { PlusIcon, CheckCircleIcon, CircleIcon, CalendarIcon, BatteryIcon } from 'lucide-react'
const TaskManager: React.FC = () => {
const { state, dispatch } = useApp()
const [showAddTask, setShowAddTask] = useState(false)
const [newTask, setNewTask] = useState({
title: '',
description: '',
priority: 'medium' as 'low' | 'medium' | 'high',
category: 'personal',
energyLevel: 5,
dueDate: ''
})
const handleAddTask = () => {
if (!newTask.title.trim()) return
const task = {
id: Date.now().toString(),
title: newTask.title,
description: newTask.description,
completed: false,
priority: newTask.priority,
category: newTask.category,
energyLevel: newTask.energyLevel,
dueDate: newTask.dueDate || undefined
}
dispatch({ type: 'ADD_TASK', payload: task })
dispatch({ type: 'UPDATE_TOKENS', payload: 5 })
setNewTask({
title: '',
description: '',
priority: 'medium',
category: 'personal',
energyLevel: 5,
dueDate: ''
})
setShowAddTask(false)
}
const handleToggleTask = (taskId: string) => {
dispatch({ type: 'TOGGLE_TASK', payload: taskId })
dispatch({ type: 'UPDATE_TOKENS', payload: 15 })
}
const getPriorityColor = (priority: string) => {
switch (priority) {
case 'high': return 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200'
case 'medium': return 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200'
case 'low': return 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200'
default: return 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200'
}
}
const getCategoryColor = (category: string) => {
switch (category) {
case 'wellness': return 'bg-wellness-100 text-wellness-800 dark:bg-wellness-900 dark:text-wellness-200'
case 'work': return 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200'
case 'personal': return 'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200'
default: return 'bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200'
}
}
const completedTasks = state.tasks.filter(task => task.completed).length
const totalTasks = state.tasks.length
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold text-gray-900 dark:text-white">Task Manager</h1>
<p className="text-gray-600 dark:text-gray-400 mt-1">
Organize your tasks based on energy levels and wellness goals
</p>
</div>
<button
onClick={() => setShowAddTask(true)}
className="btn-primary flex items-center"
>
<PlusIcon className="w-4 h-4 mr-2" />
Add Task
</button>
</div>
{/* Progress Stats */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<div className="card">
<div className="flex items-center">
<div className="w-12 h-12 bg-green-100 dark:bg-green-900 rounded-lg flex items-center justify-center">
<CheckCircleIcon className="w-6 h-6 text-green-600 dark:text-green-400" />
</div>
<div className="ml-4">
<p className="text-sm font-medium text-gray-600 dark:text-gray-400">Completed Today</p>
<p className="text-2xl font-bold text-gray-900 dark:text-white">{completedTasks}</p>
</div>
</div>
</div>
<div className="card">
<div className="flex items-center">
<div className="w-12 h-12 bg-blue-100 dark:bg-blue-900 rounded-lg flex items-center justify-center">
<CircleIcon className="w-6 h-6 text-blue-600 dark:text-blue-400" />
</div>
<div className="ml-4">
<p className="text-sm font-medium text-gray-600 dark:text-gray-400">Total Tasks</p>
<p className="text-2xl font-bold text-gray-900 dark:text-white">{totalTasks}</p>
</div>
</div>
</div>
<div className="card">
<div className="flex items-center">
<div className="w-12 h-12 bg-purple-100 dark:bg-purple-900 rounded-lg flex items-center justify-center">
<BatteryIcon className="w-6 h-6 text-purple-600 dark:text-purple-400" />
</div>
<div className="ml-4">
<p className="text-sm font-medium text-gray-600 dark:text-gray-400">Completion Rate</p>
<p className="text-2xl font-bold text-gray-900 dark:text-white">
{totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0}%
</p>
</div>
</div>
</div>
</div>
{/* Add Task Modal */}
{showAddTask && (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50">
<div className="bg-white dark:bg-gray-800 rounded-xl p-6 w-full max-w-md">
<h3 className="text-xl font-bold text-gray-900 dark:text-white mb-4">
Add New Task
</h3>
<div className="space-y-4">
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Task Title
</label>
<input
type="text"
value={newTask.title}
onChange={(e) => setNewTask({ ...newTask, title: e.target.value })}
placeholder="What needs to be done?"
className="input-field"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Description (optional)
</label>
<textarea
value={newTask.description}
onChange={(e) => setNewTask({ ...newTask, description: e.target.value })}
placeholder="Add more details..."
className="input-field h-20 resize-none"
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Priority
</label>
<select
value={newTask.priority}
onChange={(e) => setNewTask({ ...newTask, priority: e.target.value as 'low' | 'medium' | 'high' })}
className="input-field"
>
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Category
</label>
<select
value={newTask.category}
onChange={(e) => setNewTask({ ...newTask, category: e.target.value })}
className="input-field"
>
<option value="personal">Personal</option>
<option value="work">Work</option>
<option value="wellness">Wellness</option>
</select>
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Energy Level Required: {newTask.energyLevel}/10
</label>
<input
type="range"
min="1"
max="10"
value={newTask.energyLevel}
onChange={(e) => setNewTask({ ...newTask, energyLevel: parseInt(e.target.value) })}
className="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Due Date (optional)
</label>
<input
type="date"
value={newTask.dueDate}
onChange={(e) => setNewTask({ ...newTask, dueDate: e.target.value })}
className="input-field"
/>
</div>
</div>
<div className="flex space-x-3 mt-6">
<button
onClick={handleAddTask}
className="btn-primary flex-1"
>
Add Task (+5 tokens)
</button>
<button
onClick={() => setShowAddTask(false)}
className="btn-secondary flex-1"
>
Cancel
</button>
</div>
</div>
</div>
)}
{/* Tasks List */}
<div className="card">
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">Your Tasks</h3>
<div className="space-y-3">
{state.tasks.length === 0 ? (
<div className="text-center py-8">
<CheckCircleIcon className="w-12 h-12 text-gray-400 mx-auto mb-4" />
<p className="text-gray-500 dark:text-gray-400">No tasks yet</p>
<p className="text-sm text-gray-400 dark:text-gray-500">
Add your first task to get started
</p>
</div>
) : (
state.tasks.map((task) => (
<div
key={task.id}
className={`border border-gray-200 dark:border-gray-700 rounded-lg p-4 transition-all duration-200 ${
task.completed ? 'bg-gray-50 dark:bg-gray-700/50' : 'bg-white dark:bg-gray-800'
}`}
>
<div className="flex items-start space-x-3">
<button
onClick={() => handleToggleTask(task.id)}
className={`mt-1 w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${
task.completed
? 'bg-green-500 border-green-500'
: 'border-gray-300 dark:border-gray-600 hover:border-green-500'
}`}
>
{task.completed && (
<CheckCircleIcon className="w-3 h-3 text-white" />
)}
</button>
<div className="flex-1">
<div className="flex items-center justify-between mb-2">
<h4 className={`font-medium ${
task.completed
? 'text-gray-500 dark:text-gray-400 line-through'
: 'text-gray-900 dark:text-white'
}`}>
{task.title}
</h4>
<div className="flex items-center space-x-2">
<span className={`px-2 py-1 text-xs rounded-full ${getPriorityColor(task.priority)}`}>
{task.priority}
</span>
<span className={`px-2 py-1 text-xs rounded-full ${getCategoryColor(task.category)}`}>
{task.category}
</span>
</div>
</div>
{task.description && (
<p className={`text-sm mb-2 ${
task.completed
? 'text-gray-400 dark:text-gray-500'
: 'text-gray-600 dark:text-gray-400'
}`}>
{task.description}
</p>
)}
<div className="flex items-center justify-between text-xs text-gray-500 dark:text-gray-400">
<div className="flex items-center space-x-4">
<div className="flex items-center space-x-1">
<BatteryIcon className="w-3 h-3" />
<span>Energy: {task.energyLevel}/10</span>
</div>
{task.dueDate && (
<div className="flex items-center space-x-1">
<CalendarIcon className="w-3 h-3" />
<span>{task.dueDate}</span>
</div>
)}
</div>
{task.completed && (
<span className="text-green-600 dark:text-green-400 font-medium">
+15 tokens earned
</span>
)}
</div>
</div>
</div>
</div>
))
)}
</div>
</div>
</div>
)
}
export default TaskManager