| 1 | { |
| 2 | "schema": 1, |
| 3 | "name": "todo", |
| 4 | "title": "To-do", |
| 5 | "glyph": "✓", |
| 6 | "blurb": "Create a to-do list", |
| 7 | "collection": "items", |
| 8 | "state": { |
| 9 | "items": { |
| 10 | "key": "id", |
| 11 | "fields": { |
| 12 | "id": "string", |
| 13 | "text": "string", |
| 14 | "done": "bool", |
| 15 | "doneAt": "time", |
| 16 | "by": "string" |
| 17 | } |
| 18 | } |
| 19 | }, |
| 20 | "events": { |
| 21 | "todo.add": { |
| 22 | "require": ["$event.text"], |
| 23 | "fold": [ |
| 24 | { "add": { "to": "items", "item": { "id": "$event.id", "text": "$event.text", "done": false, "doneAt": 0, "by": "$event.name" } } } |
| 25 | ] |
| 26 | }, |
| 27 | "todo.done": { |
| 28 | "fold": [ |
| 29 | { "update": { "in": "items", "id": "$event.id", "set": { "done": true, "doneAt": "$event.ts" } } } |
| 30 | ] |
| 31 | }, |
| 32 | "todo.reopen": { |
| 33 | "fold": [ |
| 34 | { "update": { "in": "items", "id": "$event.id", "set": { "done": false, "doneAt": 0 } } } |
| 35 | ] |
| 36 | }, |
| 37 | "todo.remove": { |
| 38 | "fold": [ |
| 39 | { "remove": { "from": "items", "id": "$event.id" } } |
| 40 | ] |
| 41 | }, |
| 42 | "todo.move": { |
| 43 | "require": ["$event.id"], |
| 44 | "fold": [ |
| 45 | { "move": { "in": "items", "id": "$event.id", "after": "$event.after" } } |
| 46 | ] |
| 47 | } |
| 48 | }, |
| 49 | "partition": { "flag": "done", "at": "doneAt", "graceMs": 750 }, |
| 50 | "actions": { |
| 51 | "add": { |
| 52 | "require": ["$input"], |
| 53 | "steps": [ |
| 54 | { "emit": { "type": "todo.add", "id": "$newId", "text": "$input" } } |
| 55 | ] |
| 56 | }, |
| 57 | "toggle": { |
| 58 | "steps": [ |
| 59 | { "if": { "truthy": "$item.done" }, "emit": { "type": "todo.reopen", "id": "$item.id" } }, |
| 60 | { "if": { "not": { "truthy": "$item.done" } }, "emit": { "type": "todo.done", "id": "$item.id" } } |
| 61 | ] |
| 62 | }, |
| 63 | "remove": { |
| 64 | "steps": [ |
| 65 | { "emit": { "type": "todo.remove", "id": "$item.id" } } |
| 66 | ] |
| 67 | }, |
| 68 | "move": { |
| 69 | "steps": [ |
| 70 | { "emit": { "type": "todo.move", "id": "$item.id", "after": "$after" } } |
| 71 | ] |
| 72 | } |
| 73 | }, |
| 74 | "chat": { |
| 75 | "todo.add": { "if": { "truthy": "$event.text" }, "text": "added “{event.text}”", "action": true } |
| 76 | }, |
| 77 | "views": { |
| 78 | "main": { |
| 79 | "kind": "list", |
| 80 | "composer": { "placeholder": "Add a to-do…", "button": "Add", "maxLength": 200, "action": "add" }, |
| 81 | "summary": [ |
| 82 | { "if": { "empty": "$items" }, "text": "No to-dos yet — add one above" }, |
| 83 | { "if": { "empty": "$buckets.active" }, "text": "all done 🎉" }, |
| 84 | { "text": "{buckets.active|count} left" } |
| 85 | ], |
| 86 | "search": { "fields": ["text"] }, |
| 87 | "sections": [ |
| 88 | { "id": "open", "source": ["active", "grace"], "order": { "by": "_index", "dir": "desc" }, "reorder": { "action": "move" } }, |
| 89 | { "id": "completed", "source": "archived", "title": "Completed ({count})", "collapsible": true, "collapsed": true, "order": { "by": "doneAt", "dir": "desc" } } |
| 90 | ], |
| 91 | "row": { |
| 92 | "leading": { "kind": "check", "on": "$item.done", "action": "toggle" }, |
| 93 | "title": { "text": "{item.text}", "strike": { "truthy": "$item.done" }, "muted": { "truthy": "$item.done" } }, |
| 94 | "trailing": [ |
| 95 | { "kind": "button", "glyph": "×", "label": "Remove", "role": "destructive", "action": "remove" } |
| 96 | ], |
| 97 | "tap": { "action": "toggle" } |
| 98 | } |
| 99 | }, |
| 100 | "detail": { |
| 101 | "title": "{item.text}", |
| 102 | "sections": [ |
| 103 | { |
| 104 | "kind": "definitions", |
| 105 | "rows": [ |
| 106 | { "term": "Status", "value": "Done", "if": { "truthy": "$item.done" } }, |
| 107 | { "term": "Status", "value": "To do", "if": { "not": { "truthy": "$item.done" } } }, |
| 108 | { "term": "Completed", "value": "{item.doneAt|abstime}", "if": { "truthy": "$item.doneAt" } }, |
| 109 | { "term": "Added by", "value": "{item.by}", "if": { "truthy": "$item.by" } } |
| 110 | ] |
| 111 | }, |
| 112 | { |
| 113 | "kind": "buttons", |
| 114 | "items": [ |
| 115 | { "label": "Mark done", "action": "toggle", "dismiss": true, "if": { "not": { "truthy": "$item.done" } } }, |
| 116 | { "label": "Reopen", "action": "toggle", "dismiss": true, "if": { "truthy": "$item.done" } }, |
| 117 | { "label": "Remove", "action": "remove", "role": "destructive", "dismiss": true } |
| 118 | ] |
| 119 | } |
| 120 | ] |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |