Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
794 lines (720 loc) · 24.4 KB
/
Copy pathindex.html
File metadata and controls
794 lines (720 loc) · 24.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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dot List — a Final Version todo demo</title>
<meta name="description" content="An interactive demo of Mark Forster's Final Version (FV) todo list system. No signup. Try it, fork it, hack it.">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Ccircle cx='32' cy='32' r='32' fill='white'/%3E%3Ctext x='32' y='46' font-family='-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif' font-size='40' font-weight='900' text-anchor='middle' fill='%23ff7a00'%3EDL%3C/text%3E%3C/svg%3E">
<style>
/* ---------- Reset-ish + base typography ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
color: #1d1d1f;
background: #fafaf7;
padding: 1rem;
max-width: 640px;
margin: 0 auto;
}
/* ---------- Header ---------- */
header {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1rem;
}
h1 {
font-size: 1.4rem;
margin: 0;
letter-spacing: -0.01em;
}
h1 .dot { color: #d4691e; }
.header-actions { display: flex; gap: 0.5rem; }
.header-actions button {
font-size: 0.85rem;
padding: 0.3rem 0.6rem;
background: transparent;
border: 1px solid #ccc;
color: #555;
border-radius: 4px;
cursor: pointer;
}
.header-actions button:hover { background: #f0f0e8; }
.header-actions button[aria-expanded="true"] {
background: #1d1d1f;
color: white;
border-color: #1d1d1f;
}
.header-actions button[aria-expanded="true"]:hover { background: #3a3a3c; }
/* ---------- Help panel (collapsible) ---------- */
#help-panel {
display: none;
background: #fff8e7;
border: 1px solid #e8d9a8;
padding: 0.75rem 1rem;
border-radius: 6px;
margin-bottom: 1rem;
font-size: 0.92rem;
}
#help-panel.open { display: block; }
#help-panel p { margin: 0.4rem 0; }
#help-panel ol { margin: 0.4rem 0; padding-left: 1.2rem; }
/* ---------- Add-task input ---------- */
.add-row {
display: flex;
gap: 0.4rem;
margin-bottom: 1rem;
align-items: center;
}
.add-row input[type=text] {
flex: 1;
padding: 0.55rem 0.7rem;
font-size: 1rem;
border: 1px solid #d0cfc7;
border-radius: 6px;
background: white;
}
.add-row input[type=text]:focus {
outline: 2px solid #d4691e;
outline-offset: -1px;
}
.add-row label {
font-size: 0.85rem;
color: #666;
display: flex;
align-items: center;
gap: 0.25rem;
user-select: none;
cursor: pointer;
}
.add-row button {
padding: 0.55rem 0.9rem;
font-size: 1rem;
background: #1d1d1f;
color: white;
border: 0;
border-radius: 6px;
cursor: pointer;
}
.add-row button:hover { background: #3a3a3c; }
/* ---------- Active prompt panel ---------- */
#prompt {
background: white;
border: 1px solid #e2e0d8;
border-radius: 8px;
padding: 1rem;
margin-bottom: 1rem;
min-height: 4rem;
}
#prompt.idle, #prompt.empty { text-align: center; }
#prompt .compare {
font-size: 1rem;
margin: 0 0 0.75rem 0;
line-height: 1.5;
}
#prompt .candidate, #prompt .benchmark {
display: inline-block;
padding: 0.1rem 0.4rem;
background: #f0ede0;
border-radius: 4px;
font-weight: 500;
}
#prompt .candidate { background: #fde4cd; }
#prompt .buttons {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
#prompt button {
padding: 0.55rem 1rem;
font-size: 0.95rem;
border-radius: 6px;
border: 1px solid #d0cfc7;
background: white;
cursor: pointer;
}
#prompt button.primary {
background: #d4691e;
color: white;
border-color: #d4691e;
}
#prompt button.primary:hover { background: #b35716; }
#prompt button:not(.primary):hover { background: #f0ede0; }
/* ---------- Task list ---------- */
ul.tasks {
list-style: none;
padding: 0;
margin: 0;
}
ul.tasks li {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 0.6rem;
border-bottom: 1px solid #ece9de;
font-size: 1rem;
}
ul.tasks li.dotted { font-weight: 500; }
ul.tasks li.benchmark { background: #fff8e7; }
ul.tasks li.candidate { background: #fde4cd; }
ul.tasks li.next-up { box-shadow: inset 3px 0 0 #d4691e; }
ul.tasks li.done { color: #999; }
ul.tasks li.done .task-text {
text-decoration: line-through;
font-style: italic;
}
.dot-marker {
width: 1em;
display: inline-block;
text-align: center;
color: #d4691e;
font-size: 0.9em;
}
.task-text { flex: 1; }
.task-meta { font-size: 0.75rem; color: #888; }
.task-complete, .task-delete {
background: transparent;
border: 0;
cursor: pointer;
color: #bbb;
font-size: 1rem;
padding: 0 0.2rem;
}
.task-complete:hover { color: #2e8b57; }
.task-delete:hover { color: #c33; }
/* ---------- Footer ---------- */
footer {
margin-top: 1.5rem;
font-size: 0.85rem;
color: #888;
display: flex;
justify-content: space-between;
align-items: center;
}
footer a, footer button.linklike {
color: #888;
background: none;
border: 0;
padding: 0;
cursor: pointer;
text-decoration: underline;
font: inherit;
}
footer a:hover, footer button.linklike:hover { color: #d4691e; }
/* ---------- Tiny screens ---------- */
@media (max-width: 420px) {
body { padding: 0.75rem; }
h1 { font-size: 1.2rem; }
.add-row label { font-size: 0.8rem; }
}
</style>
</head>
<body>
<header>
<h1><span class="dot">●</span> Dot List</h1>
<div class="header-actions">
<button id="help-btn" aria-controls="help-panel" aria-expanded="false">What's this?</button>
<button id="reset-btn" title="Wipe and reload the demo list">Reset</button>
</div>
</header>
<div id="help-panel">
<p><strong>Dot List aka Forster List</strong> is a tiny demo of Mark Forster's <em>Final Version</em> todo system.
There's a
<a href="https://blog.beeminder.com/forster">thorough explanation</a>
on the Beeminder blog.
</p>
<p><strong>How Do You (To)Do?</strong></p>
<ol>
<li>New tasks are added to the bottom of the list</li>
<li>The top task gets a dot</li>
<li><strong>Start review</strong> takes you through the list comparing each task to the current dotted task</li>
<li>At the end of the review, you'll have a chain of tasks which you work from the bottom up</li>
<li>As you mark items off, Dot List will surface the next item in your chain</li>
<li>Note: you do not have to complete the entire task! At a minimum make a start on it. You can always click "Started, not done" and push it back onto the bottom of the list for next time.</li>
<li>Did something out of order? Click any task's ✓ to mark it done on the spot.</li>
</ol>
<p>Want more or different features? Make your own version by grabbing the source in your browser; it's plain JavaScript + HTML. Or <a href="https://github.com/bsoule/dotlist">fork it up</a> from GitHub.</p>
</div>
<div class="add-row">
<input type="text" id="task-input" placeholder="Add a task…" autocomplete="off" />
<label><input type="checkbox" id="urgent-check" /> urgent</label>
<button id="add-btn">Add</button>
</div>
<div id="prompt"></div>
<ul class="tasks" id="task-list"></ul>
<footer>
<button class="linklike" id="clear-done-btn">Clear completed</button>
<span>based on Mark Forster's <a href="https://blog.beeminder.com/forster" target="_blank" rel="noopener">Final Version</a></span>
</footer>
<script>
'use strict';
/* ============================================================
* Dot List — a single-file demo of Mark Forster's Final Version.
*
* The whole app is in this file. The blog-post-companion goal
* is that "View Source" should be a perfectly readable tour.
*
* Sections, in order:
* 1. State + persistence
* 2. Algorithm (anchor, chain-build, execution order)
* 3. Render
* 4. Events
* ============================================================ */
/* -----------------------------------------------------------
* 1. STATE + PERSISTENCE
* -----------------------------------------------------------
* One JSON blob in localStorage. Shape:
* {
* tasks: [{ id, text, dotted, dotOrder, doneAt, addedAt }],
* mode: 'empty' | 'idle' | 'reviewing' | 'executing',
* reviewCursor: index|null // next list-index to compare
* }
* --------------------------------------------------------- */
const STORAGE_KEY = 'dotlist-v1';
const DEMO_SEED = [
'Write blog post intro',
"Reply to mum",
'Order cat food',
'Read chapter ג of Unsong',
'Laundry',
];
let state;
function freshState(seed = DEMO_SEED) {
const tasks = seed.map(text => makeTask(text));
const s = {
tasks,
mode: tasks.length ? 'idle' : 'empty',
reviewCursor: null,
};
// Anchor the top task on first load so the user sees a dot immediately.
recomputeAnchor(s);
return s;
}
function makeTask(text, { dotted = false, dotOrder = null } = {}) {
return {
id: (crypto.randomUUID && crypto.randomUUID()) || String(Math.random()).slice(2),
text,
dotted,
dotOrder,
doneAt: null,
addedAt: Date.now(),
};
}
function load() {
try {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return freshState();
const parsed = JSON.parse(raw);
// Light sanity check — if shape looks wrong, start fresh.
if (!parsed || !Array.isArray(parsed.tasks)) return freshState();
return parsed;
} catch (e) {
return freshState();
}
}
function save() {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
} catch (e) {
// localStorage can fail in private browsing or when full; we just skip.
}
}
/* -----------------------------------------------------------
* 2. ALGORITHM
* -----------------------------------------------------------
* Active tasks = tasks where doneAt === null.
* Anchor = topmost active task; it's always dotted with dotOrder 0.
* Chain = active dotted tasks, sorted by dotOrder ascending.
* Execution order = reverse of dotOrder.
* --------------------------------------------------------- */
function activeTasks(s = state) {
return s.tasks.filter(t => t.doneAt === null);
}
function chain(s = state) {
return activeTasks(s)
.filter(t => t.dotted)
.sort((a, b) => a.dotOrder - b.dotOrder);
}
function nextDotOrder(s = state) {
const c = chain(s);
return c.length ? c[c.length - 1].dotOrder + 1 : 0;
}
// Ensure the topmost active task is dotted as anchor (dotOrder 0).
// Called whenever the list shape changes outside of an active review.
function recomputeAnchor(s = state) {
const active = activeTasks(s);
if (active.length === 0) return;
// If no task has dotOrder 0, promote the topmost active task.
const hasAnchor = active.some(t => t.dotted && t.dotOrder === 0);
if (!hasAnchor) {
active[0].dotted = true;
active[0].dotOrder = 0;
}
}
// Given the index in state.tasks of the current benchmark, return the
// index of the next active, undotted task strictly below it. Returns -1
// if none remain — that's the end-of-review signal.
function nextCandidateIndex(fromIndex) {
for (let i = fromIndex + 1; i < state.tasks.length; i++) {
const t = state.tasks[i];
if (t.doneAt === null && !t.dotted) return i;
}
return -1;
}
// Find the index in state.tasks of the highest-dotOrder active dotted task.
// That's the current benchmark during review and the next-up during execution.
function benchmarkIndex() {
let best = -1;
let bestOrder = -1;
for (let i = 0; i < state.tasks.length; i++) {
const t = state.tasks[i];
if (t.doneAt === null && t.dotted && t.dotOrder > bestOrder) {
bestOrder = t.dotOrder;
best = i;
}
}
return best;
}
/* -----------------------------------------------------------
* 3. RENDER
* -----------------------------------------------------------
* One function repaints the world from state. No virtual DOM,
* just straightforward DOM manipulation since the list is small.
* --------------------------------------------------------- */
const $prompt = document.getElementById('prompt');
const $list = document.getElementById('task-list');
function render() {
renderPrompt();
renderList();
// Keep mode honest: if there are no active tasks, we're empty.
if (activeTasks().length === 0 && state.mode !== 'empty') {
state.mode = 'empty';
save();
renderPrompt();
}
}
function renderPrompt() {
$prompt.className = state.mode;
$prompt.innerHTML = '';
if (state.mode === 'empty') {
$prompt.innerHTML = `
<p class="compare">Your list is empty. Add a task above to get started — or
<button class="primary" id="seed-btn">load the demo list</button>.</p>`;
document.getElementById('seed-btn').onclick = () => {
state = freshState();
save();
render();
};
return;
}
if (state.mode === 'idle') {
const benchIdx = benchmarkIndex();
const benchText = benchIdx >= 0 ? state.tasks[benchIdx].text : '';
$prompt.innerHTML = `
<p class="compare">Your benchmark is <span class="benchmark"></span>.
Walk the list and dot anything you'd rather do first.</p>
<div class="buttons">
<button class="primary" id="start-review-btn">Start review →</button>
</div>`;
$prompt.querySelector('.benchmark').textContent = benchText;
document.getElementById('start-review-btn').onclick = startReview;
return;
}
if (state.mode === 'reviewing') {
const benchIdx = benchmarkIndex();
const candIdx = state.reviewCursor;
if (candIdx === -1 || candIdx == null || candIdx >= state.tasks.length) {
// Defensive: shouldn't normally hit this, but if state is odd, end review.
finishReview();
return;
}
const benchText = benchIdx >= 0 ? state.tasks[benchIdx].text : '';
const candText = state.tasks[candIdx].text;
$prompt.innerHTML = `
<p class="compare">Do you want to do
<span class="candidate"></span>
more than
<span class="benchmark"></span>?</p>
<div class="buttons">
<button class="primary" id="yes-btn">Yes, dot it</button>
<button id="no-btn">No, skip</button>
<button id="end-review-btn" title="End the review and start working the chain">End review</button>
</div>`;
$prompt.querySelector('.candidate').textContent = candText;
$prompt.querySelector('.benchmark').textContent = benchText;
document.getElementById('yes-btn').onclick = reviewYes;
document.getElementById('no-btn').onclick = reviewNo;
document.getElementById('end-review-btn').onclick = finishReview;
return;
}
if (state.mode === 'executing') {
const idx = benchmarkIndex();
if (idx < 0) {
// Chain done.
state.mode = activeTasks().length ? 'idle' : 'empty';
recomputeAnchor();
save();
renderPrompt();
return;
}
const text = state.tasks[idx].text;
$prompt.innerHTML = `
<p class="compare">Now doing: <span class="candidate"></span></p>
<div class="buttons">
<button class="primary" id="done-btn">Done</button>
<button id="partial-btn">Started, not done</button>
</div>`;
$prompt.querySelector('.candidate').textContent = text;
document.getElementById('done-btn').onclick = () => completeCurrent({ partial: false });
document.getElementById('partial-btn').onclick = () => completeCurrent({ partial: true });
return;
}
}
function renderList() {
$list.innerHTML = '';
const benchIdx = state.mode === 'reviewing' ? benchmarkIndex() : -1;
const candIdx = state.mode === 'reviewing' ? state.reviewCursor : -1;
const nextUpIdx = state.mode === 'executing' ? benchmarkIndex() : -1;
state.tasks.forEach((t, i) => {
const li = document.createElement('li');
const classes = [];
if (t.dotted && t.doneAt === null) classes.push('dotted');
if (t.doneAt !== null) classes.push('done');
if (i === benchIdx) classes.push('benchmark');
if (i === candIdx) classes.push('candidate');
if (i === nextUpIdx) classes.push('next-up');
li.className = classes.join(' ');
const dot = document.createElement('span');
dot.className = 'dot-marker';
dot.textContent = (t.dotted && t.doneAt === null) ? '●' : '';
li.appendChild(dot);
const text = document.createElement('span');
text.className = 'task-text';
text.textContent = t.text;
li.appendChild(text);
if (t.doneAt === null) {
const done = document.createElement('button');
done.className = 'task-complete';
done.textContent = '✓';
done.title = 'Mark this task done';
done.onclick = () => completeTask(t.id);
li.appendChild(done);
}
const del = document.createElement('button');
del.className = 'task-delete';
del.textContent = '×';
del.title = 'Delete this task';
del.onclick = () => deleteTask(t.id);
li.appendChild(del);
$list.appendChild(li);
});
}
/* -----------------------------------------------------------
* 4. EVENTS
* --------------------------------------------------------- */
function addTask(text, { urgent = false } = {}) {
text = text.trim();
if (!text) return;
const task = makeTask(text);
if (urgent) {
// Urgent items are dotted immediately and slot into the current chain
// at the end (so they're the very next thing to do when execution
// starts, or if already executing, the very next thing after current).
task.dotted = true;
task.dotOrder = nextDotOrder();
}
state.tasks.push(task);
// If we were empty, we're now idle (or executing if urgent only).
if (state.mode === 'empty') {
state.mode = 'idle';
}
recomputeAnchor();
save();
render();
}
function deleteTask(id) {
state.tasks = state.tasks.filter(t => t.id !== id);
// If we just removed the current review candidate, advance the cursor
// sensibly so we don't point past the end.
if (state.mode === 'reviewing') {
if (state.reviewCursor >= state.tasks.length) {
finishReview();
return;
}
}
// Reanchor if we deleted the anchor.
recomputeAnchor();
if (activeTasks().length === 0) state.mode = 'empty';
save();
render();
}
function startReview() {
// Begin at the first task strictly below the anchor.
const anchorIdx = benchmarkIndex();
const candIdx = nextCandidateIndex(anchorIdx);
if (candIdx === -1) {
// Only the anchor exists — straight to execution.
state.mode = 'executing';
} else {
state.mode = 'reviewing';
state.reviewCursor = candIdx;
}
save();
render();
}
function reviewYes() {
const i = state.reviewCursor;
if (i == null || i < 0 || i >= state.tasks.length) return;
const t = state.tasks[i];
t.dotted = true;
t.dotOrder = nextDotOrder();
// Continue scanning from the just-dotted task downward.
const next = nextCandidateIndex(i);
if (next === -1) {
finishReview();
} else {
state.reviewCursor = next;
save();
render();
}
}
function reviewNo() {
// Skip: advance cursor relative to the current candidate, NOT the benchmark.
// (The candidate may be far below the benchmark by now.)
const next = nextCandidateIndex(state.reviewCursor);
if (next === -1) {
finishReview();
} else {
state.reviewCursor = next;
save();
render();
}
}
function finishReview() {
state.mode = 'executing';
state.reviewCursor = null;
save();
render();
}
function completeCurrent({ partial }) {
const idx = benchmarkIndex();
if (idx < 0) return;
const t = state.tasks[idx];
t.doneAt = Date.now();
t.dotted = false;
// dotOrder left as historical record but no longer affects logic (filtered by doneAt).
if (partial) {
// Push a fresh, un-dotted copy to the bottom for next round.
state.tasks.push(makeTask(t.text));
}
// If chain is now empty, drop back to idle (and reanchor) or empty.
const remainingChain = chain();
if (remainingChain.length === 0) {
if (activeTasks().length === 0) {
state.mode = 'empty';
} else {
state.mode = 'idle';
recomputeAnchor();
}
}
save();
render();
}
// Mark any task done by id — the per-item "✓" button. Unlike
// completeCurrent, the task needn't be the chain's next-up; this is for
// things that got done out of order.
function completeTask(id) {
const t = state.tasks.find(t => t.id === id);
if (!t || t.doneAt !== null) return;
t.doneAt = Date.now();
t.dotted = false;
if (state.mode === 'reviewing') {
recomputeAnchor();
// If we completed the current candidate (or reanchoring dotted it),
// advance to the next comparable task; if none remain, review is over.
const cand = state.tasks[state.reviewCursor];
if (!cand || cand.doneAt !== null || cand.dotted) {
const next = nextCandidateIndex(state.reviewCursor);
if (next === -1) { finishReview(); return; }
state.reviewCursor = next;
}
} else if (state.mode === 'executing') {
// Same tail logic as completeCurrent: an emptied chain ends execution.
// (No reanchoring mid-chain — that would dot an unreviewed task.)
if (chain().length === 0) {
state.mode = activeTasks().length ? 'idle' : 'empty';
recomputeAnchor();
}
} else {
// idle: reanchor in case we completed the anchor.
recomputeAnchor();
if (activeTasks().length === 0) state.mode = 'empty';
}
save();
render();
}
function clearCompleted() {
state.tasks = state.tasks.filter(t => t.doneAt === null);
save();
render();
}
function resetAll() {
if (!confirm('Wipe your list?')) return;
state = freshState([]); // empty — user can click "load demo list" if they want it back
save();
render();
}
/* -----------------------------------------------------------
* Wire up the static UI controls.
* --------------------------------------------------------- */
const $input = document.getElementById('task-input');
const $urgent = document.getElementById('urgent-check');
document.getElementById('add-btn').onclick = submitAdd;
$input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') submitAdd();
});
function submitAdd() {
addTask($input.value, { urgent: $urgent.checked });
$input.value = '';
$urgent.checked = false;
$input.focus();
}
document.getElementById('reset-btn').onclick = resetAll;
document.getElementById('clear-done-btn').onclick = clearCompleted;
const $help = document.getElementById('help-panel');
const $helpBtn = document.getElementById('help-btn');
function setHelpOpen(open) {
$help.classList.toggle('open', open);
$helpBtn.setAttribute('aria-expanded', open ? 'true' : 'false');
}
$helpBtn.onclick = () => setHelpOpen(!$help.classList.contains('open'));
// ?help (or ?help=1) in the URL opens the intro panel on load — handy for sharing
// the page with someone who hasn't read the blog post.
if (new URLSearchParams(location.search).has('help')) setHelpOpen(true);
// Keyboard shortcuts during review/execution. Ignored when typing in the input.
document.addEventListener('keydown', (e) => {
if (document.activeElement === $input) return;
if (e.metaKey || e.ctrlKey || e.altKey) return;
if (state.mode === 'reviewing') {
if (e.key === 'y' || e.key === 'Y') { e.preventDefault(); reviewYes(); }
else if (e.key === 'n' || e.key === 'N') { e.preventDefault(); reviewNo(); }
} else if (state.mode === 'executing') {
if (e.key === 'd' || e.key === 'D') { e.preventDefault(); completeCurrent({ partial: false }); }
else if (e.key === 'p' || e.key === 'P') { e.preventDefault(); completeCurrent({ partial: true }); }
} else if (state.mode === 'idle') {
if (e.key === 'r' || e.key === 'R') { e.preventDefault(); startReview(); }
}
});
/* -----------------------------------------------------------
* Boot.
* --------------------------------------------------------- */
state = load();
// Defensive: if persisted state somehow has no anchor and isn't empty, fix it.
recomputeAnchor();
render();
</script>
</body>
</html>