Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>TaskFlow - Modern Todo App</title> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| :root { | |
| --primary: #6366f1; | |
| --primary-dark: #4f46e5; | |
| --primary-light: #818cf8; | |
| --secondary: #22d3ee; | |
| --success: #10b981; | |
| --warning: #f59e0b; | |
| --danger: #ef4444; | |
| --dark: #1e293b; | |
| --light: #f1f5f9; | |
| --white: #ffffff; | |
| --gray: #64748b; | |
| --gray-light: #e2e8f0; | |
| --shadow: 0 10px 30px rgba(0, 0, 0, 0.1); | |
| --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.15); | |
| --radius: 12px; | |
| --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); | |
| } | |
| body { | |
| font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| padding: 20px; | |
| position: relative; | |
| overflow-x: hidden; | |
| } | |
| body::before { | |
| content: ''; | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| right: 0; | |
| bottom: 0; | |
| background: | |
| radial-gradient(circle at 20% 80%, rgba(99, 102, 241, 0.3) 0%, transparent 50%), | |
| radial-gradient(circle at 80% 20%, rgba(34, 211, 238, 0.3) 0%, transparent 50%), | |
| radial-gradient(circle at 40% 40%, rgba(168, 85, 247, 0.2) 0%, transparent 50%); | |
| pointer-events: none; | |
| } | |
| .container { | |
| width: 100%; | |
| max-width: 900px; | |
| background: rgba(255, 255, 255, 0.95); | |
| backdrop-filter: blur(20px); | |
| border-radius: 24px; | |
| box-shadow: var(--shadow-lg); | |
| overflow: hidden; | |
| position: relative; | |
| z-index: 1; | |
| animation: slideUp 0.5s ease-out; | |
| } | |
| @keyframes slideUp { | |
| from { | |
| opacity: 0; | |
| transform: translateY(30px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| } | |
| header { | |
| background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); | |
| color: white; | |
| padding: 30px; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| header::after { | |
| content: ''; | |
| position: absolute; | |
| top: -50%; | |
| right: -10%; | |
| width: 300px; | |
| height: 300px; | |
| background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%); | |
| border-radius: 50%; | |
| } | |
| .header-content { | |
| position: relative; | |
| z-index: 1; | |
| } | |
| .header-top { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 20px; | |
| } | |
| h1 { | |
| font-size: 2.5rem; | |
| font-weight: 700; | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| } | |
| h1 i { | |
| font-size: 2rem; | |
| opacity: 0.9; | |
| } | |
| .brand-link { | |
| color: white; | |
| text-decoration: none; | |
| font-size: 0.85rem; | |
| opacity: 0.8; | |
| transition: opacity 0.3s; | |
| position: absolute; | |
| bottom: 10px; | |
| right: 30px; | |
| } | |
| .brand-link:hover { | |
| opacity: 1; | |
| } | |
| .stats { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); | |
| gap: 20px; | |
| margin-top: 20px; | |
| } | |
| .stat-card { | |
| background: rgba(255, 255, 255, 0.1); | |
| backdrop-filter: blur(10px); | |
| padding: 15px; | |
| border-radius: var(--radius); | |
| text-align: center; | |
| transition: var(--transition); | |
| } | |
| .stat-card:hover { | |
| background: rgba(255, 255, 255, 0.15); | |
| transform: translateY(-2px); | |
| } | |
| .stat-number { | |
| font-size: 2rem; | |
| font-weight: 700; | |
| margin-bottom: 5px; | |
| } | |
| .stat-label { | |
| font-size: 0.85rem; | |
| opacity: 0.9; | |
| } | |
| .progress-bar { | |
| width: 100%; | |
| height: 8px; | |
| background: rgba(255, 255, 255, 0.2); | |
| border-radius: 4px; | |
| overflow: hidden; | |
| margin-top: 10px; | |
| } | |
| .progress-fill { | |
| height: 100%; | |
| background: linear-gradient(90deg, var(--success), var(--secondary)); | |
| border-radius: 4px; | |
| transition: width 0.5s ease; | |
| } | |
| .main-content { | |
| padding: 30px; | |
| } | |
| .input-section { | |
| background: var(--light); | |
| padding: 25px; | |
| border-radius: var(--radius); | |
| margin-bottom: 30px; | |
| } | |
| .input-group { | |
| display: flex; | |
| gap: 15px; | |
| margin-bottom: 15px; | |
| flex-wrap: wrap; | |
| } | |
| .task-input { | |
| flex: 1; | |
| min-width: 200px; | |
| padding: 12px 20px; | |
| border: 2px solid transparent; | |
| border-radius: var(--radius); | |
| font-size: 1rem; | |
| background: white; | |
| transition: var(--transition); | |
| } | |
| .task-input:focus { | |
| outline: none; | |
| border-color: var(--primary); | |
| box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1); | |
| } | |
| .input-meta { | |
| display: flex; | |
| gap: 15px; | |
| flex-wrap: wrap; | |
| } | |
| .meta-input { | |
| padding: 10px 15px; | |
| border: 2px solid var(--gray-light); | |
| border-radius: var(--radius); | |
| background: white; | |
| font-size: 0.9rem; | |
| transition: var(--transition); | |
| } | |
| .meta-input:focus { | |
| outline: none; | |
| border-color: var(--primary); | |
| } | |
| .btn { | |
| padding: 12px 24px; | |
| border: none; | |
| border-radius: var(--radius); | |
| font-size: 1rem; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: var(--transition); | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 8px; | |
| } | |
| .btn-primary { | |
| background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); | |
| color: white; | |
| } | |
| .btn-primary:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3); | |
| } | |
| .btn-secondary { | |
| background: var(--gray-light); | |
| color: var(--dark); | |
| } | |
| .btn-secondary:hover { | |
| background: var(--gray); | |
| color: white; | |
| } | |
| .controls { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 20px; | |
| flex-wrap: wrap; | |
| gap: 15px; | |
| } | |
| .filter-tabs { | |
| display: flex; | |
| gap: 10px; | |
| background: var(--light); | |
| padding: 5px; | |
| border-radius: var(--radius); | |
| } | |
| .filter-tab { | |
| padding: 8px 16px; | |
| background: transparent; | |
| border: none; | |
| border-radius: 8px; | |
| cursor: pointer; | |
| font-weight: 500; | |
| color: var(--gray); | |
| transition: var(--transition); | |
| } | |
| .filter-tab.active { | |
| background: white; | |
| color: var(--primary); | |
| box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); | |
| } | |
| .search-box { | |
| position: relative; | |
| min-width: 250px; | |
| } | |
| .search-input { | |
| width: 100%; | |
| padding: 10px 40px 10px 15px; | |
| border: 2px solid var(--gray-light); | |
| border-radius: var(--radius); | |
| font-size: 0.9rem; | |
| transition: var(--transition); | |
| } | |
| .search-input:focus { | |
| outline: none; | |
| border-color: var(--primary); | |
| } | |
| .search-icon { | |
| position: absolute; | |
| right: 15px; | |
| top: 50%; | |
| transform: translateY(-50%); | |
| color: var(--gray); | |
| } | |
| .todo-list { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 12px; | |
| max-height: 500px; | |
| overflow-y: auto; | |
| padding-right: 10px; | |
| } | |
| .todo-list::-webkit-scrollbar { | |
| width: 8px; | |
| } | |
| .todo-list::-webkit-scrollbar-track { | |
| background: var(--light); | |
| border-radius: 4px; | |
| } | |
| .todo-list::-webkit-scrollbar-thumb { | |
| background: var(--gray); | |
| border-radius: 4px; | |
| } | |
| .todo-item { | |
| background: white; | |
| border: 2px solid var(--gray-light); | |
| border-radius: var(--radius); | |
| padding: 20px; | |
| display: flex; | |
| align-items: center; | |
| gap: 15px; | |
| transition: var(--transition); | |
| cursor: move; | |
| animation: fadeIn 0.3s ease; | |
| } | |
| @keyframes fadeIn { | |
| from { | |
| opacity: 0; | |
| transform: translateX(-20px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateX(0); | |
| } | |
| } | |
| .todo-item:hover { | |
| box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); | |
| transform: translateY(-2px); | |
| } | |
| .todo-item.dragging { | |
| opacity: 0.5; | |
| transform: rotate(2deg); | |
| } | |
| .todo-item.completed { | |
| opacity: 0.7; | |
| background: var(--light); | |
| } | |
| .todo-item.completed .todo-text { | |
| text-decoration: line-through; | |
| color: var(--gray); | |
| } | |
| .checkbox { | |
| width: 24px; | |
| height: 24px; | |
| border: 2px solid var(--primary); | |
| border-radius: 6px; | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| transition: var(--transition); | |
| flex-shrink: 0; | |
| } | |
| .checkbox:hover { | |
| background: var(--primary-light); | |
| border-color: var(--primary-light); | |
| } | |
| .checkbox.checked { | |
| background: var(--primary); | |
| border-color: var(--primary); | |
| } | |
| .checkbox.checked::after { | |
| content: '✓'; | |
| color: white; | |
| font-weight: bold; | |
| } | |
| .todo-content { | |
| flex: 1; | |
| } | |
| .todo-text { | |
| font-size: 1rem; | |
| color: var(--dark); | |
| margin-bottom: 5px; | |
| word-break: break-word; | |
| } | |
| .todo-meta { | |
| display: flex; | |
| gap: 10px; | |
| flex-wrap: wrap; | |
| margin-top: 8px; | |
| } | |
| .todo-badge { | |
| padding: 3px 8px; | |
| border-radius: 4px; | |
| font-size: 0.75rem; | |
| font-weight: 600; | |
| } | |
| .priority-high { | |
| background: rgba(239, 68, 68, 0.1); | |
| color: var(--danger); | |
| } | |
| .priority-medium { | |
| background: rgba(245, 158, 11, 0.1); | |
| color: var(--warning); | |
| } | |
| .priority-low { | |
| background: rgba(16, 185, 129, 0.1); | |
| color: var(--success); | |
| } | |
| .category-badge { | |
| background: rgba(99, 102, 241, 0.1); | |
| color: var(--primary); | |
| } | |
| .due-date { | |
| background: rgba(100, 116, 139, 0.1); | |
| color: var(--gray); | |
| } | |
| .todo-actions { | |
| display: flex; | |
| gap: 8px; | |
| } | |
| .action-btn { | |
| width: 32px; | |
| height: 32px; | |
| border: none; | |
| background: var(--light); | |
| border-radius: 8px; | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| transition: var(--transition); | |
| color: var(--gray); | |
| } | |
| .action-btn:hover { | |
| background: var(--primary); | |
| color: white; | |
| transform: scale(1.1); | |
| } | |
| .action-btn.delete:hover { | |
| background: var(--danger); | |
| } | |
| .empty-state { | |
| text-align: center; | |
| padding: 60px 20px; | |
| color: var(--gray); | |
| } | |
| .empty-state i { | |
| font-size: 4rem; | |
| margin-bottom: 20px; | |
| opacity: 0.3; | |
| } | |
| .empty-state h3 { | |
| font-size: 1.5rem; | |
| margin-bottom: 10px; | |
| } | |
| .clear-completed { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-top: 20px; | |
| padding-top: 20px; | |
| border-top: 2px solid var(--gray-light); | |
| } | |
| .toast { | |
| position: fixed; | |
| bottom: 30px; | |
| right: 30px; | |
| background: var(--dark); | |
| color: white; | |
| padding: 15px 20px; | |
| border-radius: var(--radius); | |
| box-shadow: var(--shadow-lg); | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| transform: translateX(400px); | |
| transition: transform 0.3s ease; | |
| z-index: 1000; | |
| } | |
| .toast.show { | |
| transform: translateX(0); | |
| } | |
| @media (max-width: 768px) { | |
| h1 { | |
| font-size: 1.8rem; | |
| } | |
| .stats { | |
| grid-template-columns: repeat(2, 1fr); | |
| } | |
| .controls { | |
| flex-direction: column; | |
| align-items: stretch; | |
| } | |
| .search-box { | |
| width: 100%; | |
| } | |
| .filter-tabs { | |
| justify-content: center; | |
| } | |
| .todo-item { | |
| padding: 15px; | |
| } | |
| .input-meta { | |
| flex-direction: column; | |
| } | |
| .meta-input { | |
| width: 100%; | |
| } | |
| } | |
| @media (max-width: 480px) { | |
| .container { | |
| border-radius: 0; | |
| min-height: 100vh; | |
| } | |
| body { | |
| padding: 0; | |
| } | |
| header { | |
| padding: 20px; | |
| } | |
| .main-content { | |
| padding: 20px; | |
| } | |
| h1 { | |
| font-size: 1.5rem; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <header> | |
| <div class="header-content"> | |
| <div class="header-top"> | |
| <h1> | |
| <i class="fas fa-tasks"></i> | |
| TaskFlow | |
| </h1> | |
| </div> | |
| <div class="stats"> | |
| <div class="stat-card"> | |
| <div class="stat-number" id="totalTasks">0</div> | |
| <div class="stat-label">Total Tasks</div> | |
| </div> | |
| <div class="stat-card"> | |
| <div class="stat-number" id="completedTasks">0</div> | |
| <div class="stat-label">Completed</div> | |
| </div> | |
| <div class="stat-card"> | |
| <div class="stat-number" id="activeTasks">0</div> | |
| <div class="stat-label">Active</div> | |
| </div> | |
| <div class="stat-card"> | |
| <div class="stat-number" id="completionRate">0%</div> | |
| <div class="stat-label">Completion</div> | |
| <div class="progress-bar"> | |
| <div class="progress-fill" id="progressFill"></div> | |
| </div> | |
| </div> | |
| </div> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="brand-link"> | |
| Built with anycoder | |
| </a> | |
| </div> | |
| </header> | |
| <main class="main-content"> | |
| <section class="input-section"> | |
| <div class="input-group"> | |
| <input type="text" | |
| class="task-input" | |
| id="taskInput" | |
| placeholder="What needs to be done today?..." | |
| maxlength="200"> | |
| <button class="btn btn-primary" id="addTaskBtn"> | |
| <i class="fas fa-plus"></i> | |
| Add Task | |
| </button> | |
| </div> | |
| <div class="input-meta"> | |
| <select class="meta-input" id="prioritySelect"> | |
| <option value="low">Low Priority</option> | |
| <option value="medium" selected>Medium Priority</option> | |
| <option value="high">High Priority</option> | |
| </select> | |
| <select class="meta-input" id="categorySelect"> | |
| <option value="personal">Personal</option> | |
| <option value="work">Work</option> | |
| <option value="shopping">Shopping</option> | |
| <option value="health">Health</option> | |
| <option value="education">Education</option> | |
| <option value="other">Other</option> | |
| </select> | |
| <input type="date" | |
| class="meta-input" | |
| id="dueDateInput"> | |
| </div> | |
| </section> | |
| <section class="controls"> | |
| <div class="filter-tabs"> | |
| <button class="filter-tab active" data-filter="all"> | |
| All Tasks | |
| </button> | |
| <button class="filter-tab" data-filter="active"> | |
| Active | |
| </button> | |
| <button class="filter-tab" data-filter="completed"> | |
| Completed | |
| </button> | |
| </div> | |
| <div class="search-box"> | |
| <input type="text" | |
| class="search-input" | |
| id="searchInput" | |
| placeholder="Search tasks..."> | |
| <i class="fas fa-search search-icon"></i> | |
| </div> | |
| </section> | |
| <section class="todo-list" id="todoList"> | |
| <!-- Tasks will be dynamically added here --> | |
| </section> | |
| <div class="empty-state" id="emptyState" style="display: none;"> | |
| <i class="fas fa-clipboard-list"></i> | |
| <h3>No tasks yet!</h3> | |
| <p>Start by adding your first task above.</p> | |
| </div> | |
| <div class="clear-completed" id="clearSection" style="display: none;"> | |
| <span id="completedCount">0 completed tasks</span> | |
| <button class="btn btn-secondary" id="clearCompletedBtn"> | |
| <i class="fas fa-trash"></i> | |
| Clear Completed | |
| </button> | |
| </div> | |
| </main> | |
| </div> | |
| <div class="toast" id="toast"> | |
| <i class="fas fa-check-circle"></i> | |
| <span id="toastMessage">Task added successfully!</span> | |
| </div> | |
| <script> | |
| class TodoApp { | |
| constructor() { | |
| this.todos = JSON.parse(localStorage.getItem('todos')) || []; | |
| this.currentFilter = 'all'; | |
| this.searchTerm = ''; | |
| this.draggedItem = null; | |
| this.init(); | |
| } | |
| init() { | |
| this.setupEventListeners(); | |
| this.render(); | |
| this.updateStats(); | |
| this.setMinDate(); | |
| } | |
| setMinDate() { | |
| const today = new Date().toISOString().split('T')[0]; | |
| document.getElementById('dueDateInput').setAttribute('min', today); | |
| } | |
| setupEventListeners() { | |
| // Add task | |
| document.getElementById('addTaskBtn').addEventListener('click', () => this.addTask()); | |
| document.getElementById('taskInput').addEventListener('keypress', (e) => { | |
| if (e.key === 'Enter') this.addTask(); | |
| }); | |
| // Filter tabs | |
| document.querySelectorAll('.filter-tab').forEach(tab => { | |
| tab.addEventListener('click', (e) => { | |
| document.querySelectorAll('.filter-tab').forEach(t => t.classList.remove('active')); | |
| e.target.classList.add('active'); | |
| this.currentFilter = e.target.dataset.filter; | |
| this.render(); | |
| }); | |
| }); | |
| // Search | |
| document.getElementById('searchInput').addEventListener('input', (e) => { | |
| this.searchTerm = e.target.value.toLowerCase(); | |
| this.render(); | |
| }); | |
| // Clear completed | |
| document.getElementById('clearCompletedBtn').addEventListener('click', () => { | |
| this.clearCompleted(); | |
| }); | |
| } | |
| addTask() { | |
| const input = document.getElementById('taskInput'); | |
| const text = input.value.trim(); | |
| if (!text) { | |
| this.showToast('Please enter a task!', 'error'); | |
| return; | |
| } | |
| const todo = { | |
| id: Date.now(), | |
| text: text, | |
| completed: false, | |
| priority: document.getElementById('prioritySelect').value, | |
| category: document.getElementById('categorySelect').value, | |
| dueDate: document.getElementById('dueDateInput').value, | |
| createdAt: new Date().toISOString() | |
| }; | |
| this.todos.unshift(todo); | |
| this.saveTodos(); | |
| this.render(); | |
| this.updateStats(); | |
| // Reset form | |
| input.value = ''; | |
| document.getElementById('dueDateInput').value = ''; | |
| document.getElementById('prioritySelect').value = 'medium'; | |
| document.getElementById('categorySelect').value = 'personal'; | |
| this.showToast('Task added successfully!'); | |
| } | |
| toggleTask(id) { | |
| const todo = this.todos.find(t => t.id === id); | |
| if (todo) { | |
| todo.completed = !todo.completed; | |
| this.saveTodos(); | |
| this.render(); | |
| this.updateStats(); | |
| this.showToast(todo.completed ? 'Task completed!' : 'Task marked as active'); | |
| } | |
| } | |
| deleteTask(id) { | |
| this.todos = this.todos.filter(t => t.id !== id); | |
| this.saveTodos(); | |
| this.render(); | |
| this.updateStats(); | |
| this.showToast('Task deleted!'); | |
| } | |
| editTask(id) { | |
| const todo = this.todos.find(t => t.id === id); | |
| if (todo) { | |
| const newText = prompt('Edit task:', todo.text); | |
| if (newText && newText.trim()) { | |
| todo.text = newText.trim(); | |
| this.saveTodos(); | |
| this.render(); | |
| this.showToast('Task updated!'); | |
| } | |
| } | |
| } | |
| clearCompleted() { | |
| const completedCount = this.todos.filter(t => t.completed).length; | |
| if (completedCount === 0) { | |
| this.showToast('No completed tasks to clear'); | |
| return; | |
| } | |
| if (confirm(`Clear ${completedCount} completed task(s)?`)) { | |
| this.todos = this.todos.filter(t => !t.completed); | |
| this.saveTodos(); | |
| this.render(); | |
| this.updateStats(); | |
| this.showToast(`Cleared ${completedCount} completed task(s)!`); | |
| } | |
| } | |
| getFilteredTodos() { | |
| let filtered = this.todos; | |
| // Apply filter | |
| if (this.currentFilter === 'active') { | |
| filtered = filtered.filter(t => !t.completed); | |
| } else if (this.currentFilter === 'completed') { | |
| filtered = filtered.filter(t => t.completed); | |
| } | |
| // Apply search | |
| if (this.searchTerm) { | |
| filtered = filtered.filter(t => | |
| t.text.toLowerCase().includes(this.searchTerm) || | |
| t.category.toLowerCase().includes(this.searchTerm) | |
| ); | |
| } | |
| return filtered; | |
| } | |
| render() { | |
| const todoList = document.getElementById('todoList'); | |
| const emptyState = document.getElementById('emptyState'); | |
| const clearSection = document.getElementById('clearSection'); | |
| const filteredTodos = this.getFilteredTodos(); | |
| if (this.todos.length === 0) { | |
| todoList.style.display = 'none'; | |
| emptyState.style.display = 'block'; | |
| clearSection.style.display = 'none'; | |
| return; | |
| } | |
| todoList.style.display = 'flex'; | |
| emptyState.style.display = 'none'; | |
| if (this.todos.some(t => t.completed)) { | |
| clearSection.style.display = 'flex'; | |
| const completedCount = this.todos.filter(t => t.completed).length; | |
| document.getElementById('completedCount').textContent = | |
| `${completedCount} completed task${completedCount !== 1 ? 's' : ''}`; | |
| } else { | |
| clearSection.style.display = 'none'; | |
| } | |
| if (filteredTodos.length === 0) { | |
| todoList.innerHTML = ` | |
| <div class="empty-state"> | |
| <i class="fas fa-search"></i> | |
| <h3>No tasks found</h3> | |
| <p>Try adjusting your search or filter</p> | |
| </div> | |
| `; | |
| return; | |
| } | |
| todoList.innerHTML = filteredTodos.map(todo => this.createTodoHTML(todo)).join(''); | |
| // Add event listeners to new elements | |
| this.attachTodoEventListeners(); | |
| this.setupDragAndDrop(); | |
| } | |
| createTodoHTML(todo) { | |
| const priorityClass = `priority-${todo.priority}`; | |
| const dueDateText = todo.dueDate ? this.formatDate(todo.dueDate) : ''; | |
| const isOverdue = todo.dueDate && new Date(todo.dueDate) < new Date() && !todo.completed; | |
| return ` | |
| <div class="todo-item ${todo.completed ? 'completed' : ''}" | |
| data-id="${todo.id}" | |
| draggable="true"> | |
| <div class="checkbox ${todo.completed ? 'checked' : ''}" | |
| onclick="app.toggleTask(${todo.id})"></div> | |
| <div class="todo-content"> | |
| <div class="todo-text">${this.escapeHtml(todo.text)}</div> | |
| <div class="todo-meta"> | |
| <span class="todo-badge ${priorityClass}"> | |
| ${todo.priority.charAt(0).toUpperCase() + todo.priority.slice(1)} | |
| </span> | |
| <span class="todo-badge category-badge"> | |
| ${todo.category.charAt(0).toUpperCase() + todo.category.slice(1)} | |
| </span> | |
| ${dueDateText ? ` | |
| <span class="todo-badge due-date ${isOverdue ? 'priority-high' : ''}"> | |
| <i class="far fa-calendar"></i> ${dueDateText} | |
| </span> | |
| ` : ''} | |
| </div> | |
| </div> | |
| <div class="todo-actions"> | |
| <button class="action-btn" onclick="app.editTask(${todo.id})"> | |
| <i class="fas fa-edit"></i> | |
| </button> | |
| <button class="action-btn delete" onclick="app.deleteTask(${todo.id})"> | |
| <i class="fas fa-trash"></i> | |
| </button> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| formatDate(dateString) { | |
| const date = new Date(dateString); | |
| const today = new Date(); | |
| const tomorrow = new Date(today); | |
| tomorrow.setDate(tomorrow.getDate() + 1); | |
| if (date.toDateString() === today.toDateString()) { | |
| return 'Today'; | |
| } else if (date.toDateString() === tomorrow.toDateString()) { | |
| return 'Tomorrow'; | |
| } else { | |
| return date.toLocaleDateString('en-US', { | |
| month: 'short', | |
| day: 'numeric' | |
| }); | |
| } | |
| } | |
| attachTodoEventListeners() { | |
| // Already handled by inline onclick handlers | |
| } | |
| setupDragAndDrop() { | |
| const items = document.querySelectorAll('.todo-item'); | |
| items.forEach(item => { | |
| item.addEventListener('dragstart', (e) => { | |
| this.draggedItem = item; | |
| item.classList.add('dragging'); | |
| }); | |
| item.addEventListener('dragend', (e) => { | |
| item.classList.remove('dragging'); | |
| }); | |
| item.addEventListener('dragover', (e) => { | |
| e.preventDefault(); | |
| const afterElement = this.getDragAfterElement(document.getElementById('todoList'), e.clientY); | |
| if (afterElement == null) { | |
| document.getElementById('todoList').appendChild(this.draggedItem); | |
| } else { | |
| document.getElementById('todoList').insertBefore(this.draggedItem, afterElement); | |
| } | |
| }); | |
| item.addEventListener('drop', (e) => { | |
| e.preventDefault(); | |
| this.reorderTodos(); | |
| }); | |
| }); | |
| } | |
| getDragAfterElement(container, y) { | |
| const draggableElements = [...container.querySelectorAll('.todo-item:not(.dragging)')]; | |
| return draggableElements.reduce((closest, child) => { | |
| const box = child.getBoundingClientRect(); | |
| const offset = y - box.top - box.height / 2; | |
| if (offset < 0 && offset > closest.offset) { | |
| return { offset: offset, element: child }; | |
| } else { | |
| return closest; | |
| } | |
| }, { offset: Number.NEGATIVE_INFINITY }).element; | |
| } | |
| reorderTodos() { | |
| const items = document.querySelectorAll('.todo-item'); | |
| const newOrder = []; | |
| items.forEach(item => { | |
| const id = parseInt(item.dataset.id); | |
| const todo = this.todos.find(t => t.id === id); | |
| if (todo) newOrder.push(todo); | |
| }); | |
| this.todos = newOrder; | |
| this.saveTodos(); | |
| } | |
| updateStats() { | |
| const total = this.todos.length; | |
| const completed = this.todos.filter(t => t.completed).length; | |
| const active = total - completed; | |
| const rate = total > 0 ? Math.round((completed / total) * 100) : 0; | |
| document.getElementById('totalTasks').textContent = total; | |
| document.getElementById('completedTasks').textContent = completed; | |
| document.getElementById('activeTasks').textContent = active; | |
| document.getElementById('completionRate').textContent = `${rate}%`; | |
| document.getElementById('progressFill').style.width = `${rate}%`; | |
| } | |
| saveTodos() { | |
| localStorage.setItem('todos', JSON.stringify(this.todos)); | |
| } | |
| showToast(message, type = 'success') { | |
| const toast = document.getElementById('toast'); | |
| const toastMessage = document.getElementById('toastMessage'); | |
| toastMessage.textContent = message; | |
| toast.classList.add('show'); | |
| setTimeout(() => { | |
| toast.classList.remove('show'); | |
| }, 3000); | |
| } | |
| escapeHtml(text) { | |
| const div = document.createElement('div'); | |
| div.textContent = text; | |
| return div.innerHTML; | |
| } | |
| } | |
| // Initialize the app | |
| const app = new TodoApp(); | |
| </script> | |
| </body> | |
| </html> |