Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>TaskFlow - Apple Style Todo</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 { | |
| --blue: #007AFF; | |
| --blue-dark: #0051D5; | |
| --gray-1: #8E8E93; | |
| --gray-2: #AEAEB2; | |
| --gray-3: #C7C7CC; | |
| --gray-4: #D1D1D6; | |
| --gray-5: #E5E5EA; | |
| --gray-6: #F2F2F7; | |
| --separator: #C6C6C8; | |
| --green: #34C759; | |
| --orange: #FF9500; | |
| --red: #FF3B30; | |
| --purple: #AF52DE; | |
| --pink: #FF2D55; | |
| --teal: #5AC8FA; | |
| --indigo: #5856D6; | |
| --background: #F2F2F7; | |
| --card-bg: rgba(255, 255, 255, 0.72); | |
| --text-primary: #1C1C1E; | |
| --text-secondary: #3C3C43; | |
| --text-tertiary: #8E8E93; | |
| --shadow: 0 4px 16px rgba(0, 0, 0, 0.08); | |
| --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.12); | |
| --radius-lg: 20px; | |
| --radius-md: 12px; | |
| --radius-sm: 8px; | |
| --radius-xs: 6px; | |
| } | |
| body { | |
| font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif; | |
| background: linear-gradient(180deg, #FFFFFF 0%, #F2F2F7 100%); | |
| min-height: 100vh; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| padding: 20px; | |
| position: relative; | |
| color: var(--text-primary); | |
| -webkit-font-smoothing: antialiased; | |
| -moz-osx-font-smoothing: grayscale; | |
| } | |
| body::before { | |
| content: ''; | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| right: 0; | |
| bottom: 0; | |
| background: | |
| radial-gradient(ellipse at top left, rgba(0, 122, 255, 0.03) 0%, transparent 50%), | |
| radial-gradient(ellipse at bottom right, rgba(88, 86, 214, 0.03) 0%, transparent 50%); | |
| pointer-events: none; | |
| z-index: 0; | |
| } | |
| .container { | |
| width: 100%; | |
| max-width: 880px; | |
| background: var(--card-bg); | |
| backdrop-filter: saturate(180%) blur(20px); | |
| -webkit-backdrop-filter: saturate(180%) blur(20px); | |
| border-radius: var(--radius-lg); | |
| border: 1px solid rgba(255, 255, 255, 0.2); | |
| box-shadow: var(--shadow); | |
| overflow: hidden; | |
| position: relative; | |
| z-index: 1; | |
| animation: slideUp 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| } | |
| @keyframes slideUp { | |
| from { | |
| opacity: 0; | |
| transform: translateY(40px) scale(0.95); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateY(0) scale(1); | |
| } | |
| } | |
| header { | |
| background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%); | |
| color: white; | |
| padding: 32px; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| header::before { | |
| content: ''; | |
| position: absolute; | |
| top: -50%; | |
| right: -20%; | |
| width: 400px; | |
| height: 400px; | |
| background: radial-gradient(circle, rgba(255, 255, 255, 0.08) 0%, transparent 70%); | |
| border-radius: 50%; | |
| animation: float 20s ease-in-out infinite; | |
| } | |
| @keyframes float { | |
| 0%, | |
| 100% { | |
| transform: translate(0, 0) rotate(0deg); | |
| } | |
| 33% { | |
| transform: translate(30px, -30px) rotate(120deg); | |
| } | |
| 66% { | |
| transform: translate(-20px, 20px) rotate(240deg); | |
| } | |
| } | |
| .header-content { | |
| position: relative; | |
| z-index: 1; | |
| } | |
| .header-top { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 24px; | |
| } | |
| h1 { | |
| font-size: 2.25rem; | |
| font-weight: 700; | |
| letter-spacing: -0.02em; | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| } | |
| h1 i { | |
| font-size: 1.8rem; | |
| opacity: 0.85; | |
| } | |
| .brand-link { | |
| color: rgba(255, 255, 255, 0.7); | |
| text-decoration: none; | |
| font-size: 0.875rem; | |
| font-weight: 500; | |
| transition: all 0.3s ease; | |
| position: absolute; | |
| bottom: 12px; | |
| right: 32px; | |
| padding: 6px 12px; | |
| border-radius: var(--radius-xs); | |
| } | |
| .brand-link:hover { | |
| color: white; | |
| background: rgba(255, 255, 255, 0.1); | |
| } | |
| .stats { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); | |
| gap: 16px; | |
| margin-top: 24px; | |
| } | |
| .stat-card { | |
| background: rgba(255, 255, 255, 0.12); | |
| backdrop-filter: blur(10px); | |
| padding: 16px; | |
| border-radius: var(--radius-md); | |
| text-align: center; | |
| transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| border: 1px solid rgba(255, 255, 255, 0.1); | |
| } | |
| .stat-card:hover { | |
| background: rgba(255, 255, 255, 0.18); | |
| transform: translateY(-2px); | |
| backdrop-filter: blur(20px); | |
| } | |
| .stat-number { | |
| font-size: 2rem; | |
| font-weight: 700; | |
| margin-bottom: 4px; | |
| letter-spacing: -0.02em; | |
| } | |
| .stat-label { | |
| font-size: 0.875rem; | |
| opacity: 0.85; | |
| font-weight: 500; | |
| } | |
| .progress-bar { | |
| width: 100%; | |
| height: 4px; | |
| background: rgba(255, 255, 255, 0.2); | |
| border-radius: 2px; | |
| overflow: hidden; | |
| margin-top: 8px; | |
| } | |
| .progress-fill { | |
| height: 100%; | |
| background: linear-gradient(90deg, var(--green), var(--teal)); | |
| border-radius: 2px; | |
| transition: width 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| } | |
| .main-content { | |
| padding: 32px; | |
| } | |
| .input-section { | |
| background: var(--gray-6); | |
| padding: 24px; | |
| border-radius: var(--radius-md); | |
| margin-bottom: 28px; | |
| border: 1px solid var(--separator); | |
| } | |
| .input-group { | |
| display: flex; | |
| gap: 12px; | |
| margin-bottom: 16px; | |
| flex-wrap: wrap; | |
| } | |
| .task-input { | |
| flex: 1; | |
| min-width: 200px; | |
| padding: 14px 18px; | |
| border: 1px solid var(--gray-4); | |
| border-radius: var(--radius-md); | |
| font-size: 1rem; | |
| background: white; | |
| transition: all 0.3s ease; | |
| font-family: inherit; | |
| font-weight: 500; | |
| } | |
| .task-input:focus { | |
| outline: none; | |
| border-color: var(--blue); | |
| box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1); | |
| } | |
| .task-input::placeholder { | |
| color: var(--text-tertiary); | |
| font-weight: 400; | |
| } | |
| .input-meta { | |
| display: flex; | |
| gap: 12px; | |
| flex-wrap: wrap; | |
| } | |
| .meta-input { | |
| padding: 10px 14px; | |
| border: 1px solid var(--gray-4); | |
| border-radius: var(--radius-sm); | |
| background: white; | |
| font-size: 0.9rem; | |
| transition: all 0.3s ease; | |
| font-family: inherit; | |
| font-weight: 500; | |
| color: var(--text-primary); | |
| } | |
| .meta-input:focus { | |
| outline: none; | |
| border-color: var(--blue); | |
| box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1); | |
| } | |
| .btn { | |
| padding: 14px 24px; | |
| border: none; | |
| border-radius: var(--radius-md); | |
| font-size: 1rem; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 8px; | |
| font-family: inherit; | |
| letter-spacing: -0.01em; | |
| } | |
| .btn-primary { | |
| background: var(--blue); | |
| color: white; | |
| box-shadow: 0 2px 8px rgba(0, 122, 255, 0.2); | |
| } | |
| .btn-primary:hover { | |
| background: var(--blue-dark); | |
| transform: translateY(-1px); | |
| box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3); | |
| } | |
| .btn-primary:active { | |
| transform: translateY(0); | |
| box-shadow: 0 2px 6px rgba(0, 122, 255, 0.2); | |
| } | |
| .btn-secondary { | |
| background: white; | |
| color: var(--text-primary); | |
| border: 1px solid var(--gray-4); | |
| } | |
| .btn-secondary:hover { | |
| background: var(--gray-6); | |
| border-color: var(--gray-3); | |
| } | |
| .controls { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-bottom: 20px; | |
| flex-wrap: wrap; | |
| gap: 16px; | |
| } | |
| .filter-tabs { | |
| display: flex; | |
| gap: 4px; | |
| background: var(--gray-6); | |
| padding: 4px; | |
| border-radius: var(--radius-md); | |
| border: 1px solid var(--separator); | |
| } | |
| .filter-tab { | |
| padding: 10px 18px; | |
| background: transparent; | |
| border: none; | |
| border-radius: var(--radius-sm); | |
| cursor: pointer; | |
| font-weight: 600; | |
| color: var(--text-tertiary); | |
| transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| font-family: inherit; | |
| font-size: 0.9rem; | |
| } | |
| .filter-tab:hover { | |
| color: var(--text-primary); | |
| } | |
| .filter-tab.active { | |
| background: white; | |
| color: var(--blue); | |
| box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); | |
| } | |
| .search-box { | |
| position: relative; | |
| min-width: 240px; | |
| } | |
| .search-input { | |
| width: 100%; | |
| padding: 10px 40px 10px 16px; | |
| border: 1px solid var(--gray-4); | |
| border-radius: var(--radius-md); | |
| font-size: 0.9rem; | |
| transition: all 0.3s ease; | |
| background: white; | |
| font-family: inherit; | |
| font-weight: 500; | |
| } | |
| .search-input:focus { | |
| outline: none; | |
| border-color: var(--blue); | |
| box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1); | |
| } | |
| .search-icon { | |
| position: absolute; | |
| right: 14px; | |
| top: 50%; | |
| transform: translateY(-50%); | |
| color: var(--text-tertiary); | |
| pointer-events: none; | |
| } | |
| .todo-list { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 8px; | |
| max-height: 480px; | |
| overflow-y: auto; | |
| padding-right: 8px; | |
| } | |
| .todo-list::-webkit-scrollbar { | |
| width: 6px; | |
| } | |
| .todo-list::-webkit-scrollbar-track { | |
| background: transparent; | |
| } | |
| .todo-list::-webkit-scrollbar-thumb { | |
| background: var(--gray-3); | |
| border-radius: 3px; | |
| } | |
| .todo-list::-webkit-scrollbar-thumb:hover { | |
| background: var(--gray-2); | |
| } | |
| .todo-item { | |
| background: white; | |
| border: 1px solid var(--separator); | |
| border-radius: var(--radius-md); | |
| padding: 16px; | |
| display: flex; | |
| align-items: center; | |
| gap: 14px; | |
| transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| cursor: move; | |
| animation: fadeIn 0.4s ease; | |
| position: relative; | |
| } | |
| @keyframes fadeIn { | |
| from { | |
| opacity: 0; | |
| transform: translateX(-16px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateX(0); | |
| } | |
| } | |
| .todo-item:hover { | |
| box-shadow: var(--shadow); | |
| transform: translateY(-1px); | |
| border-color: var(--gray-3); | |
| } | |
| .todo-item.dragging { | |
| opacity: 0.6; | |
| transform: rotate(1deg) scale(0.98); | |
| box-shadow: var(--shadow-hover); | |
| } | |
| .todo-item.completed { | |
| opacity: 0.65; | |
| background: var(--gray-6); | |
| } | |
| .todo-item.completed .todo-text { | |
| text-decoration: line-through; | |
| color: var(--text-tertiary); | |
| } | |
| .checkbox { | |
| width: 24px; | |
| height: 24px; | |
| border: 2px solid var(--gray-3); | |
| border-radius: var(--radius-sm); | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| flex-shrink: 0; | |
| background: white; | |
| } | |
| .checkbox:hover { | |
| border-color: var(--blue); | |
| background: rgba(0, 122, 255, 0.04); | |
| } | |
| .checkbox.checked { | |
| background: var(--blue); | |
| border-color: var(--blue); | |
| } | |
| .checkbox.checked::after { | |
| content: '✓'; | |
| color: white; | |
| font-weight: 600; | |
| font-size: 14px; | |
| } | |
| .todo-content { | |
| flex: 1; | |
| min-width: 0; | |
| } | |
| .todo-text { | |
| font-size: 1rem; | |
| color: var(--text-primary); | |
| margin-bottom: 6px; | |
| word-break: break-word; | |
| font-weight: 500; | |
| line-height: 1.4; | |
| } | |
| .todo-meta { | |
| display: flex; | |
| gap: 8px; | |
| flex-wrap: wrap; | |
| margin-top: 8px; | |
| } | |
| .todo-badge { | |
| padding: 4px 10px; | |
| border-radius: var(--radius-xs); | |
| font-size: 0.75rem; | |
| font-weight: 600; | |
| letter-spacing: 0.02em; | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 4px; | |
| } | |
| .priority-high { | |
| background: rgba(255, 59, 48, 0.1); | |
| color: var(--red); | |
| } | |
| .priority-medium { | |
| background: rgba(255, 149, 0, 0.1); | |
| color: var(--orange); | |
| } | |
| .priority-low { | |
| background: rgba(52, 199, 89, 0.1); | |
| color: var(--green); | |
| } | |
| .category-badge { | |
| background: rgba(0, 122, 255, 0.1); | |
| color: var(--blue); | |
| } | |
| .due-date { | |
| background: rgba(142, 142, 147, 0.1); | |
| color: var(--text-tertiary); | |
| } | |
| .todo-actions { | |
| display: flex; | |
| gap: 6px; | |
| } | |
| .action-btn { | |
| width: 32px; | |
| height: 32px; | |
| border: none; | |
| background: var(--gray-6); | |
| border-radius: var(--radius-sm); | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| color: var(--text-tertiary); | |
| } | |
| .action-btn:hover { | |
| background: var(--blue); | |
| color: white; | |
| transform: scale(1.05); | |
| } | |
| .action-btn.delete:hover { | |
| background: var(--red); | |
| } | |
| .empty-state { | |
| text-align: center; | |
| padding: 80px 20px; | |
| color: var(--text-tertiary); | |
| } | |
| .empty-state i { | |
| font-size: 4rem; | |
| margin-bottom: 20px; | |
| opacity: 0.3; | |
| } | |
| .empty-state h3 { | |
| font-size: 1.5rem; | |
| margin-bottom: 8px; | |
| font-weight: 600; | |
| color: var(--text-secondary); | |
| } | |
| .empty-state p { | |
| font-size: 1rem; | |
| font-weight: 400; | |
| } | |
| .clear-completed { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| margin-top: 24px; | |
| padding-top: 24px; | |
| border-top: 1px solid var(--separator); | |
| } | |
| .toast { | |
| position: fixed; | |
| bottom: 32px; | |
| right: 32px; | |
| background: var(--text-primary); | |
| color: white; | |
| padding: 16px 20px; | |
| border-radius: var(--radius-md); | |
| box-shadow: var(--shadow-hover); | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| transform: translateX(400px); | |
| transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); | |
| z-index: 1000; | |
| font-weight: 500; | |
| backdrop-filter: saturate(180%) blur(20px); | |
| } | |
| .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: 14px; | |
| } | |
| .input-meta { | |
| flex-direction: column; | |
| } | |
| .meta-input { | |
| width: 100%; | |
| } | |
| .toast { | |
| right: 16px; | |
| bottom: 16px; | |
| left: 16px; | |
| transform: translateY(100px); | |
| } | |
| .toast.show { | |
| transform: translateY(0); | |
| } | |
| } | |
| @media (max-width: 480px) { | |
| .container { | |
| border-radius: 0; | |
| min-height: 100vh; | |
| max-width: 100%; | |
| } | |
| body { | |
| padding: 0; | |
| } | |
| header { | |
| padding: 24px; | |
| } | |
| .main-content { | |
| padding: 24px; | |
| } | |
| h1 { | |
| font-size: 1.5rem; | |
| } | |
| .brand-link { | |
| position: static; | |
| margin-top: 16px; | |
| display: inline-block; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <header> | |
| <div class="header-content"> | |
| <div class="header-top"> | |
| <h1> | |
| <i class="fas fa-check-circle"></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> |