Spaces:
Running
Running
el Sort no funciona - Follow Up Deployment
Browse files- index.html +113 -22
index.html
CHANGED
|
@@ -58,18 +58,12 @@
|
|
| 58 |
}
|
| 59 |
|
| 60 |
.completed-task {
|
| 61 |
-
opacity: 0.
|
| 62 |
-
|
| 63 |
}
|
| 64 |
|
| 65 |
-
.
|
| 66 |
-
|
| 67 |
-
position: absolute;
|
| 68 |
-
top: 50%;
|
| 69 |
-
left: 10px;
|
| 70 |
-
right: 10px;
|
| 71 |
-
height: 1px;
|
| 72 |
-
background-color: #10B981;
|
| 73 |
}
|
| 74 |
</style>
|
| 75 |
</head>
|
|
@@ -154,12 +148,23 @@
|
|
| 154 |
<div class="flex justify-between items-center mb-6">
|
| 155 |
<h2 class="text-2xl font-bold text-gray-800">My Tasks</h2>
|
| 156 |
<div class="flex space-x-2">
|
| 157 |
-
<button class="px-4 py-2 rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50">
|
| 158 |
-
<i class="fas fa-filter mr-2"></i>
|
| 159 |
-
</button>
|
| 160 |
-
<button class="px-4 py-2 rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50">
|
| 161 |
-
<i class="fas fa-sort mr-2"></i>Sort
|
| 162 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
</div>
|
| 164 |
</div>
|
| 165 |
|
|
@@ -169,7 +174,7 @@
|
|
| 169 |
<div class="flex justify-between">
|
| 170 |
<div>
|
| 171 |
<p class="text-sm text-gray-500">Total Tasks</p>
|
| 172 |
-
<h3 class="text-2xl font-bold text-gray-800">
|
| 173 |
</div>
|
| 174 |
<div class="bg-blue-100 p-3 rounded-lg">
|
| 175 |
<i class="fas fa-tasks text-primary text-xl"></i>
|
|
@@ -181,7 +186,7 @@
|
|
| 181 |
<div class="flex justify-between">
|
| 182 |
<div>
|
| 183 |
<p class="text-sm text-gray-500">Completed</p>
|
| 184 |
-
<h3 class="text-2xl font-bold text-gray-800">
|
| 185 |
</div>
|
| 186 |
<div class="bg-green-100 p-3 rounded-lg">
|
| 187 |
<i class="fas fa-check-circle text-secondary text-xl"></i>
|
|
@@ -193,7 +198,7 @@
|
|
| 193 |
<div class="flex justify-between">
|
| 194 |
<div>
|
| 195 |
<p class="text-sm text-gray-500">Pending</p>
|
| 196 |
-
<h3 class="text-2xl font-bold text-gray-800">
|
| 197 |
</div>
|
| 198 |
<div class="bg-yellow-100 p-3 rounded-lg">
|
| 199 |
<i class="fas fa-exclamation-circle text-yellow-500 text-xl"></i>
|
|
@@ -346,7 +351,75 @@
|
|
| 346 |
document.addEventListener('DOMContentLoaded', () => {
|
| 347 |
renderTasks();
|
| 348 |
setupEventListeners();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
|
| 351 |
// Set up event listeners
|
| 352 |
function setupEventListeners() {
|
|
@@ -442,6 +515,7 @@
|
|
| 442 |
if (task) {
|
| 443 |
task.completed = !task.completed;
|
| 444 |
renderTasks();
|
|
|
|
| 445 |
|
| 446 |
// Show notification
|
| 447 |
const message = task.completed ? 'Task marked as completed!' : 'Task marked as pending!';
|
|
@@ -465,9 +539,26 @@
|
|
| 465 |
}
|
| 466 |
}
|
| 467 |
|
| 468 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
function renderTasks() {
|
| 470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
taskList.classList.add('hidden');
|
| 472 |
emptyState.classList.remove('hidden');
|
| 473 |
return;
|
|
@@ -479,7 +570,7 @@
|
|
| 479 |
taskList.innerHTML = '';
|
| 480 |
|
| 481 |
// Sort tasks: uncompleted first, then by priority (high to low)
|
| 482 |
-
const sortedTasks = [...
|
| 483 |
if (a.completed !== b.completed) {
|
| 484 |
return a.completed ? 1 : -1;
|
| 485 |
}
|
|
@@ -492,7 +583,7 @@
|
|
| 492 |
const taskCard = document.createElement('div');
|
| 493 |
taskCard.className = `task-card bg-white rounded-xl shadow-sm overflow-hidden ${task.completed ? 'completed-task' : ''}`;
|
| 494 |
taskCard.innerHTML = `
|
| 495 |
-
<div class="p-5 flex">
|
| 496 |
<div class="mr-4 mt-1">
|
| 497 |
<button onclick="toggleTaskCompletion(${task.id})" class="w-6 h-6 rounded-full border-2 flex items-center justify-center ${task.completed ? 'bg-secondary border-secondary' : 'border-gray-300'}">
|
| 498 |
${task.completed ? '<i class="fas fa-check text-white text-xs"></i>' : ''}
|
|
|
|
| 58 |
}
|
| 59 |
|
| 60 |
.completed-task {
|
| 61 |
+
opacity: 0.5;
|
| 62 |
+
background-color: #f8fafc;
|
| 63 |
}
|
| 64 |
|
| 65 |
+
.pending-task {
|
| 66 |
+
border-left: 4px solid #3B82F6;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
</style>
|
| 69 |
</head>
|
|
|
|
| 148 |
<div class="flex justify-between items-center mb-6">
|
| 149 |
<h2 class="text-2xl font-bold text-gray-800">My Tasks</h2>
|
| 150 |
<div class="flex space-x-2">
|
| 151 |
+
<button id="filterPending" class="px-4 py-2 rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50">
|
| 152 |
+
<i class="fas fa-filter mr-2"></i>Show Pending
|
|
|
|
|
|
|
|
|
|
| 153 |
</button>
|
| 154 |
+
<div class="relative">
|
| 155 |
+
<button id="sortButton" class="px-4 py-2 rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 flex items-center">
|
| 156 |
+
<i class="fas fa-sort mr-2"></i>Sort
|
| 157 |
+
<i class="fas fa-chevron-down ml-2 text-xs"></i>
|
| 158 |
+
</button>
|
| 159 |
+
<div id="sortDropdown" class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 hidden">
|
| 160 |
+
<div class="py-1">
|
| 161 |
+
<a href="#" class="sort-option block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-sort="date-asc">Date (Oldest First)</a>
|
| 162 |
+
<a href="#" class="sort-option block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-sort="date-desc">Date (Newest First)</a>
|
| 163 |
+
<a href="#" class="sort-option block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-sort="priority">Priority</a>
|
| 164 |
+
<a href="#" class="sort-option block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" data-sort="category">Category</a>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
</div>
|
| 169 |
</div>
|
| 170 |
|
|
|
|
| 174 |
<div class="flex justify-between">
|
| 175 |
<div>
|
| 176 |
<p class="text-sm text-gray-500">Total Tasks</p>
|
| 177 |
+
<h3 id="totalTasks" class="text-2xl font-bold text-gray-800">3</h3>
|
| 178 |
</div>
|
| 179 |
<div class="bg-blue-100 p-3 rounded-lg">
|
| 180 |
<i class="fas fa-tasks text-primary text-xl"></i>
|
|
|
|
| 186 |
<div class="flex justify-between">
|
| 187 |
<div>
|
| 188 |
<p class="text-sm text-gray-500">Completed</p>
|
| 189 |
+
<h3 id="completedTasks" class="text-2xl font-bold text-gray-800">1</h3>
|
| 190 |
</div>
|
| 191 |
<div class="bg-green-100 p-3 rounded-lg">
|
| 192 |
<i class="fas fa-check-circle text-secondary text-xl"></i>
|
|
|
|
| 198 |
<div class="flex justify-between">
|
| 199 |
<div>
|
| 200 |
<p class="text-sm text-gray-500">Pending</p>
|
| 201 |
+
<h3 id="pendingTasks" class="text-2xl font-bold text-gray-800">2</h3>
|
| 202 |
</div>
|
| 203 |
<div class="bg-yellow-100 p-3 rounded-lg">
|
| 204 |
<i class="fas fa-exclamation-circle text-yellow-500 text-xl"></i>
|
|
|
|
| 351 |
document.addEventListener('DOMContentLoaded', () => {
|
| 352 |
renderTasks();
|
| 353 |
setupEventListeners();
|
| 354 |
+
|
| 355 |
+
// Add filter event listener
|
| 356 |
+
document.getElementById('filterPending').addEventListener('click', () => {
|
| 357 |
+
const filteredTasks = tasks.filter(task => !task.completed);
|
| 358 |
+
renderFilteredTasks(filteredTasks);
|
| 359 |
+
});
|
| 360 |
+
|
| 361 |
+
// Sort functionality
|
| 362 |
+
const sortButton = document.getElementById('sortButton');
|
| 363 |
+
const sortDropdown = document.getElementById('sortDropdown');
|
| 364 |
+
|
| 365 |
+
sortButton.addEventListener('click', () => {
|
| 366 |
+
sortDropdown.classList.toggle('hidden');
|
| 367 |
+
});
|
| 368 |
+
|
| 369 |
+
// Close dropdown when clicking outside
|
| 370 |
+
document.addEventListener('click', (e) => {
|
| 371 |
+
if (!sortButton.contains(e.target) && !sortDropdown.contains(e.target)) {
|
| 372 |
+
sortDropdown.classList.add('hidden');
|
| 373 |
+
}
|
| 374 |
+
});
|
| 375 |
+
|
| 376 |
+
// Handle sort option selection
|
| 377 |
+
document.querySelectorAll('.sort-option').forEach(option => {
|
| 378 |
+
option.addEventListener('click', (e) => {
|
| 379 |
+
e.preventDefault();
|
| 380 |
+
const sortType = e.target.dataset.sort;
|
| 381 |
+
sortTasks(sortType);
|
| 382 |
+
sortDropdown.classList.add('hidden');
|
| 383 |
+
});
|
| 384 |
+
});
|
| 385 |
});
|
| 386 |
+
|
| 387 |
+
// Sort tasks based on selected criteria
|
| 388 |
+
function sortTasks(sortType) {
|
| 389 |
+
let sortedTasks = [...tasks];
|
| 390 |
+
|
| 391 |
+
switch(sortType) {
|
| 392 |
+
case 'date-asc':
|
| 393 |
+
sortedTasks.sort((a, b) => {
|
| 394 |
+
if (!a.dueDate && !b.dueDate) return 0;
|
| 395 |
+
if (!a.dueDate) return 1;
|
| 396 |
+
if (!b.dueDate) return -1;
|
| 397 |
+
return new Date(a.dueDate) - new Date(b.dueDate);
|
| 398 |
+
});
|
| 399 |
+
break;
|
| 400 |
+
|
| 401 |
+
case 'date-desc':
|
| 402 |
+
sortedTasks.sort((a, b) => {
|
| 403 |
+
if (!a.dueDate && !b.dueDate) return 0;
|
| 404 |
+
if (!a.dueDate) return 1;
|
| 405 |
+
if (!b.dueDate) return -1;
|
| 406 |
+
return new Date(b.dueDate) - new Date(a.dueDate);
|
| 407 |
+
});
|
| 408 |
+
break;
|
| 409 |
+
|
| 410 |
+
case 'priority':
|
| 411 |
+
const priorityOrder = { high: 3, medium: 2, low: 1 };
|
| 412 |
+
sortedTasks.sort((a, b) => priorityOrder[b.priority] - priorityOrder[a.priority]);
|
| 413 |
+
break;
|
| 414 |
+
|
| 415 |
+
case 'category':
|
| 416 |
+
sortedTasks.sort((a, b) => a.category.localeCompare(b.category));
|
| 417 |
+
break;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
renderFilteredTasks(sortedTasks);
|
| 421 |
+
showNotification(`Tasks sorted by ${sortType.replace('-', ' ')}`);
|
| 422 |
+
}
|
| 423 |
|
| 424 |
// Set up event listeners
|
| 425 |
function setupEventListeners() {
|
|
|
|
| 515 |
if (task) {
|
| 516 |
task.completed = !task.completed;
|
| 517 |
renderTasks();
|
| 518 |
+
updateStats();
|
| 519 |
|
| 520 |
// Show notification
|
| 521 |
const message = task.completed ? 'Task marked as completed!' : 'Task marked as pending!';
|
|
|
|
| 539 |
}
|
| 540 |
}
|
| 541 |
|
| 542 |
+
// Update stats counters
|
| 543 |
+
function updateStats() {
|
| 544 |
+
const totalTasks = tasks.length;
|
| 545 |
+
const completedTasks = tasks.filter(task => task.completed).length;
|
| 546 |
+
const pendingTasks = totalTasks - completedTasks;
|
| 547 |
+
|
| 548 |
+
document.getElementById('totalTasks').textContent = totalTasks;
|
| 549 |
+
document.getElementById('completedTasks').textContent = completedTasks;
|
| 550 |
+
document.getElementById('pendingTasks').textContent = pendingTasks;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
// Render all tasks
|
| 554 |
function renderTasks() {
|
| 555 |
+
renderFilteredTasks(tasks);
|
| 556 |
+
updateStats();
|
| 557 |
+
}
|
| 558 |
+
|
| 559 |
+
// Render filtered tasks
|
| 560 |
+
function renderFilteredTasks(filteredTasks) {
|
| 561 |
+
if (filteredTasks.length === 0) {
|
| 562 |
taskList.classList.add('hidden');
|
| 563 |
emptyState.classList.remove('hidden');
|
| 564 |
return;
|
|
|
|
| 570 |
taskList.innerHTML = '';
|
| 571 |
|
| 572 |
// Sort tasks: uncompleted first, then by priority (high to low)
|
| 573 |
+
const sortedTasks = [...filteredTasks].sort((a, b) => {
|
| 574 |
if (a.completed !== b.completed) {
|
| 575 |
return a.completed ? 1 : -1;
|
| 576 |
}
|
|
|
|
| 583 |
const taskCard = document.createElement('div');
|
| 584 |
taskCard.className = `task-card bg-white rounded-xl shadow-sm overflow-hidden ${task.completed ? 'completed-task' : ''}`;
|
| 585 |
taskCard.innerHTML = `
|
| 586 |
+
<div class="p-5 flex ${!task.completed ? 'pending-task' : ''}">
|
| 587 |
<div class="mr-4 mt-1">
|
| 588 |
<button onclick="toggleTaskCompletion(${task.id})" class="w-6 h-6 rounded-full border-2 flex items-center justify-center ${task.completed ? 'bg-secondary border-secondary' : 'border-gray-300'}">
|
| 589 |
${task.completed ? '<i class="fas fa-check text-white text-xs"></i>' : ''}
|