-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
602 lines (516 loc) · 20.9 KB
/
Copy pathindex.html
File metadata and controls
602 lines (516 loc) · 20.9 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Daily Energy To-Do</title>
<style>
/* Basic Reset & Font */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f4f7f6;
color: #333;
line-height: 1.6;
padding: 20px;
display: flex;
justify-content: center;
align-items: flex-start; /* Align items to the top */
min-height: 100vh;
}
.container {
background-color: #ffffff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 700px;
}
h1 {
text-align: center;
color: #2c3e50;
margin-bottom: 25px;
font-weight: 600;
}
/* Input Area */
.input-area {
display: flex;
flex-wrap: wrap; /* Allow wrapping */
gap: 10px;
margin-bottom: 15px; /* Reduced margin */
padding-bottom: 20px;
border-bottom: 1px solid #eee;
align-items: center; /* Align items vertically */
}
#task-input {
flex: 1 1 250px; /* Grow, shrink, basis */
padding: 12px 15px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1rem;
}
.input-options-container {
display: flex;
flex-wrap: wrap;
gap: 15px;
align-items: center;
flex: 1 1 auto; /* Allow options to take space */
justify-content: space-between; /* Space out groups */
}
.input-group {
display: flex;
flex-direction: column; /* Stack label and input/radios */
gap: 5px;
}
.input-group span { /* Label for the group */
font-size: 0.85rem;
color: #555;
font-weight: 500;
margin-bottom: 3px;
}
.input-group label { /* Radio/checkbox labels */
display: flex;
align-items: center;
gap: 5px;
cursor: pointer;
font-size: 0.9rem;
color: #555;
}
.input-group input[type="radio"] {
margin-right: 3px;
accent-color: #3498db; /* Modern look for radio */
}
#task-minutes {
padding: 8px 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 0.9rem;
width: 80px; /* Fixed width for minutes */
}
#add-task-btn {
padding: 12px 20px;
background-color: #3498db;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: 500;
transition: background-color 0.2s ease;
white-space: nowrap; /* Prevent button text wrapping */
flex-shrink: 0; /* Prevent button from shrinking too much */
margin-top: 10px; /* Add space when wrapped */
}
@media (min-width: 650px) { /* Adjust breakpoint as needed */
#add-task-btn {
margin-top: 0; /* No top margin on wider screens */
}
}
#add-task-btn:hover {
background-color: #2980b9;
}
/* Total Minutes Display */
#total-minutes-display {
text-align: center;
font-size: 1.1rem;
font-weight: 600;
color: #34495e;
margin: 0 0 25px 0; /* Margin below */
padding: 10px;
background-color: #ecf0f1;
border-radius: 5px;
}
/* Task Sections */
.task-section {
margin-bottom: 30px;
}
.task-section h2 {
color: #34495e;
margin-bottom: 15px;
padding-bottom: 5px;
border-bottom: 2px solid #3498db;
font-weight: 600;
font-size: 1.3rem;
}
.task-list {
list-style: none;
padding: 0;
}
.task-list h3 {
font-size: 0.95rem;
color: #7f8c8d;
margin-top: 15px;
margin-bottom: 8px;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.task-list h3:first-child {
margin-top: 0;
}
.task-item {
background-color: #fdfdfd;
border: 1px solid #eee;
padding: 10px 15px;
margin-bottom: 10px;
border-radius: 5px;
display: flex;
justify-content: space-between;
align-items: center;
transition: background-color 0.2s ease, opacity 0.3s ease;
word-break: break-word; /* Prevent long text overflow */
gap: 10px; /* Add gap between text/minutes and actions */
}
.task-item:hover {
background-color: #f9f9f9;
}
.task-item.high-energy {
border-left: 4px solid #e67e22; /* Orange for high energy */
}
.task-item.low-energy {
border-left: 4px solid #3498db; /* Blue for low energy */
}
.task-content { /* Group text and minutes */
flex-grow: 1;
margin-right: 10px;
cursor: pointer; /* Indicate it's clickable for completion */
display: flex; /* Use flex to align text and minutes */
flex-direction: column; /* Stack text and minutes vertically */
}
.task-text {
/* Main task text styling */
}
.task-minutes-display {
font-size: 0.8rem;
color: #888;
margin-top: 2px;
}
.task-item.completed .task-content { /* Apply style to group */
text-decoration: line-through;
color: #95a5a6;
}
.task-item.completed .task-minutes-display {
color: #b0b8b9; /* Lighter gray when completed */
}
.task-item.completed {
opacity: 0.7;
background-color: #f0f0f0;
}
.task-actions {
flex-shrink: 0; /* Prevent actions from shrinking */
display: flex;
gap: 5px;
}
.task-actions button {
background: none;
border: none;
cursor: pointer;
font-size: 1.1rem;
padding: 5px;
color: #7f8c8d;
transition: color 0.2s ease;
}
.task-actions .delete-btn {
color: #e74c3c;
}
.task-actions .delete-btn:hover {
color: #c0392b;
}
/* Message for empty lists */
.empty-list-message {
color: #95a5a6;
font-style: italic;
text-align: center;
padding: 15px 0;
font-size: 0.9rem;
}
/* Responsive Adjustments */
@media (max-width: 700px) {
.input-area {
flex-direction: column;
align-items: stretch; /* Make items full width */
}
.input-options-container {
justify-content: space-around; /* Even spacing */
margin-top: 10px;
width: 100%;
}
#add-task-btn {
width: 100%;
margin-top: 15px;
}
}
@media (max-width: 480px) {
.task-item {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.task-actions {
width: 100%;
justify-content: flex-end; /* Align buttons to the right */
margin-top: 5px;
}
.task-content {
margin-right: 0;
width: 100%; /* Take full width */
}
}
</style>
</head>
<body>
<div class="container">
<h1>Daily Energy To-Do</h1>
<!-- Input Area -->
<div class="input-area">
<input type="text" id="task-input" placeholder="Enter new task...">
<div class="input-options-container">
<div class="input-group">
<span>Energy</span>
<div>
<label><input type="radio" name="energy" value="high" checked> High</label>
<label><input type="radio" name="energy" value="low"> Low</label>
</div>
</div>
<div class="input-group">
<span>Due</span>
<div>
<label><input type="radio" name="due" value="today" checked> Today</label>
<label><input type="radio" name="due" value="upcoming"> Upcoming</label>
</div>
</div>
<div class="input-group">
<span>Minutes</span>
<input type="number" id="task-minutes" placeholder="Mins" min="1" step="1">
</div>
</div>
<button id="add-task-btn">Add Task</button>
</div>
<!-- Total Minutes Display Area -->
<div id="total-minutes-display">Estimated time: 0 minutes</div>
<!-- Task Display Area -->
<div class="task-sections">
<div class="task-section" id="due-today-section">
<h2>Due Today</h2>
<ul class="task-list" id="due-today-list">
<!-- Tasks will be injected here by JS -->
</ul>
</div>
<div class="task-section" id="upcoming-section">
<h2>Upcoming</h2>
<ul class="task-list" id="upcoming-list">
<!-- Tasks will be injected here by JS -->
</ul>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const taskInput = document.getElementById('task-input');
const minutesInput = document.getElementById('task-minutes');
const addTaskBtn = document.getElementById('add-task-btn');
const dueTodayList = document.getElementById('due-today-list');
const upcomingList = document.getElementById('upcoming-list');
const totalMinutesDisplay = document.getElementById('total-minutes-display');
let tasks = loadTasks();
// --- Event Listeners ---
addTaskBtn.addEventListener('click', addTask);
taskInput.addEventListener('keypress', handleInputKeypress);
minutesInput.addEventListener('keypress', handleInputKeypress); // Add Enter listener to minutes too
// Use event delegation for task actions (complete/delete)
dueTodayList.addEventListener('click', handleTaskAction);
upcomingList.addEventListener('click', handleTaskAction);
// --- Core Functions ---
function handleInputKeypress(e) {
if (e.key === 'Enter') {
addTask();
}
}
function addTask() {
const taskText = taskInput.value.trim();
const minutesValue = parseInt(minutesInput.value, 10);
if (taskText === '') {
alert('Please enter a task description.');
taskInput.focus();
return;
}
if (isNaN(minutesValue) || minutesValue <= 0) {
alert('Please enter a valid number of minutes (greater than 0).');
minutesInput.focus();
return;
}
const energy = document.querySelector('input[name="energy"]:checked').value;
const due = document.querySelector('input[name="due"]:checked').value;
const newTask = {
id: Date.now(), // Simple unique ID
text: taskText,
minutes: minutesValue, // Add minutes
energy: energy, // 'high' or 'low'
due: due, // 'today' or 'upcoming'
completed: false
};
tasks.push(newTask);
saveTasks();
renderTasks();
// Reset input
taskInput.value = '';
minutesInput.value = ''; // Clear minutes input
document.querySelector('input[name="energy"][value="high"]').checked = true; // Default back to high
document.querySelector('input[name="due"][value="today"]').checked = true; // Default back to today
taskInput.focus();
}
function handleTaskAction(event) {
const target = event.target;
const taskItem = target.closest('.task-item');
if (!taskItem) return; // Clicked outside a task item
const taskId = Number(taskItem.dataset.id);
// Check if the click was on the delete button
if (target.classList.contains('delete-btn') || target.closest('.delete-btn')) {
deleteTask(taskId);
}
// Check if the click was on the task content area (for toggling complete)
else if (target.classList.contains('task-content') || target.closest('.task-content')) {
toggleComplete(taskId);
}
}
function toggleComplete(taskId) {
tasks = tasks.map(task => {
if (task.id === taskId) {
return { ...task, completed: !task.completed };
}
return task;
});
saveTasks();
renderTasks(); // Re-render to update style and total minutes
}
function deleteTask(taskId) {
if (confirm('Are you sure you want to delete this task?')) {
tasks = tasks.filter(task => task.id !== taskId);
saveTasks();
renderTasks(); // Re-render to remove item and update total minutes
}
}
function renderTasks() {
// Clear current lists
dueTodayList.innerHTML = '';
upcomingList.innerHTML = '';
// Filter tasks
const todayTasks = tasks.filter(task => task.due === 'today');
const upcomingTasks = tasks.filter(task => task.due === 'upcoming');
// Sort tasks: High energy first, then Low energy
const sortTasks = (a, b) => {
if (a.energy === 'high' && b.energy === 'low') return -1;
if (a.energy === 'low' && b.energy === 'high') return 1;
// Optional secondary sort (e.g., by ID/time added) if energies are the same
// return a.id - b.id;
return 0;
};
todayTasks.sort(sortTasks);
upcomingTasks.sort(sortTasks);
// Render lists
renderList(todayTasks, dueTodayList);
renderList(upcomingTasks, upcomingList);
// Add messages if lists are empty
addEmptyMessageIfNeeded(dueTodayList, 'No tasks due today!');
addEmptyMessageIfNeeded(upcomingList, 'No upcoming tasks.');
// Update the total minutes display
updateTotalMinutesDisplay();
}
function renderList(taskListData, listElement) {
// Separate high and low energy for subheading structure
const highEnergyTasks = taskListData.filter(t => t.energy === 'high');
const lowEnergyTasks = taskListData.filter(t => t.energy === 'low');
if (highEnergyTasks.length > 0) {
const heading = document.createElement('h3');
heading.textContent = 'High Energy';
listElement.appendChild(heading);
highEnergyTasks.forEach(task => listElement.appendChild(createTaskElement(task)));
}
if (lowEnergyTasks.length > 0) {
const heading = document.createElement('h3');
heading.textContent = 'Low Energy';
listElement.appendChild(heading);
lowEnergyTasks.forEach(task => listElement.appendChild(createTaskElement(task)));
}
}
function createTaskElement(task) {
const li = document.createElement('li');
li.classList.add('task-item', `${task.energy}-energy`);
li.dataset.id = task.id; // Store ID for later retrieval
if (task.completed) {
li.classList.add('completed');
}
// Container for text and minutes
const contentDiv = document.createElement('div');
contentDiv.classList.add('task-content');
const textSpan = document.createElement('span');
textSpan.classList.add('task-text');
textSpan.textContent = task.text;
const minutesSpan = document.createElement('span');
minutesSpan.classList.add('task-minutes-display');
// Handle cases where minutes might be missing (e.g., older saved tasks)
minutesSpan.textContent = `${task.minutes || '?'} min`;
contentDiv.appendChild(textSpan);
contentDiv.appendChild(minutesSpan);
// Action buttons
const actionsDiv = document.createElement('div');
actionsDiv.classList.add('task-actions');
const deleteBtn = document.createElement('button');
deleteBtn.innerHTML = '✖'; // Cross mark (X)
deleteBtn.title = "Delete Task";
deleteBtn.classList.add('delete-btn');
actionsDiv.appendChild(deleteBtn);
li.appendChild(contentDiv); // Add content group
li.appendChild(actionsDiv); // Add actions
return li;
}
function addEmptyMessageIfNeeded(listElement, message) {
// Check if list has actual task items, not just headings
const hasTasks = Array.from(listElement.children).some(child => child.tagName === 'LI' && !child.classList.contains('empty-list-message'));
if (!hasTasks) {
// Remove any existing empty message first
const existingMsg = listElement.querySelector('.empty-list-message');
if (existingMsg) existingMsg.remove();
const li = document.createElement('li');
li.textContent = message;
li.classList.add('empty-list-message');
listElement.appendChild(li);
} else {
// If tasks exist, ensure no empty message is shown
const existingMsg = listElement.querySelector('.empty-list-message');
if (existingMsg) existingMsg.remove();
}
}
function updateTotalMinutesDisplay() {
const totalMinutes = tasks.reduce((sum, task) => {
// Only add minutes from incomplete tasks
// Use || 0 to handle tasks saved before minutes were added
return sum + (!task.completed ? (parseInt(task.minutes || 0, 10)) : 0);
}, 0);
totalMinutesDisplay.textContent = `Estimated time for incomplete tasks: ${totalMinutes} minutes`;
}
// --- Local Storage ---
function saveTasks() {
localStorage.setItem('dailyEnergyTasks', JSON.stringify(tasks));
}
function loadTasks() {
const storedTasks = localStorage.getItem('dailyEnergyTasks');
// Basic check if storedTasks is valid JSON array
try {
const parsedTasks = JSON.parse(storedTasks);
return Array.isArray(parsedTasks) ? parsedTasks : [];
} catch (e) {
console.error("Error parsing tasks from localStorage", e);
return []; // Return empty array on error
}
}
// --- Initial Render ---
renderTasks(); // Render existing tasks and calculate initial total
});
</script>
</body>
</html>