-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
520 lines (458 loc) · 25.4 KB
/
index.html
File metadata and controls
520 lines (458 loc) · 25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TaskFlow — AI To-Do App</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #F5F3EE;
--surface: #FFFFFF;
--surface2: #F0EDE6;
--border: #E5E0D8;
--accent: #5B47E0;
--accent-light: #EEF0FF;
--accent2: #FF7043;
--success: #00C896;
--text: #1A1A2E;
--muted: #8B8B9E;
--warn: #F59E0B;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font-family: 'Plus Jakarta Sans', sans-serif; min-height: 100vh; }
.app { display: grid; grid-template-columns: 280px 1fr 320px; min-height: 100vh; }
/* Left Sidebar */
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 28px 20px; display: flex; flex-direction: column; }
.logo { font-weight: 800; font-size: 20px; color: var(--accent); display: flex; align-items: center; gap: 8px; margin-bottom: 32px; }
.logo-icon { width: 32px; height: 32px; background: var(--accent); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px; }
.section-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 20px 0 8px; }
.list-item { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--muted); transition: all 0.15s; margin-bottom: 2px; }
.list-item:hover { background: var(--surface2); color: var(--text); }
.list-item.active { background: var(--accent-light); color: var(--accent); }
.list-left { display: flex; align-items: center; gap: 10px; }
.list-dot { width: 10px; height: 10px; border-radius: 50%; }
.count-badge { font-size: 11px; font-family: 'JetBrains Mono', monospace; background: var(--surface2); color: var(--muted); padding: 2px 7px; border-radius: 99px; }
.count-badge.accent { background: var(--accent-light); color: var(--accent); }
.add-list-btn { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; cursor: pointer; font-size: 13px; color: var(--muted); border: 1.5px dashed var(--border); margin-top: 8px; transition: all 0.15s; }
.add-list-btn:hover { border-color: var(--accent); color: var(--accent); }
.sidebar-bottom { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 8px; }
.progress-track { height: 6px; background: var(--surface2); border-radius: 99px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #8B5CF6); border-radius: 99px; transition: width 0.5s; }
/* Main */
.main { padding: 32px 36px; overflow-y: auto; }
.main-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.view-title { font-size: 26px; font-weight: 800; color: var(--text); }
.view-sub { font-size: 13px; color: var(--muted); margin-top: 3px; font-family: 'JetBrains Mono', monospace; }
.header-actions { display: flex; gap: 10px; }
.btn { padding: 9px 18px; border-radius: 10px; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.2s; border: none; }
.btn-ghost { background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(91,71,224,0.3); }
/* Add task bar */
.add-task-bar { background: var(--surface); border: 1.5px solid var(--border); border-radius: 14px; padding: 14px 18px; display: flex; align-items: center; gap: 12px; margin-bottom: 24px; transition: border-color 0.2s; }
.add-task-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,71,224,0.08); }
.add-task-input { flex: 1; border: none; outline: none; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 15px; background: transparent; color: var(--text); }
.add-task-input::placeholder { color: var(--muted); }
.priority-select { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; font-weight: 600; color: var(--text); outline: none; cursor: pointer; }
.add-task-submit { background: var(--accent); color: white; border: none; border-radius: 8px; width: 32px; height: 32px; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; flex-shrink: 0; }
.add-task-submit:hover { transform: scale(1.1); }
/* Filter tabs */
.filter-tabs { display: flex; gap: 6px; margin-bottom: 20px; }
.tab { padding: 7px 16px; border-radius: 99px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; border: 1px solid transparent; }
.tab.active { background: var(--accent); color: white; }
.tab:not(.active) { color: var(--muted); border-color: var(--border); background: var(--surface); }
.tab:not(.active):hover { color: var(--text); }
/* Task items */
.task-group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 20px 0 10px; display: flex; align-items: center; gap: 8px; }
.task-group-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.task-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 8px; display: flex; align-items: flex-start; gap: 12px; transition: all 0.2s; position: relative; overflow: hidden; }
.task-card:hover { border-color: rgba(91,71,224,0.25); box-shadow: 0 2px 12px rgba(0,0,0,0.06); transform: translateX(2px); }
.task-card.done { opacity: 0.55; }
.task-card.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-priority-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; border-radius: 12px 0 0 12px; }
.task-check { width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--border); cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; margin-top: 1px; transition: all 0.15s; }
.task-check.checked { background: var(--success); border-color: var(--success); color: white; }
.task-check:hover:not(.checked) { border-color: var(--accent); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.task-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.tag-high { background: #FEE2E2; color: #DC2626; }
.tag-medium { background: #FEF3C7; color: #D97706; }
.tag-low { background: #D1FAE5; color: #059669; }
.task-date { font-size: 11px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.task-list-label { font-size: 11px; color: var(--muted); }
.task-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.task-card:hover .task-actions { opacity: 1; }
.task-action-btn { width: 28px; height: 28px; border-radius: 7px; border: none; background: var(--surface2); cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center; }
.task-action-btn:hover { background: var(--border); }
/* AI Panel */
.ai-panel { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; }
.ai-header { padding: 24px 20px 16px; border-bottom: 1px solid var(--border); }
.ai-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.ai-badge { background: linear-gradient(135deg, var(--accent), #8B5CF6); color: white; font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.ai-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.ai-messages { flex: 1; padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.ai-msg { display: flex; gap: 10px; }
.ai-msg.user { flex-direction: row-reverse; }
.msg-avatar { width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.ai-avatar { background: linear-gradient(135deg, var(--accent), #8B5CF6); color: white; }
.user-avatar { background: var(--surface2); color: var(--text); font-size: 11px; }
.msg-bubble { max-width: 82%; padding: 10px 13px; border-radius: 12px; font-size: 13px; line-height: 1.5; }
.ai-bubble { background: var(--surface2); color: var(--text); border-radius: 4px 12px 12px 12px; }
.user-bubble { background: var(--accent); color: white; border-radius: 12px 4px 12px 12px; }
.ai-suggestions { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 6px; flex-wrap: wrap; }
.suggestion-chip { font-size: 11px; font-weight: 600; padding: 5px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.suggestion-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.ai-input-row { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.ai-input { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 13px; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 13px; color: var(--text); outline: none; transition: border-color 0.2s; }
.ai-input:focus { border-color: var(--accent); }
.ai-send-btn { background: var(--accent); color: white; border: none; border-radius: 10px; width: 36px; height: 36px; cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.15s; }
.ai-send-btn:hover { transform: scale(1.05); }
.ai-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.typing { display: flex; gap: 4px; align-items: center; padding: 10px 13px; }
.dot { width: 6px; height: 6px; background: var(--muted); border-radius: 50%; animation: bounce 1.2s infinite; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }
@media (max-width: 1100px) {
.app { grid-template-columns: 220px 1fr; }
.ai-panel { display: none; }
}
@media (max-width: 700px) {
.app { grid-template-columns: 1fr; }
.sidebar { display: none; }
.main { padding: 16px; }
}
</style>
</head>
<body>
<div class="app">
<!-- Sidebar -->
<aside class="sidebar">
<div class="logo"><div class="logo-icon">✦</div> TaskFlow</div>
<span class="section-label">Views</span>
<div class="list-item active" onclick="setView('all')">
<div class="list-left"><span>📋</span> All Tasks</div>
<span class="count-badge accent" id="badge-all">0</span>
</div>
<div class="list-item" onclick="setView('today')">
<div class="list-left"><span>🌤</span> Today</div>
<span class="count-badge" id="badge-today">0</span>
</div>
<div class="list-item" onclick="setView('upcoming')">
<div class="list-left"><span>📅</span> Upcoming</div>
<span class="count-badge" id="badge-upcoming">0</span>
</div>
<div class="list-item" onclick="setView('high')">
<div class="list-left"><span>🔴</span> High Priority</div>
<span class="count-badge" id="badge-high">0</span>
</div>
<span class="section-label">Lists</span>
<div class="list-item" onclick="setView('work')">
<div class="list-left"><div class="list-dot" style="background:#5B47E0"></div> Work</div>
<span class="count-badge" id="badge-work">0</span>
</div>
<div class="list-item" onclick="setView('personal')">
<div class="list-left"><div class="list-dot" style="background:#00C896"></div> Personal</div>
<span class="count-badge" id="badge-personal">0</span>
</div>
<div class="list-item" onclick="setView('study')">
<div class="list-left"><div class="list-dot" style="background:#F59E0B"></div> Study</div>
<span class="count-badge" id="badge-study">0</span>
</div>
<div class="add-list-btn">+ New List</div>
<div class="sidebar-bottom">
<div class="progress-label">
<span style="font-size:12px;font-weight:600;">Daily Progress</span>
<span id="progress-txt" style="font-size:12px;color:var(--muted);font-family:'JetBrains Mono',monospace;">0%</span>
</div>
<div class="progress-track"><div class="progress-fill" id="progress-bar" style="width:0%"></div></div>
</div>
</aside>
<!-- Main -->
<main class="main">
<div class="main-header">
<div>
<div class="view-title" id="view-title">All Tasks</div>
<div class="view-sub" id="view-sub">// 0 tasks remaining</div>
</div>
<div class="header-actions">
<button class="btn btn-ghost">Sort ↕</button>
<button class="btn btn-primary" onclick="focusAddTask()">+ New Task</button>
</div>
</div>
<!-- Add Task -->
<div class="add-task-bar">
<span style="font-size:18px;color:var(--muted)">+</span>
<input class="add-task-input" id="add-input" placeholder="Add a new task... (Press Enter)" onkeydown="handleAddKey(event)">
<select class="priority-select" id="add-priority">
<option value="high">🔴 High</option>
<option value="medium" selected>🟡 Medium</option>
<option value="low">🟢 Low</option>
</select>
<select class="priority-select" id="add-list">
<option value="work">Work</option>
<option value="personal">Personal</option>
<option value="study">Study</option>
</select>
<button class="add-task-submit" onclick="addTask()">↵</button>
</div>
<!-- Filter tabs -->
<div class="filter-tabs">
<div class="tab active" onclick="setFilter('all',this)">All</div>
<div class="tab" onclick="setFilter('active',this)">Active</div>
<div class="tab" onclick="setFilter('done',this)">Completed</div>
</div>
<!-- Task list -->
<div id="task-container"></div>
</main>
<!-- AI Panel -->
<aside class="ai-panel">
<div class="ai-header">
<div class="ai-title">AI Assistant <span class="ai-badge">Claude</span></div>
<div class="ai-sub">Ask me to organize, prioritize, or plan your tasks</div>
</div>
<div class="ai-messages" id="ai-messages">
<div class="ai-msg">
<div class="msg-avatar ai-avatar">✦</div>
<div class="msg-bubble ai-bubble">Hey! I'm your AI task assistant. I can help you <strong>prioritize tasks</strong>, suggest a <strong>daily schedule</strong>, break down big tasks, or motivate you. What would you like help with?</div>
</div>
</div>
<div class="ai-suggestions">
<div class="suggestion-chip" onclick="sendSuggestion(this)">Prioritize my tasks</div>
<div class="suggestion-chip" onclick="sendSuggestion(this)">Plan my day</div>
<div class="suggestion-chip" onclick="sendSuggestion(this)">Motivate me</div>
<div class="suggestion-chip" onclick="sendSuggestion(this)">Break down a task</div>
</div>
<div class="ai-input-row">
<input class="ai-input" id="ai-input" placeholder="Ask the AI..." onkeydown="handleAiKey(event)">
<button class="ai-send-btn" id="ai-send" onclick="sendAiMessage()">↑</button>
</div>
</aside>
</div>
<script>
let tasks = [
{ id:1, title:'Build FinTrack dashboard UI', priority:'high', list:'work', done:false, date: getTodayStr() },
{ id:2, title:'Complete DSA assignment on graphs', priority:'high', list:'study', done:false, date: getTodayStr() },
{ id:3, title:'Push Voyage project to GitHub', priority:'medium', list:'work', done:true, date: getTodayStr() },
{ id:4, title:'Read chapter 5 — Machine Learning book', priority:'medium', list:'study', done:false, date: getDateStr(1) },
{ id:5, title:'Morning workout — 30 mins', priority:'low', list:'personal', done:false, date: getTodayStr() },
{ id:6, title:'Update GitHub profile README', priority:'medium', list:'work', done:false, date: getDateStr(1) },
{ id:7, title:'Revise Python basics', priority:'medium', list:'study', done:false, date: getDateStr(2) },
];
let nextId = 8;
let currentView = 'all';
let currentFilter = 'all';
let aiHistory = [];
// Local Storage functions
function saveTasks() {
localStorage.setItem('taskflow-tasks', JSON.stringify(tasks));
localStorage.setItem('taskflow-nextId', nextId);
}
function loadTasks() {
const savedTasks = localStorage.getItem('taskflow-tasks');
const savedNextId = localStorage.getItem('taskflow-nextId');
if (savedTasks) {
tasks = JSON.parse(savedTasks);
}
if (savedNextId) {
nextId = parseInt(savedNextId);
}
}
// Load tasks on page load
loadTasks();
function getTodayStr() { return new Date().toISOString().split('T')[0]; }
function getDateStr(offset) {
const d = new Date(); d.setDate(d.getDate() + offset);
return d.toISOString().split('T')[0];
}
function fmtDate(str) {
const d = new Date(str + 'T00:00:00');
const today = getTodayStr();
const tom = getDateStr(1);
if (str === today) return 'Today';
if (str === tom) return 'Tomorrow';
return d.toLocaleDateString('en-IN', { day:'numeric', month:'short' });
}
function getFilteredTasks() {
let list = [...tasks];
if (currentView === 'today') list = list.filter(t => t.date === getTodayStr());
else if (currentView === 'upcoming') list = list.filter(t => t.date > getTodayStr());
else if (currentView === 'high') list = list.filter(t => t.priority === 'high');
else if (['work','personal','study'].includes(currentView)) list = list.filter(t => t.list === currentView);
if (currentFilter === 'active') list = list.filter(t => !t.done);
if (currentFilter === 'done') list = list.filter(t => t.done);
return list;
}
function renderTasks() {
const container = document.getElementById('task-container');
const list = getFilteredTasks();
const pending = list.filter(t => !t.done);
const done = list.filter(t => t.done);
let html = '';
if (pending.length > 0) {
html += `<div class="task-group-label">Pending · ${pending.length}</div>`;
html += pending.map(t => taskHTML(t)).join('');
}
if (done.length > 0 && currentFilter !== 'active') {
html += `<div class="task-group-label">Completed · ${done.length}</div>`;
html += done.map(t => taskHTML(t)).join('');
}
if (list.length === 0) html = `<div style="text-align:center;padding:48px;color:var(--muted);font-size:14px;">No tasks here. Add one above! ✦</div>`;
container.innerHTML = html;
updateBadges();
updateProgress();
}
function taskHTML(t) {
const colors = { high:'#DC2626', medium:'#D97706', low:'#059669' };
return `
<div class="task-card ${t.done?'done':''}" id="task-${t.id}">
<div class="task-priority-bar" style="background:${colors[t.priority]}"></div>
<div class="task-check ${t.done?'checked':''}" onclick="toggleTask(${t.id})">${t.done?'✓':''}</div>
<div class="task-body">
<div class="task-title">${t.title}</div>
<div class="task-meta">
<span class="task-tag tag-${t.priority}">${t.priority}</span>
<span class="task-date">📅 ${fmtDate(t.date)}</span>
<span class="task-list-label">· ${t.list}</span>
</div>
</div>
<div class="task-actions">
<button class="task-action-btn" onclick="deleteTask(${t.id})">🗑</button>
</div>
</div>
`;
}
function toggleTask(id) {
const t = tasks.find(t => t.id === id);
if (t) t.done = !t.done;
saveTasks();
renderTasks();
}
function deleteTask(id) {
tasks = tasks.filter(t => t.id !== id);
saveTasks();
renderTasks();
}
function addTask() {
const input = document.getElementById('add-input');
const title = input.value.trim();
if (!title) return;
const priority = document.getElementById('add-priority').value;
const list = document.getElementById('add-list').value;
tasks.unshift({ id: nextId++, title, priority, list, done: false, date: getTodayStr() });
input.value = '';
saveTasks();
renderTasks();
}
function handleAddKey(e) { if (e.key === 'Enter') addTask(); }
function focusAddTask() { document.getElementById('add-input').focus(); }
function setView(view) {
currentView = view;
const labels = { all:'All Tasks', today:"Today's Tasks", upcoming:'Upcoming', high:'High Priority', work:'Work', personal:'Personal', study:'Study' };
document.getElementById('view-title').textContent = labels[view] || 'Tasks';
document.querySelectorAll('.list-item').forEach(el => el.classList.remove('active'));
renderTasks();
}
function setFilter(f, el) {
currentFilter = f;
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
el.classList.add('active');
renderTasks();
}
function updateBadges() {
const today = getTodayStr();
document.getElementById('badge-all').textContent = tasks.filter(t=>!t.done).length;
document.getElementById('badge-today').textContent = tasks.filter(t=>t.date===today&&!t.done).length;
document.getElementById('badge-upcoming').textContent = tasks.filter(t=>t.date>today&&!t.done).length;
document.getElementById('badge-high').textContent = tasks.filter(t=>t.priority==='high'&&!t.done).length;
document.getElementById('badge-work').textContent = tasks.filter(t=>t.list==='work'&&!t.done).length;
document.getElementById('badge-personal').textContent = tasks.filter(t=>t.list==='personal'&&!t.done).length;
document.getElementById('badge-study').textContent = tasks.filter(t=>t.list==='study'&&!t.done).length;
const remaining = tasks.filter(t=>!t.done).length;
document.getElementById('view-sub').textContent = `// ${remaining} task${remaining!==1?'s':''} remaining`;
}
function updateProgress() {
const todayTasks = tasks.filter(t => t.date === getTodayStr());
const doneTasks = todayTasks.filter(t => t.done);
const pct = todayTasks.length > 0 ? Math.round(doneTasks.length / todayTasks.length * 100) : 0;
document.getElementById('progress-bar').style.width = pct + '%';
document.getElementById('progress-txt').textContent = pct + '%';
}
// AI Chat
function sendSuggestion(el) {
document.getElementById('ai-input').value = el.textContent;
sendAiMessage();
}
function handleAiKey(e) { if (e.key === 'Enter') sendAiMessage(); }
async function sendAiMessage() {
const input = document.getElementById('ai-input');
const msg = input.value.trim();
if (!msg) return;
input.value = '';
appendMsg('user', msg);
aiHistory.push({ role: 'user', content: msg });
const sendBtn = document.getElementById('ai-send');
sendBtn.disabled = true;
const typingId = appendTyping();
const taskSummary = tasks.map(t => `- [${t.done?'done':'pending'}] ${t.title} (${t.priority} priority, ${t.list}, due ${fmtDate(t.date)})`).join('\n');
try {
const res = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'claude-sonnet-4-20250514',
max_tokens: 1000,
system: `You are a friendly, energetic AI productivity assistant inside a task management app called TaskFlow. The user's current tasks are:\n\n${taskSummary}\n\nHelp them be productive. Give short, actionable, motivating responses. Use bullet points when listing items. Keep responses concise (under 120 words). Be warm and encouraging.`,
messages: aiHistory
})
});
const data = await res.json();
const reply = data.content?.map(c => c.text || '').join('') || 'Sorry, I had trouble thinking! Try again?';
removeTyping(typingId);
appendMsg('ai', reply);
aiHistory.push({ role: 'assistant', content: reply });
} catch {
removeTyping(typingId);
appendMsg('ai', 'Hmm, I had a connection issue. Check your network and try again!');
}
sendBtn.disabled = false;
}
function appendMsg(role, text) {
const msgs = document.getElementById('ai-messages');
const id = 'msg-' + Date.now();
const isAI = role === 'ai';
const div = document.createElement('div');
div.className = `ai-msg${isAI ? '' : ' user'}`;
div.id = id;
div.innerHTML = `
<div class="msg-avatar ${isAI ? 'ai-avatar' : 'user-avatar'}">${isAI ? '✦' : 'AJ'}</div>
<div class="msg-bubble ${isAI ? 'ai-bubble' : 'user-bubble'}">${text.replace(/\n/g,'<br>')}</div>
`;
msgs.appendChild(div);
msgs.scrollTop = msgs.scrollHeight;
return id;
}
function appendTyping() {
const msgs = document.getElementById('ai-messages');
const id = 'typing-' + Date.now();
const div = document.createElement('div');
div.className = 'ai-msg'; div.id = id;
div.innerHTML = `<div class="msg-avatar ai-avatar">✦</div><div class="msg-bubble ai-bubble"><div class="typing"><div class="dot"></div><div class="dot"></div><div class="dot"></div></div></div>`;
msgs.appendChild(div);
msgs.scrollTop = msgs.scrollHeight;
return id;
}
function removeTyping(id) {
const el = document.getElementById(id);
if (el) el.remove();
}
renderTasks();
</script>
</body>
</html>