Spaces:
Running
Running
File size: 30,260 Bytes
35b4be4 | 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 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TaskMaster Pro</title>
<!-- Import Google Fonts (Poppins & Inter) -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@600;700;800&display=swap" rel="stylesheet">
<!-- Import FontAwesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root {
/* Modern Color Palette - Light Mode */
--primary-color: #6366f1;
--primary-hover: #4f46e5;
--secondary-color: #ec4899;
--bg-body: #f3f4f6;
--bg-card: #ffffff;
--text-main: #1f2937;
--text-secondary: #6b7280;
--border-color: #e5e7eb;
--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
--shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Dark Mode Variables */
[data-theme="dark"] {
--bg-body: #0f172a;
--bg-card: #1e293b;
--text-main: #f1f5f9;
--text-secondary: #94a3b8;
--border-color: #334155;
--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
--shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg-body);
color: var(--text-main);
transition: var(--transition);
line-height: 1.6;
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* --- Header Section --- */
header {
background-color: var(--bg-card);
padding: 1rem 2rem;
box-shadow: var(--shadow-sm);
display: flex;
justify-content: space-between;
align-items: center;
position: sticky;
top: 0;
z-index: 100;
border-bottom: 1px solid var(--border-color);
}
.brand {
display: flex;
align-items: center;
gap: 10px;
font-family: 'Poppins', sans-serif;
font-weight: 800;
font-size: 1.5rem;
color: var(--primary-color);
}
.brand i {
font-size: 1.8rem;
}
.header-controls {
display: flex;
align-items: center;
gap: 1.5rem;
}
.theme-toggle {
cursor: pointer;
font-size: 1.2rem;
color: var(--text-secondary);
transition: color 0.3s;
padding: 8px;
border-radius: 50%;
background: transparent;
border: none;
}
.theme-toggle:hover {
background-color: var(--bg-body);
color: var(--primary-color);
}
.user-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
font-size: 1rem;
}
/* --- Main Layout --- */
main {
flex: 1;
padding: 2rem;
max-width: 1400px;
margin: 0 auto;
width: 100%;
}
.dashboard-header {
margin-bottom: 2rem;
display: flex;
justify-content: space-between;
align-items: flex-end;
}
.dashboard-title h1 {
font-family: 'Poppins', sans-serif;
font-size: 2.5rem;
font-weight: 700;
}
.dashboard-title p {
color: var(--text-secondary);
margin-top: 0.5rem;
}
.stats-container {
display: flex;
gap: 1.5rem;
}
.stat-card {
background-color: var(--bg-card);
padding: 1rem 1.5rem;
border-radius: 12px;
box-shadow: var(--shadow-sm);
border-left: 4px solid var(--primary-color);
min-width: 150px;
}
.stat-value {
font-size: 2rem;
font-weight: 700;
color: var(--primary-color);
}
.stat-label {
color: var(--text-secondary);
font-size: 0.9rem;
text-transform: uppercase;
letter-spacing: 0.5px;
}
/* --- Task Board (Kanban) --- */
.board-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
height: 100%;
}
.column {
background-color: var(--bg-body);
border-radius: 16px;
padding: 1.5rem;
display: flex;
flex-direction: column;
min-height: 600px;
transition: var(--transition);
}
.column-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
padding-bottom: 1rem;
border-bottom: 2px solid var(--border-color);
}
.column-title {
font-family: 'Poppins', sans-serif;
font-weight: 600;
font-size: 1.2rem;
display: flex;
align-items: center;
gap: 10px;
}
.task-count {
background-color: var(--bg-card);
padding: 2px 8px;
border-radius: 12px;
font-size: 0.8rem;
color: var(--text-secondary);
font-weight: 600;
}
.add-btn {
background: none;
border: none;
color: var(--primary-color);
cursor: pointer;
font-size: 1.2rem;
transition: transform 0.2s;
padding: 5px;
border-radius: 8px;
}
.add-btn:hover {
background-color: rgba(99, 102, 241, 0.1);
transform: scale(1.1);
}
.task-list {
flex: 1;
overflow-y: auto;
padding-right: 5px;
scrollbar-width: thin;
}
/* Custom Scrollbar */
.task-list::-webkit-scrollbar {
width: 6px;
}
.task-list::-webkit-scrollbar-track {
background: transparent;
}
.task-list::-webkit-scrollbar-thumb {
background-color: var(--border-color);
border-radius: 20px;
}
/* --- Task Cards --- */
.task-card {
background-color: var(--bg-card);
padding: 1.25rem;
border-radius: 12px;
margin-bottom: 1rem;
box-shadow: var(--shadow-sm);
transition: var(--transition);
border: 1px solid transparent;
cursor: grab;
position: relative;
}
.task-card:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-md);
border-color: var(--primary-color);
}
.task-card.dragging {
opacity: 0.5;
cursor: grabbing;
}
.task-priority {
display: inline-block;
font-size: 0.75rem;
font-weight: 700;
text-transform: uppercase;
padding: 4px 8px;
border-radius: 6px;
margin-bottom: 0.75rem;
}
.priority-high { background-color: #fee2e2; color: #dc2626; }
.priority-medium { background-color: #fef3c7; color: #d97706; }
.priority-low { background-color: #dbeafe; color: #2563eb; }
.task-title {
font-family: 'Poppins', sans-serif;
font-size: 1.1rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: var(--text-main);
}
.task-desc {
font-size: 0.9rem;
color: var(--text-secondary);
margin-bottom: 1rem;
white-space: pre-wrap;
}
.task-meta {
display: flex;
justify-content: space-between;
align-items: center;
border-top: 1px solid var(--border-color);
padding-top: 0.75rem;
font-size: 0.85rem;
color: var(--text-secondary);
}
.due-date {
display: flex;
align-items: center;
gap: 5px;
}
.delete-btn {
background: none;
border: none;
color: #9ca3af;
cursor: pointer;
padding: 5px;
border-radius: 4px;
transition: all 0.2s;
}
.delete-btn:hover {
color: #ef4444;
background-color: #fee2e2;
}
/* --- Modal / Add Task Form --- */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(4px);
display: flex;
justify-content: center;
align-items: center;
z-index: 200;
opacity: 0;
visibility: hidden;
transition: var(--transition);
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
.modal {
background-color: var(--bg-card);
padding: 2rem;
border-radius: 16px;
width: 90%;
max-width: 500px;
box-shadow: var(--shadow-lg);
transform: scale(0.9);
transition: var(--transition);
}
.modal-overlay.active .modal {
transform: scale(1);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.modal-title {
font-family: 'Poppins', sans-serif;
font-size: 1.5rem;
font-weight: 700;
}
.close-btn {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: var(--text-secondary);
}
.form-group {
margin-bottom: 1.25rem;
}
.form-label {
display: block;
margin-bottom: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
color: var(--text-main);
}
.form-input {
width: 100%;
padding: 0.75rem;
border-radius: 8px;
border: 1px solid var(--border-color);
background-color: var(--bg-body);
color: var(--text-main);
font-family: 'Inter', sans-serif;
font-size: 1rem;
transition: var(--transition);
}
.form-input:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
textarea.form-input {
resize: vertical;
min-height: 100px;
}
.form-select {
width: 100%;
padding: 0.75rem;
border-radius: 8px;
border: 1px solid var(--border-color);
background-color: var(--bg-body);
color: var(--text-main);
font-family: 'Inter', sans-serif;
font-size: 1rem;
cursor: pointer;
}
.modal-footer {
display: flex;
justify-content: flex-end;
gap: 1rem;
margin-top: 2rem;
}
.btn {
padding: 0.75rem 1.5rem;
border-radius: 8px;
font-weight: 600;
font-size: 0.95rem;
cursor: pointer;
transition: var(--transition);
border: none;
font-family: 'Inter', sans-serif;
}
.btn-primary {
background-color: var(--primary-color);
color: white;
}
.btn-primary:hover {
background-color: var(--primary-hover);
transform: translateY(-1px);
}
.btn-secondary {
background-color: transparent;
color: var(--text-secondary);
border: 1px solid var(--border-color);
}
.btn-secondary:hover {
background-color: var(--bg-body);
color: var(--text-main);
}
/* --- Footer --- */
footer {
text-align: center;
padding: 2rem;
color: var(--text-secondary);
font-size: 0.9rem;
border-top: 1px solid var(--border-color);
margin-top: auto;
}
.footer-link {
color: var(--primary-color);
text-decoration: none;
font-weight: 600;
}
.footer-link:hover {
text-decoration: underline;
}
/* --- Responsive Mobile --- */
@media (max-width: 768px) {
.dashboard-title h1 { font-size: 2rem; }
.stats-container { grid-template-columns: 1fr 1fr; }
.header-controls { gap: 1rem; }
.brand span { display: none; }
}
</style>
</head>
<body>
<!-- Header -->
<header>
<div class="brand">
<i class="fa-solid fa-rocket"></i>
<span>TaskMaster</span>
</div>
<div class="header-controls">
<button class="theme-toggle" id="themeToggle" title="Toggle Theme">
<i class="fa-solid fa-moon"></i>
</button>
<div class="user-avatar">JD</div>
</div>
</header>
<!-- Main Content -->
<main>
<div class="dashboard-header">
<div class="dashboard-title">
<h1>My Dashboard</h1>
<p>Welcome back, John! You have <span id="totalTasks" style="color:var(--primary-color); font-weight:700;">0</span> pending tasks.</p>
</div>
<div class="stats-container">
<div class="stat-card">
<div class="stat-value" id="pendingCount">0</div>
<div class="stat-label">To Do</div>
</div>
<div class="stat-card" style="border-color: #f59e0b;">
<div class="stat-value" id="progressCount">0</div>
<div class="stat-label">In Progress</div>
</div>
<div class="stat-card" style="border-color: #10b981;">
<div class="stat-value" id="doneCount">0</div>
<div class="stat-label">Completed</div>
</div>
</div>
</div>
<!-- Kanban Board -->
<div class="board-container">
<!-- Column: To Do -->
<div class="column" id="todo">
<div class="column-header">
<div class="column-title">
<i class="fa-solid fa-list-check" style="color: #6366f1;"></i>
To Do
<span class="task-count" id="count-todo">0</span>
</div>
<button class="add-btn" onclick="openModal('todo')">
<i class="fa-solid fa-plus"></i>
</button>
</div>
<div class="task-list" id="list-todo">
<!-- Tasks injected here -->
</div>
</div>
<!-- Column: In Progress -->
<div class="column" id="inprogress">
<div class="column-header">
<div class="column-title">
<i class="fa-solid fa-circle-play" style="color: #f59e0b;"></i>
In Progress
<span class="task-count" id="count-inprogress">0</span>
</div>
<button class="add-btn" onclick="openModal('inprogress')">
<i class="fa-solid fa-plus"></i>
</button>
</div>
<div class="task-list" id="list-inprogress">
<!-- Tasks injected here -->
</div>
</div>
<!-- Column: Done -->
<div class="column" id="done">
<div class="column-header">
<div class="column-title">
<i class="fa-solid fa-check-to-slot" style="color: #10b981;"></i>
Completed
<span class="task-count" id="count-done">0</span>
</div>
</div>
<div class="task-list" id="list-done">
<!-- Tasks injected here -->
</div>
</div>
</div>
</main>
<!-- Footer with Requirement -->
<footer>
<p>© 2023 TaskMaster Pro. Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="footer-link">any coder</a>.</p>
</footer>
<!-- Add Task Modal -->
<div class="modal-overlay" id="taskModal">
<div class="modal">
<div class="modal-header">
<h2 class="modal-title" id="modalTitle">Add New Task</h2>
<button class="close-btn" onclick="closeModal()">×</button>
</div>
<form id="taskForm">
<input type="hidden" id="taskId">
<div class="form-group">
<label class="form-label" for="taskTitle">Task Title</label>
<input type="text" id="taskTitle" class="form-input" placeholder="e.g., Redesign Homepage" required>
</div>
<div class="form-group">
<label class="form-label" for="taskDesc">Description</label>
<textarea id="taskDesc" class="form-input" placeholder="Add details about this task..."></textarea>
</div>
<div class="form-group">
<label class="form-label" for="taskPriority">Priority</label>
<select id="taskPriority" class="form-select">
<option value="low">Low Priority</option>
<option value="medium" selected>Medium Priority</option>
<option value="high">High Priority</option>
</select>
</div>
<div class="form-group">
<label class="form-label" for="taskStatus">Move To</label>
<select id="taskStatus" class="form-select">
<option value="todo">To Do</option>
<option value="inprogress">In Progress</option>
<option value="done">Completed</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="closeModal()">Cancel</button>
<button type="submit" class="btn btn-primary">Save Task</button>
</div>
</form>
</div>
</div>
<script>
// --- State Management ---
let tasks = JSON.parse(localStorage.getItem('taskMasterData')) || [
{ id: 1, title: "Welcome to TaskMaster", desc: "This is a demo task. You can drag and drop this card!", priority: "low", status: "todo", date: new Date().toISOString().split('T')[0] },
{ id: 2, title: "Update Settings", desc: "Remember to change the theme color in settings.", priority: "medium", status: "inprogress", date: new Date().toISOString().split('T')[0] },
{ id: 3, title: "Complete Project", desc: "Finish the HTML, CSS, and JS parts.", priority: "high", status: "done", date: new Date().toISOString().split('T')[0] }
];
let draggedItem = null;
// --- DOM Elements ---
const themeToggle = document.getElementById('themeToggle');
const modal = document.getElementById('taskModal');
const taskForm = document.getElementById('taskForm');
const modalTitle = document.getElementById('modalTitle');
const taskLists = {
todo: document.getElementById('list-todo'),
inprogress: document.getElementById('list-inprogress'),
done: document.getElementById('list-done')
};
// --- Initialization ---
document.addEventListener('DOMContentLoaded', () => {
renderTasks();
updateStats();
checkTheme();
});
// --- Theme Logic ---
function checkTheme() {
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
}
themeToggle.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
});
function updateThemeIcon(theme) {
const icon = themeToggle.querySelector('i');
if (theme === 'dark') {
icon.className = 'fa-solid fa-sun';
} else {
icon.className = 'fa-solid fa-moon';
}
}
// --- Task Rendering ---
function renderTasks() {
// Clear lists
taskLists.todo.innerHTML = '';
taskLists.inprogress.innerHTML = '';
taskLists.done.innerHTML = '';
tasks.forEach(task => {
const card = createTaskCard(task);
taskLists[task.status].appendChild(card);
});
updateStats();
saveData();
}
function createTaskCard(task) {
const card = document.createElement('div');
card.className = 'task-card';
card.draggable = true;
card.id = task.id;
// Priority Styles
const priorityClass = `priority-${task.priority}`;
const priorityLabel = task.priority.charAt(0).toUpperCase() + task.priority.slice(1);
card.innerHTML = `
<span class="task-priority ${priorityClass}">${priorityLabel}</span>
<div class="task-title">${escapeHtml(task.title)}</div>
<div class="task-desc">${escapeHtml(task.desc)}</div>
<div class="task-meta">
<span class="due-date">
<i class="fa-regular fa-calendar"></i> ${task.date}
</span>
<div style="display:flex; gap:5px;">
<button class="delete-btn" onclick="deleteTask(${task.id})" title="Delete">
<i class="fa-solid fa-trash"></i>
</button>
</div>
</div>
`;
// Drag Events
card.addEventListener('dragstart', handleDragStart);
card.addEventListener('dragend', handleDragEnd);
card.addEventListener('dragover', handleDragOver);
card.addEventListener('drop', handleDrop);
card.addEventListener('dragenter', handleDragEnter);
card.addEventListener('dragleave', handleDragLeave);
return card;
}
function updateStats() {
const total = tasks.length;
const pending = tasks.filter(t => t.status === 'todo').length;
const progress = tasks.filter(t => t.status === 'inprogress').length;
const done = tasks.filter(t => t.status === 'done').length;
document.getElementById('totalTasks').innerText = total;
document.getElementById('pendingCount').innerText = pending;
document.getElementById('progressCount').innerText = progress;
document.getElementById('doneCount').innerText = done;
document.getElementById('count-todo').innerText = pending;
document.getElementById('count-inprogress').innerText = progress;
document.getElementById('count-done').innerText = done;
}
// --- Drag & Drop Logic ---
function handleDragStart(e) {
draggedItem = this;
setTimeout(() => this.classList.add('dragging'), 0);
}
function handleDragEnd(e) {
this.classList.remove('dragging');
draggedItem = null;
}
function handleDragOver(e) {
e.preventDefault(); // Necessary to allow dropping
}
function handleDragEnter(e) {
e.preventDefault();
if (this !== draggedItem && this.classList.contains('task-list')) {
this.style.borderColor = 'var(--primary-color)';
this.style.backgroundColor = 'var(--bg-card)';
}
}
function handleDragLeave(e) {
if (this.classList.contains('task-list')) {
this.style.borderColor = 'transparent';
this.style.backgroundColor = 'var(--bg-body)';
}
}
function handleDrop(e) {
e.preventDefault();
this.style.borderColor = 'transparent';
this.style.backgroundColor = 'var(--bg-body)';
if (draggedItem && draggedItem !== this) {
// Find the target task ID (if dropping on a card) or just append (if dropping on empty list)
let targetTask = this;
// If we dropped on the task-list container directly
if (this.classList.contains('task-list')) {
this.appendChild(draggedItem);
updateTaskStatus(draggedItem.id, this.id.replace('list-', ''));
return;
}
// If we dropped on another card
if (this.classList.contains('task-card')) {
this.after(draggedItem);
updateTaskStatus(draggedItem.id, this.parentElement.id.replace('list-', ''));
}
}
}
function updateTaskStatus(taskId, newStatus) {
const taskIndex = tasks.findIndex(t => t.id === taskId);
if (taskIndex > -1) {
tasks[taskIndex].status = newStatus;
saveData();
updateStats();
}
}
// --- Modal & Form Logic ---
function openModal(status = 'todo') {
modal.classList.add('active');
document.getElementById('modalTitle').innerText = "Add New Task";
taskForm.reset();
document.getElementById('taskStatus').value = status;
document.getElementById('taskId').value = '';
}
function closeModal() {
modal.classList.remove('active');
taskForm.reset();
}
taskForm.addEventListener('submit', (e) => {
e.preventDefault();
const id = document.getElementById('taskId').value;
const title = document.getElementById('taskTitle').value;
const desc = document.getElementById('taskDesc').value;
const priority = document.getElementById('taskPriority').value;
const status = document.getElementById('taskStatus').value;
const date = new Date().toISOString().split('T')[0];
if (id) {
// Edit existing
const taskIndex = tasks.findIndex(t => t.id == id);
if (taskIndex > -1) {
tasks[taskIndex] = { ...tasks[taskIndex], title, desc, priority, status, date };
}
} else {
// Create new
const newTask = {
id: Date.now(),
title,
desc,
priority,
status,
date
};
tasks.push(newTask);
}
saveData();
renderTasks();
closeModal();
});
function deleteTask(id) {
if (confirm('Are you sure you want to delete this task?')) {
tasks = tasks.filter(task => task.id !== id);
saveData();
renderTasks();
}
}
// --- Utilities ---
function saveData() {
localStorage.setItem('taskMasterData', JSON.stringify(tasks));
}
function escapeHtml(text) {
if (!text) return "";
return text
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
// Close modal if clicking outside
modal.addEventListener('click', (e) => {
if (e.target === modal) closeModal();
});
</script>
</body>
</html> |